Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not add reference to .NET assembly in IronPython console in m11 #125

Open
ziemiowid opened this issue Sep 2, 2022 · 2 comments
Open
Assignees

Comments

@ziemiowid
Copy link

Hi,
I used to write my small addins to MapGuide Maestro in F#.
In m10 I am able to load compiled assembly within IronPython console with

clr.AddReference("MyPlugin")
import MyNamespace

MyCommand()

But now, in m11, this simple code provokes error:

IronPython 2.7.11 (2.7.11.1000)
[.NETCoreApp,Version=v3.1 on .NET 6.0.7 (64-bit)]
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> import clr
>>> sys.path.append(r"d:\PATH\TO\MyPlugin")
>>> clr.AddReference("MyPlugin")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IOError: System.IO.IOException: Could not add reference to assembly MyPlugin
   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.FuncCallInstruction`6.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 IronPython.Compiler.Ast.CallExpression.Invoke1Instruction.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
   at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
   at IronPython.Compiler.PythonScriptCode.Run(Scope scope)
   at IronPython.Hosting.PythonCommandLine.<>c__DisplayClass27_0.<RunOneInteraction>b__0()

Trying to solve this problem, I found entry in Windows Application Event Log:

Description: A .NET application failed.
Application: Maestro.exe
Path: C:\Program Files\MapGuide Maestro 6.0m11\Maestro.exe
Message: Cannot use file stream for [C:\Program Files\MapGuide Maestro 6.0m11\Maestro.deps.json]: No such file or directory

This suggests that there may be issues with Maestro configuration as self-contained .NET application.

--
Best regards
Rick

@jumpinjackie
Copy link
Owner

Could you post a hypothetical minimal "hello world" F# example that your IronPython snippet would've loaded in the past and how such an example would be built (sorry, I don't use F#) and I'll investigate.

@ziemiowid
Copy link
Author

I think my information about F# was unnecessary. I wanted simply to tell that I use IronPython to load compiled .NET assemblies. You can build any basic, minimal C# example to reproduce this behavior. I reproduced this error with following code:

namespace ClassLibrary1
{
    public class Class1
    {
        public void Start()
        {
            int dummy = 0;
        }
    }
}

It's not problem with code within plugin, but with referencing it from IronPython.

By the way it is possible to load this assembly using clr.LoadAssemblyFromFile:

>>> tp  = clr.LoadAssemblyFromFile("ClassLibrary1.dll")
>>> print tp
ClassLibrary1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
>>> c1 = tp.ClassLibrary1.Class1()
>>> c1.Start()
>>> 

but real code with additional dependencies throws runtime errors.

@jumpinjackie jumpinjackie self-assigned this Sep 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants