MethodAccessException on AuthenticationBase<User>.UpdateUser Exception - wcf

I'm calling a UpdateUser on AuthenticationBase class in the System.ServiceModel.DomainServices.Server assembly installed by the WCF RIA Services installer. This works on my Win 7 desktop but on my Win 7 laptop, I get the following exception.
Any ideas on what I ought to be looking for or how I can determine what is different between the two systems? Thanks.
System.MethodAccessException was unhandled
Message=Attempt by method 'System.ServiceModel.DomainServices.Server.ApplicationServices.AuthenticationBase`1<T>.IsReadOnly(System.Reflection.PropertyInfo)' to access method 'System.Linq.Enumerable.Cast<System.ComponentModel.DataAnnotations.EditableAttribute>(System.Collections.IEnumerable)' failed.
Source=System.ServiceModel.DomainServices.Server
StackTrace:
at System.ServiceModel.DomainServices.Server.ApplicationServices.AuthenticationBase`1.IsReadOnly(PropertyInfo propertyInfo)
at System.ServiceModel.DomainServices.Server.ApplicationServices.AuthenticationBase`1.UpdateProfile(T user)
at System.ServiceModel.DomainServices.Server.ApplicationServices.AuthenticationBase`1.UpdateUserCore(T user)
at System.ServiceModel.DomainServices.Server.ApplicationServices.AuthenticationBase`1.UpdateUser(T user)

It sounds like you do not have Reflection permission on the laptop instance.
Are you perhaps running it under another user account?
Have a look at the MethodAccessException docs.
Also, make sure both are running the same version of .NET as there are security changes introduced in .NET 4.

Related

How To Reference a Com Object in a WCF Service

I need to reference a Com DLL from within a Silverlight program. Since this is not allowed, I created a wcf service and put my reference to the Com in it.
This idea seems to work fine when I ran my wcf service from my local machine but when I publish the service to my server it failed to work. The error was “Object reference not set to an instance of an object” where I tried to instance the DLL.
Here problem line is
m_cloVB6Encryption = New VB6Encryption.cEncryption
VB6Encryption is a complicated one. It called another DLL which calls several others.
To try to isolate the problem I created a very simple VB6 component, this time I got the error
"Retrieving the COM class factory for component with CLSID {74FE605A-5861-41A0-BA13-27DDD9C2EBB8} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))."
This is despite the fact that I manually registered the component and it was successful.
The problem line was cloSimple = New Simple.cSimple.
My computer runs Windows 7; the server runs Windows Server 2012 R2 Standard.
Presumably your COM component was build as 32bit...so when you register it is registered as a (InProc) 32bit COM component....(and can only be loaded by a 32bit application).
Your ASP.NET Website is most likely running in an AppPool that is set to be 64bit...thus it can't use the 32bit COM class.
There are 2 options (the clearest and easiest is option 1):
1) Get your IIS WebSite/Application to run as 32bit, so it can access your already registered 32bit COM component.
To make sure your website is running as 32bit too (instead of as 64bit)...change the DefaultAppPool to enable 32bit applications (or you can create a new AppPool which is 32bit specifically for that webservice/site and make it use it...if you don't want to affect other sites).
https://help.webcontrolcenter.com/kb/a1114/how-to-enable-32-bit-application-pool-iis-7-dedicatedvps.aspx
OR
2) Do some additional registration so that your COM class is available to 64bit clients too (you register it so it is run OUT OF PROCESS...so it can be consumed by either 32bit or 64bit clients....but you might not want that for perf reasons...and it might not always be possible)
http://www.gfi.com/blog/32bit-object-64bit-environment/

Error 404 - file not found on Silverlight RIA service call

I have search everywhere for a solution to my problem, but I am not able to find one. I have built a Silverlight 4 Navigation app, and am using RIA Services to process a custom entity (which is essentially running server-side calls to COM dlls). In my debug environment, everything works fine, but when I try to deploy to IIS7 (on the development machine) as a website, it gives me the following error when calling the Get query on the entity:
Load operation failed for query 'GetNewHWCoil'. The remote server returned an error: NotFound.
at System.ServiceModel.DomainServices.Client.OperationBase.Complete(Exception error)
at System.ServiceModel.DomainServices.Client.LoadOperation.Complete(Exception error)
at System.ServiceModel.DomainServices.Client.DomainContext.CompleteLoad(IAsyncResult asyncResult)
at System.ServiceModel.DomainServices.Client.DomainContext.<>c__DisplayClass1b.<Load>b__17(Object )
Everything I found online says to check the Authentication area on IIS and make sure that it is set only to Anonymous Authentication, which it is. And they also say to enable WCF logging, which when I add the necessary text to the web.config file, I still don't get any logs. They also say to use Fiddler2 to trace the HTTP calls, but I only get a 404 error on there with the textview giving me the standard IIS file not found website. I cannot figure out how to debug this problem.
The Silverlight app needs to make calls to a set of 3rd party COM dlls to calculate the performace of water coils. Since I do not want to have the app run OOB, (this will negate the whole point of it being a web app instead of a WPF app) I have the ASP.net project interacting with the dlls using the custom entities.
The function (or Query as RIA services calls it) GetNewHWCoil is located in the DomainService class and uses this code:
Public Function GetNewHWCoil() as HWCoil 'HWCoil is a custom object
If bRanCalc then 'bRanCalc is a global boolean variable that gets set to true if the calc call on the dlls have been made
Return mHWCoil 'global copy of the calculated coil object
bRanCalc = False
else
Return New HWCoil
end if
End Function
The error runs before any calculation should be called, so it is assumed that it is erroring on the 'Return New HWCoil' part.
Any help on this would be appreciated.
Thanks,
Chris
I found the solution to my problem. I fonud out that I can have VS run the debug from IIS, and when I had it create the virtual directory it told me I needed to install ASP.NET 4 on the server. I thought that by checking the ASP.NET checkbox in the Add Windows Features dialog that I had already done that. But it only installed .NET 2 version. So after looking online for this new problem, I found that I needed to run the command
C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis -i
and everything worked fine after that.
Chris

FluentNHibernate blows up in Windows Service but not website

I've got a class library doing all my NHibernate stuff. It also handles all the mapping using Fluent NHibernate - no mapping files to deploy.
This class library is consumed by a number of apps, including a Windows Service running on my computer. Although it works fine in all my web apps, the Windows Service gets this when it tries to use NHibernate:
An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory()
at Kctc.NHibernate.KctcSessionFactory.get_SessionFactory() in C:\Kctc\Trunk\Kctc.NHibernate\KctcSessionFactory.cs:line 28
...more stack trace...
I have checked for an InnerException and there doesn't appear to be one. I have no idea what the PotentialReasons collection is, and Google doesn't seem to be forthcoming either.
This is my dev machine, so when I'm working on my web apps they run locally (i.e. using the web server in Visual Studio). The fact that the Windows Service and my dev web apps are running on this same machine suggest it's not to do with trust settings or what have you.
Can anyone suggest what I should try? This is one of those ones where I'm so stumped I can't even think of how to get more information about the problem.
Just a wild guess. NHibernate picks up the hibernate.cfg.xml file from the execution directory. Did you configure the execution directory of the service that it can find this file?
I've found out what the problem is. The Service did not deploy with the required NHibernate.ByteCode.LinFu.dll.
I appear to have an ongoing problem with the Visual Studio compiler not always copying indirect dependencies (i.e. dlls required by class libraries required by the app) into the output folder during the build. I should have thought of this sooner really.
Thanks for racking your brains on my behalf guys.
I bet the name of the connection string is missing from the app.config. For me that message is almost exclusively a missing connection string.
Are you targeting the same database or could it be some sort of schema mismatch between databases?
Could it be authentication issues on the service like you use windows authentication where it can't be used (or the sql authentication that doesn't work)?
It's hard to tell when there is no code, just an exception!
EDIT Are you ever using HttpContext, HostingEnvironment or anything else specific to "web"?

WCF can only serialize parameters on development machine

I have created a WCF service using vb.net. Everything works fine on my development machine but when I deployed it it failed with the following error
'There was an error while trying to deserialize parameter http://tempuri.org/:querys'
I call a single method on the service and it has a single parameter called 'querys'. This parameter was a list(Of CustomType).
I then created a new method with a single parameter of type ArrayList. Thinking that this should serialize. Again it works fine on my development machine but fails when I deploy it with the same error a above.
I am completely stumped how it can serialize a parameter on one machine and not on another. I've tried it on 2 other machine and it doesn't work on either of them. So that rules out a problem with the machine itself.
All machines are running Win XP and .Net v3.5. The service was developed using VB .net in Visual Studio 2008.
Has anyone else experienced this?
I have not included any code because the error is happening System.ServiceModel and as I mentioned above the code does work on the development machine.
Please let me know if you need any more information.
Thanks in advance
Did you mark your 'CustomType' and its fields/properties you want to serialize with attribute DataContract, DataMember?
When you add the service reference to your client app which setting do you use? (Reuse types in referenced assemblies, always generate message contracts...)
If you host the WCF service on a IIS, then you should remember to run this command on the servers.
C:\WINDOWS\Microsoft.NET\Framework\v3.0\Windows Communication Foundation\ServiceModelReg.exe /i /x
Thanks to everyone who replied,
I have resolved the problem but unfortunately do not how. I tried many code changes but as far as I can tell I have reset the code back to the way it was. It is working now and I can not spend any more time on the issue to find out what caused it.
Just one of those things I guess.

Getting System.ServiceModel.CommunicationObjectAbortedException from a single client

We have a customer in the field that installed our client app on a new machine. When they try and login; which calls a WCF web service; they get the following error:
System.ServiceModel.CommunicationObjectAbortedException
"The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it has been Aborted."
They installed on another machine, and had no problem. The app is installed at several locations with no problems.
Any idea why it does not work on a single machine? The machine is running Windows 7, but the app is running on other machines with Windows 7.
Any ideas would be appreciated.
How are you making your calls to the service?
From what you've said it sounds a bit like the service call is failing and somehow you are trying to make a method call on the object that implements IChannel, i.e., it's in a using block and the dispose method is blowing up.
Post some code?
Here is the code:
try {
userService = Services.UserServiceClient();
LoggedInUser.User = userService.Login(tbUsername.Text, tbPassword.Text);
userService.Close();
}
catch... { }
But, like I said above, it is working on several other computers with no problems. Just not working on a single computer. Was thinking maybe some .net lib needs installed or something.