0
votes

For 2 weeks we have been experiencing a small totally random issue with plugins in CRM 2015 OnPremise. When we make an upload, randomly and without much sense (at least according to analyze all code does not) plugins are throwing us the following exception:

The Web Service plug-in failed in OrganizationId: fb2630bc-8dc1-e411-80be-bae05bad392c; SdkMessageProcessingStepId: d2713f4e-51b7-e411-80b8-527d00dcf108; EntityName: new_serviciobase; Stage: 30; MessageName: Create; AssemblyName: Microsoft.Crm.Extensibility.InternalOperationPlugin, Microsoft.Crm.ObjectModel, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35; ClassName: Microsoft.Crm.Extensibility.InternalOperationPlugin; Exception: Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.

at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)

at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)

at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)

at System.Web.Services.Protocols.LogicalMethodInfo.Invoke(Object target, Object[] values)

at Microsoft.Crm.Extensibility.InternalOperationPlugin.Execute(IServiceProvider serviceProvider)

at Microsoft.Crm.Extensibility.V5PluginProxyStep.ExecuteInternal(PipelineExecutionContext context)

at Microsoft.Crm.Extensibility.VersionedPluginProxyStepBase.Execute(PipelineExecutionContext context)

Inner Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.

at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)

at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)

at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)

at System.Activator.CreateInstance(Type type, Boolean nonPublic)

at System.Activator.CreateInstance(Type type)

at Microsoft.Crm.Extensibility.VersionedPluginProxyStepBase.InitializePlugin[T](IOrganizationContext context, StepDescription stepDescription, SecureConfigurationCache stepSecureConfigurationCache, Type type)

at Microsoft.Crm.Extensibility.V5PluginProxyStep..ctor(Guid stepId, SecureConfigurationCache stepSecureConfigurationCache, CrmEventLog eventLog, IOrganizationContext context)

at Microsoft.Crm.Extensibility.PluginStep..ctor(Guid stepId, SecureConfigurationCache stepSecureConfigurationCache, CrmEventLog eventLog, IOrganizationContext context)

at Microsoft.Crm.Extensibility.PipelineStepFactory.CreateInstance(Guid stepId, IOrganizationContext context)

at Microsoft.Crm.Caching.PipelineStepCacheLoader.LoadCacheData(Guid key, ExecutionContext context)

at Microsoft.Crm.Caching.ObjectModelCacheLoader`2.LoadCacheData(TKey key, IOrganizationContext context)

at Microsoft.Crm.Caching.CrmMultiOrgCacheBase`2.CreateEntry(TKey key, IOrganizationContext context)

at Microsoft.Crm.Caching.CrmSharedMultiOrgCache`2.LookupEntry(TKey key, IOrganizationContext context)

at Microsoft.Crm.Caching.MessageProcessorCacheLoader.GetCustomizationLevel(MessageProcessor mp, ExecutionContext context)

at Microsoft.Crm.Caching.MessageProcessorCacheLoader.LoadCacheData(MessageProcessorKey key, ExecutionContext context) at Microsoft.Crm.Caching.ObjectModelCacheLoader`2.LoadCacheData(TKey key, IOrganizationContext context)

at Microsoft.Crm.Caching.CrmSharedMultiOrgCache`2.LookupEntry(TKey key, IOrganizationContext context)

at Microsoft.Crm.Extensibility.InternalMessageDispatcher.TryGetMessageProcessor(MessageProcessorKey key, ExecutionContext context)

at Microsoft.Crm.Extensibility.ExtensiblePlatformMessageDispatcher.IsPipelineDefined(MessageProcessorKey key, ExecutionContext context)

at Microsoft.Crm.Extensibility.ExtensiblePlatformMessageDispatcher.CreateWithInvocationSource(BusinessEntity entity, Int32 invocationSource, ExecutionContext context)

at Microsoft.Crm.BusinessEntities.BusinessProcessObject.Create(IBusinessEntity entity, ExecutionContext context)

Inner Exception: System.IO.FileLoadException: Could not load file or assembly ‘SCM.CRM.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=369abd01f82b8d9d’ or one of its dependencies. Access is denied.

at SCM.CRM.Plugins.Plugin..ctor(Type childClassName)

at SCM.CRM.Plugins.PLGServicioBase..ctor()

It brings a little headache because we don't understand what happened, just that sometimes fails and sometimes not ... we have a custom library registered plugins (disk) "SCM.Core.dll" to which says itself unable to access ... Any ideas?

3

3 Answers

1
votes

As @Sxntk said, you need to make sure you merge any plugins with ilmerge if you are using Sandbox mode isolation mode when registering the plugin assembly.

If you have an isolation mode of 'none', make sure the assembly is in the GAC or placed in the bin\assembly folder in the CRM installation directory on the server.

Hopefully this helps.

0
votes

I'm a coleague of Alexis, and now we have more details thanks to crmdiagtool:

System.IO.FileLoadException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #ED0C936C: System.IO.FileLoadException: Could not load file or assembly 'SCM.CRM.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=369abd01f82b8d9d' or one of its dependencies. Access is denied. File name: 'SCM.CRM.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=369abd01f82b8d9d'

0
votes

You can do the following thing:

  1. make sure all your referenced assemblies have "Copy Local" set to "True"
  2. unload the project from visual studio
  3. right click on the unloaded project and edit the csproj file
  4. add the following lines in the csproj file right before the "Project" end tag (before last line in the document):

    <Target Name="AfterResolveReferences">
        <ItemGroup>
          <EmbeddedResource Include="@(ReferenceCopyLocalPaths)" Condition="'%(ReferenceCopyLocalPaths.Extension)' == '.dll'">
            <LogicalName>%(ReferenceCopyLocalPaths.DestinationSubDirectory)%(ReferenceCopyLocalPaths.Filename)%(ReferenceCopyLocalPaths.Extension)</LogicalName>
          </EmbeddedResource>
        </ItemGroup>
      </Target>
  1. add this method to the plugin class:

    private static Assembly OnResolveAssembly(object sender, ResolveEventArgs args)
    {
    
        Assembly executingAssembly = Assembly.GetExecutingAssembly();
        AssemblyName assemblyName = new AssemblyName(args.Name);
        string path = assemblyName.Name + ".dll";
    
        if (assemblyName.CultureInfo.Equals(CultureInfo.InvariantCulture) == false)
        {
            path = String.Format(@"{0}\{1}", assemblyName.CultureInfo, path);
        }
    
        using (Stream stream = executingAssembly.GetManifestResourceStream(path))
        {
            if (stream == null)
                return null;
            byte[] assemblyRawBytes = new byte[stream.Length];
            stream.Read(assemblyRawBytes, 0, assemblyRawBytes.Length);
            return Assembly.Load(assemblyRawBytes);
        }
    }
    
  2. add the following constructor to the plugin class:

    static [Constructor name]()
    {
        AppDomain.CurrentDomain.AssemblyResolve += OnResolveAssembly;
    }
    
  3. rebuild and register your plugin

Doing this, all the referenced assemblies that are copied locally to your bin folder are packed into the main dll. The drawback is that you could end up having such a huge dll that you can not register it as a plugin.

Hope this helps, Cheers