• 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 FilesMicrosoft Dynamics CRMCRMWebin目录下,但是如果改成Async时就应该log4net.dll放到异步服务所在的服务器的CRM安装目录下,并且详细目录和Sync稍有不同,应该放在D:Program FilesMicrosoft Dynamics CRMServerin目录下。

    备注:

    • 文件放进去之后并不会马上生效,需要重启异步服务所在的服务器
    • 异步作业读取的config文件不再是web.config,而是位于D:Program FilesMicrosoft Dynamics CRMServerin目录下的CrmAsyncService.exe.config文件
  • 相关阅读:
    Log4Net 全方位跟踪程序运行
    ASP.NET MVC 3和Razor中的@helper 语法
    C# 4.0四大新特性代码示例与解读
    程序员必读
    重学算法(1)--遍历二叉树
    重学算法-目录
    Epplus使用技巧
    JQuery 获取URL中传递的参数
    Epplus 使用案例
    .net调用存储过程详解(转载)
  • 原文地址:https://www.cnblogs.com/cndota2/p/12097988.html
Copyright © 2020-2023  润新知