在使用Ironpython引用WebDriver程序集做web自动化时碰到这个问题,出问题的代码很简单,如下:

import sys

import clr

clr.AddReferenceToFileAndPath(r"c:\WebDriver.dll")

运行抛出异常,告知无法添加引用

解决方案:

clr的AddReferenceXX系列方法其实就是Assembly.LoadXX系列,可参见链接http://blogs.msdn.com/b/haibo_luo/archive/2007/09/25/5130072.aspx

所以最初的想法是创建一个c#工程然后Assembly.LoadFile之。果不出奇然,抛出异常:

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.

单看错误原因表面上是加载了一个网络路径上的dll,可是我的dll是在本地啊,打开kb看到这么一段话:

If an application has been copied from the web, it is flagged by Windows as being a web application, even if it resides on the local computer. You can change that designation by changing the file properties, or you can use the<loadFromRemoteSources> element to grant the assembly full trust. As an alternative, you can use the UnsafeLoadFrom method to load a local assembly that the operating system has flagged as having been loaded from the web.

so查看WebDriver.dll的文件属性,

在最下方Unlock之,在重新运行c#工程和原python代码,问题解决了!

IronPython fail to add reference to WebDriver.dll的更多相关文章

  1. Failed to add reference to 'System.Net.Http'. Please make sure that it is in the Global Assembly Cache.

    关闭VS再来就好了

  2. Asp.net core 学习笔记 (library)

    refer : https://docs.microsoft.com/en-us/dotnet/core/tutorials/library-with-visual-studio https://do ...

  3. using log4net on my project within a self-hosted WCF application z

    Add reference to log4net.dll to our console service host project (our application entry point) Add t ...

  4. Windows Dll Injection、Process Injection、API Hook、DLL后门/恶意程序入侵技术

    catalogue 1. 引言2. 使用注册表注入DLL3. 使用Windows挂钩来注入DLL4. 使用远程线程来注入DLL5. 使用木马DLL来注入DLL6. 把DLL作为调试器来注入7. 使用c ...

  5. ASP.NET与非托管DLL的那些事儿【转+增】

    https://www.cnblogs.com/yeahgis/archive/2011/11/12/2246341.html ASP.NET与非托管DLL的那些事儿 环境VS2010 语言:ISO ...

  6. .Net中DLL冲突解决(真假美猴王)

    <西游记>中真假美猴王让人着实难以区分,但是我们熟知了其中的细节也不难把他们剥去表象分别出来.对问题不太关心的可以直接调到文中关于.Net文件版本的介绍 问题 最近在编译AKKA.net ...

  7. Embed dll Files Within an exe (C# WinForms)—Winform 集成零散dll进exe的方法

    A while back I was working on a small C# WinForms application in Visual Studio 2008. For the sake of ...

  8. lib和dll的例子

    .dll和.lib的区别 lib是静态库,dll一般是动态链接库(也有可能是别的)比如要编译个exe,lib在编译的时候就会被编译到exe里,作为程序的一部分而dll是不被编译进去,是运行的时候才调入 ...

  9. asp.net中bin目录下的 dll.refresh文件

    首先找到了这篇文章http://www.cnblogs.com/haokaibo/archive/2010/07/31/1789342.html 然后找到一篇英文的文章http://monsur.xa ...

随机推荐

  1. UI层调用WCF服务实例(源码)

    WCF原理性的东西,暂时还没有深入研究,只是在公司的项目中使用到了,会调用,然后再多做了一些了解,现在将它抽出来了一个小实例,写了一个WCF的demo. 我写的这个WCF.Demo主要包括数据契约和服 ...

  2. 文件上传利器SWFUpload使用指南

    这里就不再介绍什么是SWFUpload啦,简单为大家写一个简单关于SWFUpload的Demo. 1.把SWFUpload 相关的文件引用进来 2.创建upload.aspx页面(页面名称可自定义), ...

  3. JSP include HTML出现乱码

    解决方法:在项目的web.xml中加入下面语句:<jsp-config>     <jsp-property-group>     <description>    ...

  4. C# 虚方法 抽象方法 接口

    虚方法:virtu 注意的几点: 1,父类中如果有方法让子类重写,则可以将该方法标记为virtual 2.虚方法在父类中必须有实现,哪怕是空实现 3虚方法子类可以重写,也可以不重写 4.如果类是抽象类 ...

  5. 比较ArrayList和LinkedList

    比较一:添加内容 涉及方法:add public void add_test(){ List<Person> addlist = new ArrayList<Person>() ...

  6. 345. Reverse Vowels of a String(C++)

    345. Reverse Vowels of a String Write a function that takes a string as input and reverse only the v ...

  7. juquery验证插件validation addMethod方法使用笔记

    该方法有三个api接口参数,name,method,messages addMethod(name,method,message)方法 参数 name 是添加的方法的名字. 参数 method 是一个 ...

  8. 自己使用Jquery封装各种功能分享

    自己使用Jquery封装各种功能分享: 左右滚动图片 瀑布流 流动显示列表 广告切换 头像切换And广告切换 获取搜索引擎的来源关键字 上面列表中展示的功能都是使用jquery进行封装实现的,希望大家 ...

  9. Apache 支持.htaccess

    ******************************************************************************* Apache 服务器 ********* ...

  10. Java控制台版推箱子

    import java.util.Scanner; public class b { public static void main(String[] args) { Scanner input = ...