[Ironpython-users] Importing .NET Lib Error

Jimmy Schementi jschementi at gmail.com
Mon Jul 11 22:34:14 CEST 2011

This particular error is actually informative, and even gives a URL for how to fix it: http://go.microsoft.com/fwlink/?LinkId=155569. But I'll summarize:

You're running the script from a network share (looks like you're using Parallels with shared Mac drives?). Also looks like you're running this code from the Visual Studio repl? To get this to work you need to add the following to the <runtime> section of c:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe.config:

<loadFromRemoteSources enabled="true"/>

Note: You'll have to add this to any .NET app that runs IronPython scripts from E:\ which load assemblies (eg, ipy.exe, yourhost.exe ...). I currently have the same setup with Paralles, and this is what I do. To avoid this, store all your .NET stuff on an drive actually mounted in Windows.

Also, You didn't need to copy your assembly into IronPython's directory. Store your assemblies in your own directory, add that directory to sys.path, sys.path.append("C:\\path\\to\\assemblies"), and then clr.AddReference("LumensWorks.Framework.IO") will load it. Also, loading the assembly first and then adding it as a reference isn't necessary, just extra typing your your part.


On Jul 11, 2011, at 3:48 PM, Slide wrote:
> The next version of IP should have csv module support in it...I know that doesn't help you NOW, but should in the future.If the DLL is in the DLLs directory, you should be able to load by just using the clr.AddReference method I believe.
> Thanks,
> slide
> On Mon, Jul 11, 2011 at 12:16 PM, Chris <phatfish at gmail.com> wrote:
> Hi all,
> Sorry im a .NET newbie so im going to ask here without really trying to fix this myself.
> I want to import a CSV lib, as explained here:
> http://www.ironpython.info/index.php/Reading_CSV_Files
> My code is this, im just testing the import works at the moment:
> import clr
> from System.Reflection import Assembly
> assembly_path = "C:\Program Files (x86)\IronPython 2.7\DLLs\LumenWorks.Framework.IO.dll"
> assembly = Assembly.LoadFile(assembly_path)
> clr.AddReference(assembly)
> I receive this error (im on Win7 with .NET4 installed):
> Running E:\Users\Chris\Documents\Visual Studio 2010\Projects\BACS18 Converter\BACS18 Converter\Program.py
> Traceback (most recent call last):
>   File "c:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\Extensions\Microsoft\Python Tools for Visual Studio\1.0\visualstudio_py_repl.py", line 358, in run_file_as_main
>     exec(code, self.exec_mod.__dict__, self.exec_mod.__dict__)
>   File "E:\Users\Chris\Documents\Visual Studio 2010\Projects\BACS18 Converter\BACS18 Converter\Program.py", line 2, in <module>
>     import SPA
>   File "E:\Users\Chris\Documents\Visual Studio 2010\Projects\BACS18 Converter\BACS18 Converter\SPA.py", line 4, in <module>
>     assembly = Assembly.LoadFile(assembly_path)
> SystemError: 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.
> >>> 
> Two questions:
> Is this the best way to be importing a .NET lib, that tutorial appears to have been written in 2007?
> If it is, how do i fix that error, im not loading from a network location..?
> Many thanks,
> Chris
> _______________________________________________
> Ironpython-users mailing list
> Ironpython-users at python.org
> http://mail.python.org/mailman/listinfo/ironpython-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20110711/d91a537a/attachment.html>

More information about the Ironpython-users mailing list