IronPython fail to add reference to WebDriver.dll

在使用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的文件属性,

image

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

posted @ 2013-12-10 18:29  Dance With Automation  Views(524)  Comments(0Edit  收藏  举报