none
Setting SetThreadPrincipal property on new AppDomain with new Logged On Users causes DLLs to not be loaded RRS feed

  • Question

  • We are running WCF services each in its own AppDomain. One of the options we have is to run the service as a specific user. We do that by calling LogonAsUser and then call SetThreadPrincipal() with the new Logged on User Identity. This worked just fine in .net 3.5. But now that we are running with .net 4.0 we get errors indicating dlls can't be found.

    If I run on Windows XP it works OK. But when running on Windows 2008 Server I get the exceptions.

    If we don't call the SetThreadPrincipal() method and just load the AppDomain, the WCF service starts with no problems.

    I also tried added the user Account being used to the Administrators group.

    What may have changed between .net 3.5 and 4.0 to cause the AppDomain to not be able to find the DLLs.

    I am guessing it is a security issue but I don't know how to find it. The FusLogVw tool does not log any errors when the AppDomain tries to load.

    Here are some of the exceptions thrown

    ExType: 'TypeInitializationException'. Error: The type initializer for 'System.ServiceModel.Diagnostics.TraceUtility' threw an exception.
    StackTrace:    at System.ServiceModel.Diagnostics.TraceUtility.SetEtwProviderId()
       at System.ServiceModel.ServiceHostBase..ctor()
       at System.ServiceModel.ServiceHost..ctor(Type serviceType, Uri[] baseAddresses)
       at ECollective.ECServer.ECServices.HostedService.Impl.HostedServiceBase.StartWcfServiceHost()

    ExType: 'FileLoadException'. Error: Could not load file or assembly 'System.Runtime.DurableInstancing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The handle is invalid. (Exception from HRESULT: 0x80070006 (E_HANDLE))
    StackTrace:    at System.ServiceModel.Diagnostics.TraceUtility.SetEtwProviderId()
       at System.ServiceModel.Diagnostics.TraceUtility..cctor()

    ExType: 'FileLoadException'. Error: Could not load file or assembly 'System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The handle is invalid. (Exception from HRESULT: 0x80070006 (E_HANDLE))

    Tuesday, March 8, 2011 10:13 PM

Answers

  •  

    From Vista, Windows introduced a new feature called User Account Control (UAC), even though user logged on with administrator account, he perform common tasks as standard-user, not admin. User has to elevate itself to admin when he try to access objects of higher security level. In this case, you can run your application as administrator by right-clicking the executable and then select 'run as administrator', hope it can helps.


    Eric Yang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by eryang Monday, March 21, 2011 8:23 AM
    Wednesday, March 9, 2011 6:03 AM