Tuesday 13 November 2012

Assembly failed to load 0x80131515

We have a custom activity which loads assembly using reflection, this is working fine however when we copied assembly to system test it started failing over with following error.

Unhandled Exception: Microsoft.Xrm.Sdk.InvalidPluginExecutionException: An error occurred in the XYZ plug-in.
   at name.customactivity.Execute(CodeActivityContext executionContext)
   at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
   at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)
Inner Exception: System.IO.FileLoadException: Could not load file or assembly 'file:///C:\Program Files\Microsoft Dynamics CRM\Server\bin\assembly\anotherassembly.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)
   at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark)
   at System.Reflection.Assembly.LoadFrom(String assemblyFile)
   at E2.Crm.SharePoint.Interfaces.EntitySpIntegrationFactory`1.FetchInstance(Entity entity)
   at E2.Lbh.Crm.SharePointIntegration.InitialiseSPDocStore.Execute(CodeActivityContext executionContext)
Inner Exception: System.NotSupportedException: An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default, so this load may be dangerous. If this load is not intended to sandbox the assembly, please enable the loadFromRemoteSources switch. See http://go.microsoft.com/fwlink/?LinkId=155569 for more information


Resolution: When assembly was copied it had a protected check box enabled, which was causing issues to not load propertly. Right click on assembly and go to properties and un-check protected option.
(This option sometime gets enabled automatically when copied across network)

No comments:

Post a Comment