none
Problem with WIF and WCF Dataservices

    Question

  • I'm running into a problem with the WCF dataservices loading in a different AppDomain when running in Azure. The WIF dll is working (other parts of the site also work, and copy local is true)

    Because it's a different appdomain I get errors like:

    Unable to find assembly 'Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.

    SerializationException: Unable to find assembly 'Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.]
       System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +4767763
       System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) +1725
       System.AppDomain.get_Id() +0
       <CrtImplementationDetails>.DoCallBackInDefaultDomain(IntPtr function, Void* cookie) +191
       <CrtImplementationDetails>.LanguageSupport._Initialize(LanguageSupport* ) +354
       <CrtImplementationDetails>.LanguageSupport.Initialize(LanguageSupport* ) +102

    [ModuleLoadException: The C++ module failed to load while attempting to initialize the default appdomain.
    ]
       <CrtImplementationDetails>.ThrowModuleLoadException(String errorMessage, Exception innerException) +50
       <CrtImplementationDetails>.LanguageSupport.Initialize(LanguageSupport* ) +169
       .cctor() +33

    How can I fix this?

    Erik

     

    Wednesday, January 12, 2011 8:52 AM

Answers

  • Still not sure WHY WCF dataservices uses a different AppDomain, but the supported solution to add WIF to the GAC is through Windows Update:

    Register this Startup task, together with the WIF msu file, set copy to output to true.

    @echo off

    sc config wuauserv start= demand

    wusa.exe "%~dp0Windows6.1-KB974405-x64.msu" /quiet /norestart

    sc config wuauserv start= disabled

    • Marked as answer by Erik Oppedijk Monday, January 17, 2011 10:59 AM
    Monday, January 17, 2011 10:59 AM

All replies

  • When adding an STS to a project and run in the cloud I get the error of

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Runtime.Serialization.SerializationException: Unable to find assembly 'Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Stack Trace:

    [SerializationException: Unable to find assembly 'Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.]
      System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +4767763
      System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) +1725
      System.AppDomain.get_Id() +0
      <CrtImplementationDetails>.DoCallBackInDefaultDomain(IntPtr function, Void* cookie) +191
      <CrtImplementationDetails>.LanguageSupport._Initialize(LanguageSupport* ) +354
      <CrtImplementationDetails>.LanguageSupport.Initialize(LanguageSupport* ) +102
    
    [ModuleLoadException: The C++ module failed to load while attempting to initialize the default appdomain.
    ]
      <CrtImplementationDetails>.ThrowModuleLoadException(String errorMessage, Exception innerException) +50
      <CrtImplementationDetails>.LanguageSupport.Initialize(LanguageSupport* ) +169
      .cctor() +33
    
    [TypeInitializationException: The type initializer for '<Module>' threw an exception.]
      Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.GetConfigurationSettingValue(String configurationSettingName) +0
      GuestBook_WebRole.Global.<Application_Start>b__0(String configName, Func`2 configSetter) in C:\WAPTK\Labs\IntroductionToWindowsAzureVS2010\Source\Ex3-WindowsAzureDeployment\CS\Begin\GuestBook_WebRole\Global.asax.cs:35
      Microsoft.WindowsAzure.CloudStorageAccount.FromConfigurationSetting(String settingName) +123
      GuestBook_Data.GuestBookDataSource..cctor() in C:\WAPTK\Labs\IntroductionToWindowsAzureVS2010\Source\Ex3-WindowsAzureDeployment\CS\Begin\GuestBook_Data\GuestBookDataSource.cs:33
    
    [TypeInitializationException: The type initializer for 'GuestBook_Data.GuestBookDataSource' threw an exception.]
      GuestBook_Data.GuestBookDataSource..ctor() in C:\WAPTK\Labs\IntroductionToWindowsAzureVS2010\Source\Ex3-WindowsAzureDeployment\CS\Begin\GuestBook_Data\GuestBookDataSource.cs:45
    
    [TargetInvocationException: Exception has been thrown by the target of an invocation.]
      System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
      System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache) +117
      System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache) +247
      System.Activator.CreateInstance(Type type, Boolean nonPublic) +106
      System.Web.UI.WebControls.ObjectDataSourceView.InvokeMethod(ObjectDataSourceMethod method, Boolean disposeInstance, Object& instance) +476
      System.Web.UI.WebControls.ObjectDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +1992
      System.Web.UI.WebControls.DataList.CreateControlHierarchy(Boolean useDataSource) +546
      System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e) +178
      System.Web.UI.WebControls.BaseDataList.EnsureDataBound() +90
      System.Web.UI.Control.EnsureChildControls() +182
      System.Web.UI.Control.PreRenderRecursiveInternal() +60
      System.Web.UI.Control.PreRenderRecursiveInternal() +222
      System.Web.UI.Control.PreRenderRecursiveInternal() +222
      System.Web.UI.Control.PreRenderRecursiveInternal() +222
      System.Web.UI.Control.PreRenderRecursiveInternal() +222
      System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4185
    


    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1

    Server Error in '/' Application.

    Unable to find assembly 'Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.

     

    Steps to reproduce error:

    1) I took the hands-on lab "introduction to windows azure" and started with excercise 3, deployed to the cloud - works

    2) Run the ADD STS wizard, change <deny anonymous> to <allow anonymous> deploy, receive error missing IdentityModel.dll

    3) Add reference to microsoft.identitymodel.dll, set copy local to true, deploy to cloud, new error

     This seems like an Appdomain problem, how do I fix this?

    Erik

    • Merged by Mog Liang Friday, January 14, 2011 2:29 AM
    Thursday, January 13, 2011 1:44 PM
  • Hi Erik. It might be useful to see if the Federated Authentication in a Windows Azure Web Role Application lab from the Windows Azure Platform Training Kit works. Running the lab’s dependency checker and setup script may tell you something.


    David Pallmann GM Application Development, Neudesic Windows Azure MVP
    Thursday, January 13, 2011 9:25 PM
  • Hi Erik,

    >3) Add reference to microsoft.identitymodel.dll, set copy local to true, deploy to cloud, new error

    What is the new error? Could you post a demo project that can reproduce this issue (work locally but failed after deployment to cloud)?


    Allen Chen [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.

    Friday, January 14, 2011 6:20 AM
    Moderator
  • Hi Allen,

    The new error is in my post above, just read it carefully, it looks like the .NET error "could not loud assembly", but this one has a stack trace with some remoting in it.

    I used the standard GuestBook demo application from the WAPTK (intro to azure, exercise 3), NO code changes

    Added an STS reference (to an appfabriclabs ACS)

    and after the deploy (with copy local to true) I get this error.

    Friday, January 14, 2011 8:10 AM
  • Hi David,

    In the Federated Authentication in a Windows Azure Web Role Application lab there are no calls to a WCF Data Service, just a simple page displaying some user information. I did this lab in the past and it works (just like all the labs in the WAPTK)

    In the setup script is nothing special. And to fix my problem, you need a setup script running in the cloud...

    Erik

    Friday, January 14, 2011 8:27 AM
  • Hi,

    Just a thought, could you use elevated startup task to add this assembly to GAC? Does it work?


    Allen Chen [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.

    Friday, January 14, 2011 9:12 AM
    Moderator
  • Yes, installing to the GAC makes it work, but that's just working around the problem.

    That means that I need to register all components to the GAC.
    Vittorio mentioned a new EULA which allows us to redistribute WIF with our app.

    My question remains, WHY does WCF Dataservices use remoting and uses another AppDomain.

    Erik

    Friday, January 14, 2011 9:46 AM
  • >That means that I need to register all components to the GAC.

    Not exactly. I think only assemblies like this specific one need to be added to GAC.

    >My question remains, WHY does WCF Dataservices use remoting and uses another AppDomain.

    Please provide your implementation about the WCF Data Services and let me know where/how WIF is used. Some code snippet/config is required to answer this question.


    Allen Chen [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.

    Friday, January 14, 2011 10:02 AM
    Moderator
  • It's exactly from the sample GuestBook_Data project:

     public IEnumerable<GuestBookEntry> GetGuestBookEntries()
            {
                var results = from g in this.context.GuestBookEntry
                              where g.PartitionKey == DateTime.UtcNow.ToString("MMddyyyy")
                              select g;
                return results;
            }
     public class GuestBookDataContext
            : Microsoft.WindowsAzure.StorageClient.TableServiceContext
        {
            public GuestBookDataContext(string baseAddress, Microsoft.WindowsAzure.StorageCredentials credentials)
                : base(baseAddress, credentials)
            { }

            public IQueryable<GuestBookEntry> GuestBookEntry
            {
                get
                {
                    return this.CreateQuery<GuestBookEntry>("GuestBookEntry");
                }
            }
        }

    WIF is configured (Add STS reference) but no other WIF code is used to trigger this error.

    Could be that the WCF dataservices try to add the (WIF)securitycontext to the call and serialize that?

    Erik

    Friday, January 14, 2011 10:24 AM
  • Hi Erik,

    Could you send the repro project to me to test? My email is allenc at microsoft.com


    Allen Chen [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.

    Monday, January 17, 2011 6:35 AM
    Moderator
  • Still not sure WHY WCF dataservices uses a different AppDomain, but the supported solution to add WIF to the GAC is through Windows Update:

    Register this Startup task, together with the WIF msu file, set copy to output to true.

    @echo off

    sc config wuauserv start= demand

    wusa.exe "%~dp0Windows6.1-KB974405-x64.msu" /quiet /norestart

    sc config wuauserv start= disabled

    • Marked as answer by Erik Oppedijk Monday, January 17, 2011 10:59 AM
    Monday, January 17, 2011 10:59 AM
  • We're experiencing this exception also, but we're not using using web services in our app. 

    Our diagnosis so far has isolated the problem to calling RoleEnvironment.GetConfigurationSettingValue() in a web role deployed using Full IIS (as per http://blogs.msdn.com/b/windowsazure/archive/2010/12/02/new-full-iis-capabilities-differences-from-hosted-web-core.aspx).

    The remoting is presumably the the interop between w3wp.exe and WaIISHost.exe.

    Microsoft.IdentityModel is referenced with copy local true, so how is it that WaIIHost.exe cannot load/locate it?

     

    Andy.

    Friday, January 21, 2011 3:47 AM
  • Hello Erik, 

     

    Can you walk me through or guide me to the steps that are required to register this startup task? 

     

    I am getting "Unable to find assembly 'Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'" error while running the application which is deployed on Azure. 

    The application works fine on Dev Environment and I've ensured that the Microsoft.IdentityModel has Copy Local set to true.

    Thanks,

    Harish

    Wednesday, March 23, 2011 11:21 AM
  • I got it. Thanks Erik.
    Wednesday, March 23, 2011 2:45 PM
  • Nice to hear you've got it working

    I've also blogged about this solution here:

    http://blogs.infosupport.com/blogs/eriko/archive/2011/01/14/adding-assemblies-to-the-gac-in-windows-azure.aspx

     

    Thursday, March 24, 2011 9:28 AM