简体   繁体   English

反序列化 - 未找到程序集问题c#

[英]Deserialization - assembly not found issue c#

I am working on assembly project and external program is executed through the assembly program. 我正在进行装配项目,外部程序通过装配程序执行。 System.Environment.CurrentDirectory assembly and Application.ExecutablePath paths are different due to external application. System.Environment.CurrentDirectory程序集和Application.ExecutablePath路径因外部应用程序而异。 System.Environment.CurrentDirectory is Assembly path. System.Environment.CurrentDirectory是程序集路径。 Application.ExecutablePath External application path. Application.ExecutablePath外部应用程序路径。 While deserialization it throw expcetion 反序列化时会抛出异常

assembly not found 没有找到装配

because "Application.ExecutablePath " not having my dlls . 因为"Application.ExecutablePath "没有我的dll。 So i want to change use System.Environment.CurrentDirectory path for deserialization. 所以我想更改使用System.Environment.CurrentDirectory路径进行反序列化。

I recommend setting up an AssemblyResolve event on the current domain. 我建议在当前域上设置AssemblyResolve事件。 That way you can explicitly determine where your DLLs are and load them if they're not found automatically. 这样,您可以明确确定DLL的位置,并在未自动找到它们时加载它们。

Jeremy Tammik wrote about it here: http://thebuildingcoder.typepad.com/blog/2014/05/rvtva3c-assembly-resolver.html Jeremy Tammik在这里写到: http ://thebuildingcoder.typepad.com/blog/2014/05/rvtva3c-assembly-resolver.html

The only thing to be careful of is that you should make sure the event is looking specifically for your DLLs (not any DLLs) - and that if it's not appropriate for you to load a DLL you return null (I occasionally run into scenarios where other people's addins don't implement this nicely, and it messes up my addin doing it). 唯一要注意的是你应该确保事件专门针对你的DLL(而不是任何DLL) - 并且如果它不适合你加载DLL你返回null(我偶尔遇到其他情况)人们的插件不能很好地实现这一点,它会让我的插件搞砸了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM