Search This Blog

Tuesday, July 19, 2011

CRM 2011: Plugin Registration Tool Error - Unable to load assembly !!


Recently I wrote a custom workflow to create a direct URL for a record within CRM & output the formatted URL, so that it can be used in email alerts to the users.
I faced this peculiar problem while I was registering the custom workflow assembly using the new Plugin Registration tool on my client server. I was unable to load my custom workflow assembly onto the plugin registration tool, whenever I choose to load the assembly on the tool, it gave me an error message:
Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'file:///C:\Plugin Registration Tool\PluginRegistration.exe' 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, Evidence securityEvidence)
   at System.Activator.CreateInstanceFromInternal(String assemblyFile, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo)
   at System.AppDomain.CreateInstanceFrom(String assemblyFile, String typeName)
   at System.AppDomain.CreateInstanceFromAndUnwrap(String assemblyName, String typeName)
   at System.AppDomain.CreateInstanceFromAndUnwrap(String assemblyName, String typeName)
   at PluginRegistrationTool.AppDomainContext`1..ctor() in C:\pluginregistration\AssemblyReader.cs:line 41
   at PluginRegistrationTool.RegistrationHelper.RetrievePluginsFromAssembly(String pathToAssembly) in C:\pluginregistration\RegistrationHelper.cs:line 40
   at PluginRegistrationTool.PluginRegistrationForm.btnLoadAssembly_Click(Object sender, EventArgs e) in C:\pluginregistration\PluginRegistrationForm.cs:line 166
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.
The reason I got this error was on the client server was that, the file was blocked on the server !!
Yes, now on some new server OS’s, this feature is enabled by default i.e. any external file that you deploy on the server will be blocked. You have to exclusively unblock the file & then use it to deploy!!
On suggestions from one of my peers, I unblocked the files (workflow assembly & all the files within the plugin registration tool) & then it worked like a charm!!  Everything went smooth later on!!
Unblocking the files: Right click on the file & if you see a unblock button on the properties dialog, then unblock it, else the file is already unblocked!!

I had a day wasted due to this small thing!! hope this helps someone !!

Thanks !!

6 comments:

  1. Thanks Srinath
    Helped a lot to save time today
    Cheers
    Chris

    ReplyDelete
  2. Hi,
    I'm having the same error, I had Unblock and I clicked it but it didn't work.
    Why? Any other solutions to suggest?

    ReplyDelete
  3. THanks a lot. THis saved me some time today.

    ReplyDelete
  4. Thanks for this. Saved a lot of potentially wasted time.

    ReplyDelete