[Ironpython-users] Importing .NET Lib Error

Chris phatfish at gmail.com
Tue Jul 12 00:55:13 CEST 2011


Hi, thanks for the replies.

Im not doing anything funky like running Parallels, this is a standard Win7
install, and im not loading from a network share. I added the
"<loadFromRemoteSources enabled="true"/>" as you suggested from that link
Jimmy, restarted VS, but it had no effect, same error. Im executing the
script using "Execute In Python Interactive" with the Python Tools VS addon.

Loading the assembly with this code (im happy to leave it in the IronPython
Dlls directory for the moment, so i guess that is already on the search
path):

import clr
clr.AddReference("LumensWorks.Framework.IO")

Gets this error:

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 8, in <module>
    clr.AddReference("LumensWorks.Framework.IO")
IOError: System.IO.IOException: Could not add reference to assembly
LumensWorks.Framework.IO
   at IronPython.Runtime.ClrModule.AddReference(CodeContext context, String
name)
...
(long list of at locations)

Which look like plain "i cant find the file" error. Explicitly setting a
sys.path location gets the same error.

I did notice csv was coming in 2.7.1 Slide, but that doesn't help now as you
said.

Thanks,
Chris

On 11 July 2011 21:34, Jimmy Schementi <jschementi at gmail.com> wrote:

> 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.
>
> ~Jimmy
>
> 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/669d53a8/attachment.html>


More information about the Ironpython-users mailing list