该应用程序是一个NPAPI插件,它通过UnmanagedExports使用.Net组件.我将其设计为低完整性应用程序,因此它必须位于用户的LocalLow目录中.
在我的应用程序中,我使用了一个动态装配加载机制来在运行时加载多个程序集我使用以下方法加载程序集,
MyInterface Instance; Assembly assembly = Assembly.LoadFrom(AssemblyFile); Type type = assembly.GetType(Identifier); // Identifier is implementing the MyInterface Instance = Activator.CreateInstance(type) as MyInterface; // Do something with the Instance
将项目修改为.Net 4.0后,我注意到当二进制文件放置在LocalLow目录中时,插件崩溃(在其他地方工作).我的下一步是创建一个简单的插件,最不可能的代码来解决这个问题.我注意到动态装配加载失败,出现以下异常,
System.IO.FileLoadException: Could not load file or assembly '<assemblyPath>' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515 (COR_E_NOTSUPPORTED)) ---> System.NotSupportedException: An attempt was made to load an assembly from a network location which would have caused the assembly to be sandBoxed in prevIoUs versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default,so this load may be dangerous. If this load is not intended to sandBox the assembly,please enable the loadFromremoteSources switch. See http://go.microsoft.com/fwlink/?LinkId=131738 for more information.
> http://blogs.msdn.com/b/shawnfa/archive/2009/06/08/more-implicit-uses-of-cas-policy-loadfromremotesources.aspx
> http://www.west-wind.com/weblog/posts/2009/Jan/19/Assembly-Loading-across-AppDomains
添加配置“loadFromremoteSources”也不起作用.似乎.Net组件不加载.dll.config文件. (可能是因为UnmanagedExporting)
我的问题是
>是否可以从LocalLow动态加载程序集?
> CLR 4.0中的新CAS策略是否也适用于LocalLow?从目前为止我所了解的,它只会影响通过网络加载的程序集
>还有其他办法克服这个问题吗?
解决方法
How can I get LabView to stop locking my .NET DLL?
原文地址:https://www.jb51.cc/csharp/96167.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。