【解决问题】加载网络映射盘中的assembly失败
2011-08-05 17:00
597 查看
我有一个网络映射盘,盘符是Z:。在Z盘下面,放了一个assembly,名为test.dll。然后,我在VS2010中建立了一个.NET 4.0的工程,程序中有下面一段代码:
深入到内部异常: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=155569 for more information.。
看来是.NET的安全机制阻止加载一个网络上(本地网或者互联网)的assembly。
【办法一】
根据提示,找到了MSDN的一篇文章。文章给出的解决办法是:在程序的配置文件中加入下面的xml片段:
按照这个解决办法,程序运行正确。
MSDN链接:http://msdn.microsoft.com/en-us/library/dd409252(VS.100).aspx。
【办法二】
Assembly类有一个静态函数UnsafeLoadFrom,这个函数在加载一个assembly的时候,不会进行一些安全检查。将原先的代码修改如下即可:
【办法三】
Assembly的load方法有很多的重载,可以使用其中的一个参数为byte[]的load函数。代码如下:
string dll = @"Z:\test.dll"; Assembly a = Assembly.LoadFrom(dll);执行代码,抛出FileLoadException异常:Could not load file or assembly 'file:///Y:\bb\nvo_cas.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)。
深入到内部异常: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=155569 for more information.。
看来是.NET的安全机制阻止加载一个网络上(本地网或者互联网)的assembly。
【办法一】
根据提示,找到了MSDN的一篇文章。文章给出的解决办法是:在程序的配置文件中加入下面的xml片段:
<configuration> ...... <runtime> <!-- WARNING: will load assemblies from remote locations as fully trusted! --> <loadFromRemoteSources enabled="true" /> </runtime> ...... </configuration>
按照这个解决办法,程序运行正确。
MSDN链接:http://msdn.microsoft.com/en-us/library/dd409252(VS.100).aspx。
【办法二】
Assembly类有一个静态函数UnsafeLoadFrom,这个函数在加载一个assembly的时候,不会进行一些安全检查。将原先的代码修改如下即可:
string dll = @"Z:\test.dll"; Assembly a = Assembly.UnsafeLoadFrom(dll);
【办法三】
Assembly的load方法有很多的重载,可以使用其中的一个参数为byte[]的load函数。代码如下:
string dll = @"Z:\test.dll"; ; byte[] assemblyBuffer = File.ReadAllBytes(dll); Assembly a = Assembly.Load(assemblyBuffer);
相关文章推荐
- 加载网络映射盘中的assembly失败
- 加载网络映射盘中的assembly失败
- C# 加载网络映射盘中的assembly失败
- Donet 加载网络映射盘中的assembly失败
- 加载网络映射盘中的assembly失败的处理办法
- 解决Com类组建加载失败的问题!
- 解决Windows下网络原因Composer安装失败问题
- visual statio 2012加载cocos2dx项目失败问题解决
- jquery easyui easyloader加载外部js文件失败问题解决
- 【JavaScript】10.解决chplayer视频播放器在本地能加载视频,放到服务器上加载视频失败的问题
- vs2005水晶报表WEB打印问题、加载报表失败。-解决办法 (ZT)
- [android]完美解决ListView加载网络图片乱跳问题
- 解决“ .dll(或.ocx)控件已加载,但对DllregisterServer的调用失败,错误代码为0x80004005”问题的两种终极方法:SubInACL安装 VS 命令提示符
- “Could not load file or assembly 。。。试图加载格式不正确的程序”的问题解决
- LInux下可以使用命令自动与网络的NTP服务器同步时间 CSDN验证码验证失败问题解决
- Android 在不同架构中用到.so加载失败的问题研究与解决办法
- Foxmail接收邮件时,报出"网络操作失败","POP3:****"问题的解决办法
- 解决Visual Studio 2005 包加载失败问题。解决SQlserver企业管理器无法启动,SQLDMO未注册问题。
- 解决动态调用其他APK中的类so加载失败问题