【问题标题】:"An unexpected error ocurred" CRM2015 OnPremise Plugins“发生意外错误”CRM 2015 On Premise 插件
【发布时间】:2015-07-13 15:12:08
【问题描述】:

2 周来,我们在 CRM 2015 OnPremise 中遇到了一个完全随机的小问题。当我们进行上传时,随机且没有多大意义(至少根据分析所有代码没有)插件向我们抛出以下异常:

Web Service 插件在 OrganizationId 中失败: fb2630bc-8dc1-e411-80be-bae05bad392c; SdkMessageProcessingStepId: d2713f4e-51b7-e411-80b8-527d00dcf108;实体名称:new_serviciobase; 阶段:30;消息名称:创建;大会名称: Microsoft.Crm.Extensibility.InternalOperationPlugin, Microsoft.Crm.ObjectModel,版本=7.0.0.0,文化=中性, PublicKeyToken=31bf3856ad364e35;班级名称: Microsoft.Crm.Extensibility.InternalOperationPlugin;例外: 未处理的异常:System.Reflection.TargetInvocationException: 调用的目标已抛出异常。

在 System.RuntimeMethodHandle.InvokeMethod(对象目标,对象 [] 参数、签名 sig、布尔构造函数)

在 System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj,Object[] 参数,Object[] 参数)

在 System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr,Binder binder,Object[]参数, CultureInfo 文化)

在 System.Web.Services.Protocols.LogicalMethodInfo.Invoke(对象 目标,Object[] 值)

在 Microsoft.Crm.Extensibility.InternalOperationPlugin.Execute(IServiceProvider 服务提供者)

在 Microsoft.Crm.Extensibility.V5PluginProxyStep.ExecuteInternal(PipelineExecutionContext 上下文)

在 Microsoft.Crm.Extensibility.VersionedPluginProxyStepBase.Execute(PipelineExecutionContext 上下文)

内部异常:System.Reflection.TargetInvocationException: 调用的目标已抛出异常。

在 System.RuntimeTypeHandle.CreateInstance(RuntimeType 类型, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)

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

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

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

在 System.Activator.CreateInstance(类型类型)

在 Microsoft.Crm.Extensibility.VersionedPluginProxyStepBase.InitializePlugin[T](IOrganizationContext 上下文、步骤描述、步骤描述、SecureConfigurationCache stepSecureConfigurationCache,Type 类型)

在 Microsoft.Crm.Extensibility.V5PluginProxyStep..ctor(Guid stepId, SecureConfigurationCache 步骤SecureConfigurationCache、CrmEventLog eventLog, IOrganizationContext 上下文)

在 Microsoft.Crm.Extensibility.PluginStep..ctor(Guid stepId, SecureConfigurationCache 步骤SecureConfigurationCache、CrmEventLog eventLog, IOrganizationContext 上下文)

在 Microsoft.Crm.Extensibility.PipelineStepFactory.CreateInstance(Guid stepId, IOrganizationContext 上下文)

在 Microsoft.Crm.Caching.PipelineStepCacheLoader.LoadCacheData(Guid 键,ExecutionContext 上下文)

在 Microsoft.Crm.Caching.ObjectModelCacheLoader`2.LoadCacheData(TKey key, IOrganizationContext 上下文)

在 Microsoft.Crm.Caching.CrmMultiOrgCacheBase`2.CreateEntry(TKey key, IOrganizationContext 上下文)

在 Microsoft.Crm.Caching.CrmSharedMultiOrgCache`2.LookupEntry(TKey 键,IOrganizationContext 上下文)

在 Microsoft.Crm.Caching.MessageProcessorCacheLoader.GetCustomizationLevel(MessageProcessor mp,ExecutionContext 上下文)

在 Microsoft.Crm.Caching.MessageProcessorCacheLoader.LoadCacheData(MessageProcessorKey 键,ExecutionContext 上下文) 在 Microsoft.Crm.Caching.ObjectModelCacheLoader`2.LoadCacheData(TKey key, IOrganizationContext 上下文)

在 Microsoft.Crm.Caching.CrmSharedMultiOrgCache`2.LookupEntry(TKey 键,IOrganizationContext 上下文)

在 Microsoft.Crm.Extensibility.InternalMessageDispatcher.TryGetMessageProcessor(MessageProcessorKey 键,ExecutionContext 上下文)

在 Microsoft.Crm.Extensibility.ExtensiblePlatformMessageDispatcher.IsPipelineDefined(MessageProcessorKey 键,ExecutionContext 上下文)

在 Microsoft.Crm.Extensibility.ExtensiblePlatformMessageDispatcher.CreateWithInvocationSource(BusinessEntity 实体、Int32 调用源、ExecutionContext 上下文)

在 Microsoft.Crm.BusinessEntities.BusinessProcessObject.Create(IBusinessEntity 实体,ExecutionContext 上下文)

内部异常:System.IO.FileLoadException:无法加载文件或 程序集‘SCM.CRM.Core,版本=1.0.0.0,文化=中性, PublicKeyToken=369abd01f82b8d9d' 或其依赖项之一。访问是 拒绝。

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

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

这有点让人头疼,因为我们不明白发生了什么,只是有时会失败,有时不会……我们有一个自定义库注册的插件(磁盘)“SCM.Core.dll”,它说自己无法访问...有什么想法吗?

【问题讨论】:

    标签: plugins dynamics-crm crm dynamics-crm-2015


    【解决方案1】:

    正如@Sxntk 所说,如果您在注册插件程序集时使用沙盒模式隔离模式,则需要确保将任何插件与 ilmerge 合并。

    如果您的隔离模式为“无”,请确保程序集位于 GAC 中或放置在服务器上 CRM 安装目录的 bin\assembly 文件夹中。

    希望这会有所帮助。

    【讨论】:

    • 隔离模式是“none”,昨天我们尝试在 GAC 中注册 dll,但这导致了很多关于 Miscrosoft Enterprise Library dll 引用的错误,现在我们的 crm 没用了,因为我没有不知道为什么当我们取消注册 GAC 的 dll 时,什么都没有改变...
    • 您是否尝试过将构建项目的 bin 文件夹中的所有内容放入 bin\assembly 文件夹中?听起来您缺少其他依赖项。
    【解决方案2】:

    我是 Alexis 的同事,现在我们有了更多的详细信息,这要感谢 crmdiagtool:

    System.IO.FileLoadException:Microsoft Dynamics CRM 遇到错误。管理员或支持的参考号:#ED0C936C:System.IO.FileLoadException:无法加载文件或程序集“SCM.CRM.Core,版本=1.0.0.0,Culture=neutral,PublicKeyToken=369abd01f82b8d9d”或其依赖项之一。访问被拒绝。 文件名:'SCM.CRM.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=369abd01f82b8d9d'

    【讨论】:

    • 如果你引用像“SCM.CRM.Core”这样的程序集,你需要将它与插件合并或放入你的GAC中
    【解决方案3】:

    你可以做以下事情:

    1. 确保所有引用的程序集都将“复制本地”设置为“真”
    2. 从 Visual Studio 中卸载项目
    3. 右键点击卸载的项目,编辑csproj文件
    4. 在 csproj 文件中的“Project”结束标记之前(文档最后一行之前)添加以下行:

        <Target Name="AfterResolveReferences">
            <ItemGroup>
              <EmbeddedResource Include="@(ReferenceCopyLocalPaths)" Condition="'%(ReferenceCopyLocalPaths.Extension)' == '.dll'">
                <LogicalName>%(ReferenceCopyLocalPaths.DestinationSubDirectory)%(ReferenceCopyLocalPaths.Filename)%(ReferenceCopyLocalPaths.Extension)</LogicalName>
              </EmbeddedResource>
            </ItemGroup>
          </Target>
    1. 将此方法添加到插件类中:

      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. 将以下构造函数添加到插件类:

      static [Constructor name]()
      {
          AppDomain.CurrentDomain.AssemblyResolve += OnResolveAssembly;
      }
      
    3. 重建并注册您的插件

    这样做,所有在本地复制到您的 bin 文件夹的引用程序集都被打包到主 dll 中。缺点是您最终可能会拥有如此庞大的 dll,以至于您无法将其注册为插件。

    希望这会有所帮助, 干杯

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-09
      • 2017-07-05
      • 1970-01-01
      • 2023-03-10
      • 2016-03-13
      相关资源
      最近更新 更多