问题
I have an old azure application which was running on the azure 1.2 SDK and relies on WIF for authentication.
I have recently been trying to update it to the latest SDK (1.4).
The applications compiles and runs on Azure, including authenticating with my STS. However some pages on the site just will not load throwing the following errors.
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
I have ensured that the WIF dependency is set to copy local - and it is working - some pages work!
any ideas on how to resolve this?
Edit: The error only occurs on pages that access tablestorage
回答1:
It looks like the error is caused by calling methods from Microsoft.WindowsAzure.ServiceRuntime which changes the appdomain of your webrole.
In order to get around this you can hardcode your connection string into your app (or use web.config) instead of the azure config. (A really poor solution to this problem)
Alternatively you can use the instructions at: http://blogs.infosupport.com/blogs/eriko/archive/2011/01/14/adding-assemblies-to-the-gac-in-windows-azure.aspx to add any assemblies that you have trouble with to the azure GAC.
Recommended reading if you encounter a similar issue:
http://social.msdn.microsoft.com/Forums/kk-KZ/windowsazuretroubleshooting/thread/35d37b41-b638-4023-aaab-b8134ac27278
http://blog.smarx.com/posts/how-to-resolve-setconfigurationsettingpublisher-needs-to-be-called-before-fromconfigurationsetting-can-be-used-after-moving-to-windows-azure-sdk-1-3
回答2:
So many people have run into this. I suppose this should be already FAQ. However suprizinly I could not find correct answer on stackoverflow. The problem here is that having Microsoft.IdentityModel.dll inside your bin directory is NOT enough. In few places configuration of Appdomain does not look at /bin, so it needs to be global, installed in GAC.
Follow steps described here: http://blogs.infosupport.com/blogs/eriko/archive/2011/01/14/adding-assemblies-to-the-gac-in-windows-azure.aspx. In short summary, you will need to create startup task and run this command:
gacutil /nologo /i .\Microsoft.IdentityModel.dll
来源:https://stackoverflow.com/questions/5495531/azure-sdk-1-4-wif-the-c-module-failed-to-load-while-attempting-to-initiali