[Ironpython-users] Assembly references: file does not exist?

Dave Peterson dpeterson at broadwaytechnology.com
Wed Jun 29 16:31:56 CEST 2011


Hi Markus,

ILSpy loads my assembly dll just fine.  As does a C# app.   Only ipy.exe complains about an error.

I think the missing file error is bogus and something else is going on.   But I'm not sure what.   Hopefully the below code and output will explain the situation better than English verbiage.  Note that I verify the file actually exists very earlier in the script!

-- Dave


IN test.py:

#!/bin/python

import clr
import os
import sys

FULLPATH = r"D:\path\to\my\Assembley.Net.dll"
if os.path.exists(FULLPATH):
    pathDir = os.path.dirname(FULLPATH)
    pathBase = os.path.basename(FULLPATH)

    # First load all assemblies ours depends on.
    for dep in ["mscorlib", "Microsoft.VisualC", "System", "System.Windows.Forms", "System.Data", ]:
        clr.AddReference(dep)
        print 'After %s: clr.References=%s' % (dep, clr.References)

    # Now try our assembly
    try:
        print 'Trying AddReferenceToFileAndPath(%s)' % FULLPATH
        clr.AddReferenceToFileAndPath(FULLPATH)
        print '\tWORKED! clr.References=%s' % clr.References
    except IOError as e:
        print '\tFAILED!  Exception=%s' % e
    print ''

    try:
        print 'Trying AddReference(%s)' % pathBase
        clr.AddReference(pathBase)
        print '\tWORKED! clr.References=%s' % clr.References
    except IOError as e:
        print '\tFAILED!  Exception=%s' % e
    print ''

    # Now try with the dir to the assembly DLL on sys.path
    sys.path.append(pathDir)
    try:
        print 'Trying AddReferenceToFileAndPath(%s)' % FULLPATH
        clr.AddReferenceToFileAndPath(FULLPATH)
        print '\tWORKED! clr.References=%s' % clr.References
    except IOError as e:
        print '\tFAILED!  Exception=%s' % e
    print ''

    try:
        print 'Trying AddReference(%s)' % pathBase
        clr.AddReference(pathBase)
        print '\tWORKED! clr.References=%s' % clr.References
    except IOError as e:
        print '\tFAILED!  Exception=%s' % e
    print ''

else:
    print '%s does not exist' % FULLPATH


SAMPLE OUTPUT:

D:\src\local>ipy test.py

After mscorlib: clr.References=(<mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089>,
<System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089>,
<IronPython.Wpf, Version=2.7.0.40, Culture=neutral, PublicKeyToken=7f709c5b713576e1>)

After Microsoft.VisualC: clr.References=(<mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089>,
<System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089>,
<IronPython.Wpf, Version=2.7.0.40, Culture=neutral, PublicKeyToken=7f709c5b713576e1>,
<Microsoft.VisualC, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a>)

After System: clr.References=(<mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089>,
<System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089>,
<IronPython.Wpf, Version=2.7.0.40, Culture=neutral, PublicKeyToken=7f709c5b713576e1>,
<Microsoft.VisualC, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a>)

After System.Windows.Forms: clr.References=(<mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
>,
<System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089>,
<IronPython.Wpf, Version=2.7.0.40, Culture=neutral, PublicKeyToken=7f709c5b713576e1>,
<Microsoft.VisualC, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a>,
<System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089>)

After System.Data: clr.References=(<mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089>,
<System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089>,
<IronPython.Wpf, Version=2.7.0.40, Culture=neutral, PublicKeyToken=7f709c5b713576e1>,
<Microsoft.VisualC, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a>,
<System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089>,
<System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089>)

Trying AddReferenceToFileAndPath(D:\path\to\my\Assembley.Net.dll)
        FAILED!  Exception=System.IO.IOException: file does not exist: D:\path\to\my\Assembley.Net.dll
   at IronPython.Runtime.ClrModule.AddReferenceToFileAndPath(CodeContext context, String file)
   at IronPython.Runtime.ClrModule.AddReferenceToFileAndPath(CodeContext context, String[] files)
   at Microsoft.Scripting.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3)
   at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
   at Microsoft.Scripting.Interpreter.DynamicInstruction`4.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)

Trying AddReference(Assembly.Net.dll)
        FAILED!  Exception=System.IO.IOException: Could not add reference to assembly Assembly.Net.dll
   at IronPython.Runtime.ClrModule.AddReference(CodeContext context, String name)
   at IronPython.Runtime.ClrModule.AddReference(CodeContext context, Object reference)
   at IronPython.Runtime.ClrModule.AddReference(CodeContext context, Object[] references)
   at Microsoft.Scripting.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3)
   at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
   at Microsoft.Scripting.Interpreter.DynamicInstruction`4.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)

Trying AddReferenceToFileAndPath(D:\path\to\my\Assembley.Net.dll)
        FAILED!  Exception=System.IO.IOException: file does not exist: D:\path\to\my\Assembley.Net.dll
   at IronPython.Runtime.ClrModule.AddReferenceToFileAndPath(CodeContext context, String file)
   at IronPython.Runtime.ClrModule.AddReferenceToFileAndPath(CodeContext context, String[] files)
   at Microsoft.Scripting.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3)
   at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
   at Microsoft.Scripting.Interpreter.DynamicInstruction`4.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)

Trying AddReference(Assembly.Net.dll)
        FAILED!  Exception=System.IO.IOException: Could not add reference to assembly Assembly.Net.dll
   at IronPython.Runtime.ClrModule.AddReference(CodeContext context, String name)
   at IronPython.Runtime.ClrModule.AddReference(CodeContext context, Object reference)
   at IronPython.Runtime.ClrModule.AddReference(CodeContext context, Object[] references)
   at Microsoft.Scripting.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3)
   at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
   at Microsoft.Scripting.Interpreter.DynamicInstruction`4.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)


D:\src\local>


-- Dave

From: Markus Schaber [mailto:m.schaber at 3s-software.com]
Sent: Wednesday, June 29, 2011 2:30 PM
To: Dave Peterson; ironpython-users at python.org
Subject: AW: [Ironpython-users] Assembly references: file does not exist?

Hi, Dave,

Do you want to say that ILSpy won't load your assembly.dll, or it won't load MSVCR80.dll? The latter one is a native DLL, not an assembly, and thus cannot be loaded by ILSpy.

I re-read the thread, and my current Guess is that the "AddReference" is unable to find your "assembly.dll".

Did you specify the assembly name correctly? (Case? Without the ".dll" suffix?)

Grüße,
Markus
[Context cut to protect the innocent]

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


More information about the Ironpython-users mailing list