我有一个网络映射盘,盘符是Z:。在Z盘下面,放了一个assembly,名为test.dll。然后,我在VS2010中建立了一个.NET 4.0的工程,程序中有下面一段代码:

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);

转载:http://blog.csdn.net/studying/article/details/6663627

加载网络映射盘中的assembly失败的更多相关文章

  1. 加载网络映射盘中的assembly失败的处理办法

    错误症状: 1.{"未能加载文件或程序集“file://*****”或它的某一个依赖项.不支持操作. (异常来自 HRESULT:0x80131515)":"file:/ ...

  2. android webview加载网络连接

    webview = (WebView) findViewById(R.id.webview); WebSettings webSettings = webview.getSettings(); //设 ...

  3. UITableView加载网络数据的优化

    UITableView加载网络数据的优化 效果 源码 https://github.com/YouXianMing/Animations // // TableViewLoadDataControll ...

  4. Spring加载Hibernate 映射的几种方式及区别

    LocalSessionFactoryBean有好几个属性用来查找hibernate映射文件: mappingResources.mappingLocations.mappingDirectoryLo ...

  5. 解决 org.apache.ibatis.binding.BindingException: Invalid bound statement (not found) 以及MyBatis批量加载xml映射文件的方式

    错误 org.apache.ibatis.binding.BindingException: Invalid bound statement (not found) 的出现,意味着项目需要xml文件来 ...

  6. 使用CEfSharp之旅(1) 加载网络页面

    原文:使用CEfSharp之旅(1) 加载网络页面 版权声明:本文为博主原创文章,未经博主允许不得转载.可点击关注博主 ,不明白的进群191065815 我的群里问 https://blog.csdn ...

  7. 使用异步任务加载网络上json数据并加载到ListView中

    Android中使用网络访问来加载网上的内容,并将其解析出来加载到控件中,是一种很常见的操作.但是Android的UI线程(也就是主线程)中是不允许进行耗时操作的,因为耗时操作会阻塞主线程,影响用户体 ...

  8. android122 zhihuibeijing 新闻中心NewsCenterPager加载网络数据实现

    新闻中心NewsCenterPager.java package com.itheima.zhbj52.base.impl; import java.util.ArrayList; import an ...

  9. Universal-Image-Loader解析(三)——用ListView和ViewPager加载网络中的图片

           现在我们终于可以通过这个框架来实现ListView中加载图片了,至于ViewPager还是别的,原理其实都是一样的 一.ListView 1.布局文件 list_layout.xml & ...

随机推荐

  1. MySQL 利用SQL线程对Binlog操作(转)

    背景: 对于MySQL的binlog的查看都是用其自带的工具mysqlbinlog进行操作的,其实还有另一个方法来操作binlog,就是Replication中的SQL线程去操作binlog,其实bi ...

  2. HTML 属性

    HTML 属性 HTML 元素 HTML 标题 属性为 HTML 元素提供附加信息. HTML 属性 HTML 标签可以拥有属性.属性提供了有关 HTML 元素的更多的信息. 属性总是以名称/值对的形 ...

  3. Async 和 Await的性能(.NET4.5新异步编程模型)

    异步编程长时间以来一直都是那些技能高超.喜欢挑战自我的开发人员涉足的领域 — 这些人愿意花费时间,充满热情并拥有心理承受能力,能够在非线性的控制流程中不断地琢磨回调,之后再回调. 随着 Microso ...

  4. 【并发编程】AQS学习

    一个简单的示例: package net.jcip.examples; import java.util.concurrent.locks.*; import net.jcip.annotations ...

  5. android的Looper例子

    直接贴代码 MsgThread.java package bb.aa.looperdemo; import android.os.Handler; import android.os.Looper; ...

  6. nginx 出现 13: Permission denied

    原文地址:http://www.nginx.cn/695.html 前段时间把程序员的wordpress升级到3.5.1,本身如果没有特别的插件,在后台更新就能完成. 更新完成后在后台发布文章,编辑器 ...

  7. CSS实现背景透明,文字不透明(各浏览器兼容)

    /*CSS*/.waps{ background:url(07158.bmp) no-repeat top center fixed; width:1004px; text-align:center; ...

  8. 网页爬虫--scrapy入门

    本篇从实际出发,展示如何用网页爬虫.并介绍一个流行的爬虫框架~ 1. 网页爬虫的过程 所谓网页爬虫,就是模拟浏览器的行为访问网站,从而获得网页信息的程序.正因为是程序,所以获得网页的速度可以轻易超过单 ...

  9. Android 自定义ScrollView 支持惯性滑动,惯性回弹效果。支持上拉加载更多

    先讲下原理: ScrollView的子View 主要分为3部分:head头部,滚动内容,fooder底部 我们实现惯性滑动,以及回弹,都是靠超过head或者fooder 就重新滚动到  ,内容的顶部或 ...

  10. PLSQL_PLSQL中DML/DDL/DCL的概念和区分(概念)

    2014-06-20 Created By BaoXinjian