Thursday 21 February 2013

Could not load file or assembly 'Microsoft.Crm.Sdk, Version=4.0.0.0, Culture=neutral

If ISV code is giving following error

Could not load file or assembly 'Microsoft.Crm.Sdk, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference
This is most likely due to latest version of CRM is installed which has 5.0.0.0 assembly, and ISV code was developed using Version=4.0.0.0 crm.sdk assembly.


To solve this issue open isv code's web.config file and add following config after <configSections> node and do an iis reset code.

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Crm.Sdk" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="4.0.0.0" newVersion="5.0.0.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

Monday 18 February 2013

An attempt was made to load an assembly from a network location


When trying to register an assembly (This assembly was extracted from existing unmanaged solution) through plugin registeration tool, i was getting following error

Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'file:///C:\Users\svccrmcapdev\Desktop\<<assembly name>>-<<guid>>\<<assembly name>>-<<guid>>\<<assembly name>>.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 Microsoft.Crm.Tools.PluginRegistration.AssemblyReader.LoadAssembly(String path)

   at Microsoft.Crm.Tools.PluginRegistration.AssemblyReader.RetrievePluginsFromAssembly(String path)

   at Microsoft.Crm.Tools.PluginRegistration.AssemblyReader.RetrievePluginsFromAssembly(String path)

   at Microsoft.Crm.Tools.PluginRegistration.RegistrationHelper.RetrievePluginsFromAssembly(String pathToAssembly)

   at Microsoft.Crm.Tools.PluginRegistration.PluginRegistrationForm.btnLoadAssembly_Click(Object sender, EventArgs e)

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.

--------

Resolutions: Right click on assembly and go to properties, In General tab, next to security label following message would be shown "This file came from another computer and might be block to help protect this computer". Click on Unblock to register this assembly through plugin registeration tool.