Plugin从Sync改为Async后报Could not load file or assembly错误

问题:之前运行好好的一个PLUGIN,PostCreate,Synchronous

这次想改成异步的,结果设定为Asynchronous之后,在系统作业中发现全部运行失败了,


打开看到详细信息如下:

Unhandled 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.Activator.CreateInstance(Type type, Boolean nonPublic)
   at System.Activator.CreateInstance(Type type)
   at Microsoft.Crm.Asynchronous.VersionedProxyPluginBase.CreatePlugin[T](Type pluginType, AsyncExecutionContext context)
   at Microsoft.Crm.Asynchronous.V5ProxyPlugin..ctor(Type type, AsyncExecutionContext context, Boolean& isValid)
   at Microsoft.Crm.Asynchronous.EventOperation.InternalExecute(AsyncEvent asyncEvent)
   at Microsoft.Crm.Asynchronous.AsyncEventHandlerCommand`1.Execute(IAsyncEvent asyncEvent)
   at Microsoft.Crm.Asynchronous.AsyncEventExecutionManager`2.ExecuteCommand(IAsyncEventHandlerFactory handlerFactory)
   at Microsoft.Crm.Asynchronous.AsyncEventExecutionManager`2.ExecuteHandler(IAsyncEventHandlerFactory handlerFactory)
   at Microsoft.Crm.Asynchronous.PoolHandler.ProcessAsyncEvent(IAsyncEventExecutionManager asyncEventExecutionManager)
Inner Exception: System.TypeInitializationException: The type initializer for '******.MSCrm.Plugins.new_******' threw an exception.
   at ******.MSCrm.Plugins.******..ctor()
Inner Exception: System.IO.FileNotFoundException: Could not load file or assembly 'log4net, Version=1.2.9.0, Culture=neutral, PublicKeyToken=b32731d11ce58905' or one of its dependencies. The system cannot find the file specified.
   at ******.MSCrm.Plugins.new_******..cctor()

发现是由于找不到第三方的dll【log4net.dll】造成,因为在PLUGIN当中引用了该dll写log。那为什么之前Sync的时候就可以,改成Async就不行了呢?
原来是因为之前把log4net.dll放到了前端服务器的D:\Program Files\Microsoft Dynamics CRM\CRMWeb\bin目录下,但是如果改成Async时就应该log4net.dll放到异步服务所在的服务器的CRM安装目录下,并且详细目录和Sync稍有不同,应该放在D:\Program Files\Microsoft Dynamics CRM\Server\bin目录下。

备注:

  • 文件放进去之后并不会马上生效,需要重启异步服务所在的服务器
  • 异步作业读取的config文件不再是web.config,而是位于D:\Program Files\Microsoft Dynamics CRM\Server\bin目录下的CrmAsyncService.exe.config文件

猜你喜欢

转载自www.cnblogs.com/cndota2/p/12097988.html