在使用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. A题笔记(4)

    No. 1384 这题没啥 不过网考成绩出了,发现我的口语分数相较其他人还挺高的~~~哈哈哈 Code::Blocks 有时在程序运行结束后,.exe 并没有结束,因而之后无论怎么调试和修改代码,运行 ...

  2. Fibonacci 数列递归 重复计算

    public class Fibonacci{ public static long F(long n){ System.out.println("call F" + n); ) ...

  3. Cocos2dx开发(4)——Windows环境创建Cocod2dx 3.2第一个项目HelloWorld

    本文内容:cocos2dx+VS2013环境下创建项目,部分代码简析.会的朋友可以略过. 前面简单安装了几个环境,程序完全可以顺利跑起来(其他的cocos-stadio这些需要用到再装) 1.命令行形 ...

  4. 开发错误日志之IllegalArgumentException:MALFORMED

    java.lang.IllegalArgumentException: MALFORMED 上面存在中文问题是因为java.util.zip下的格式转换有问题 ,jdk中的zip存在字符编码的问题. ...

  5. js键盘控制div移动,解决停顿问题

    问题版本代码如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 <html> &l ...

  6. 基于SAE+CodeIgniter3.0+管理端angularjs+前台amazeui的多用户博客系统V1.0--系统设计(一)

    开发环境: 服务器系统:CentOS-6.x web服务器:Apache-2.2.x php版本:PHP-5.3.x 开发工具:sublime text 3 ,谷歌浏览器 数据库查询工具:phpmya ...

  7. Android Vibrator系统分析

    Vibrator系统的层次结构

  8. Android 简单的FC

    直接贴log 01-02 08:17:56.589 I/ActivityManager( 312): Start proc com.android.providers.calendar for con ...

  9. Git中从远程的分支获取最新的版本到本地

    Git中从远程的分支获取最新的版本到本地有这样2个命令: 1. git fetch:相当于是从远程获取最新版本到本地,不会自动merge    git fetch origin mastergit l ...

  10. bcov进行覆盖率统计

    kcov是在bcov基础上进行的,bcov已经很久没有维护了: 首先需要下载依赖库libdwraft,然后在configure时候进行指定: ./configure --with-libdwarf=/ ...