在使用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. 最小生成树之 prim算法和kruskal算法(以 hdu 1863为例)

    最小生成树的性质 MST性质:设G = (V,E)是连通带权图,U是V的真子集.如果(u,v)∈E,且u∈U,v∈V-U,且在所有这样的边中, (u,v)的权c[u][v]最小,那么一定存在G的一棵最 ...

  2. Jquery插件之信息弹出框showInfoDialog(成功、错误、警告、通知)

    一.信息种类说明: 1.1.操作成功信息 1.2.错误信息 1.3.警告信息 1.4.通知信息 二.使用说明 <!DOCTYPE html PUBLIC "-//W3C//DTD HT ...

  3. (转)Android开发:性能最佳实践-管理应用内存

    翻自:http://developer.android.com/training/articles/memory.html 在任何软件开发环境中,RAM都是宝贵的资源,但在移动操作系统中更加珍贵.尽管 ...

  4. diff函数的实现——LCS的变种问题

    昨天去去哪儿笔试,碰到了一个我们一直很熟悉的命令(diff——ubuntu下面),可以比较字符串,即根据最长公共子串问题,如果A中有B中没有的字符输出形式如下(-ch),如果A中没有,B中有可以输出如 ...

  5. javascript 自定义鼠标右键菜单

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...

  6. canonical 标签介绍

    rel=”canonical” 这个标签已经推出很久了,canonical 是 Google.雅虎.微软等搜索引擎一起推出的一个标签,它的主要作用是用来解决由于网址形式不同内容相同而造成的内容重复问题 ...

  7. PHP 关于 $GLOBALS['HTTP_RAW_POST_DATA']

    PHP 关于 $GLOBALS['HTTP_RAW_POST_DATA'] 最近用微信api写接口时用到了这个,记录,下面转载开始: —————————— 这是手册里写的 总是产生变量包含有原始的 P ...

  8. 设置(TableViewController)通用框架

    本文学习于传播播客.李明杰老师.感谢

  9. JSP基础笔记

    主要内容:1. JSP基础2. Cookie3. HttpSession ================================ JSP基础 1. jsp的作用: * Servlet: &g ...

  10. 程序集“xxx"中的类型"xxx"的方法“XXXX”没有实现

    通过反射调用一个类库时出现这样的报错,检查了一下类中已经实现了此方法,实现的方法如下: public partial class LogList : DockContent, ILogForm { p ...