[IronPython] Loading IronPython assemblies dynamatically

Marty Nelson Marty.Nelson at symyx.com
Sat May 17 02:44:29 CEST 2008


Probably has to do with binding context.  This means that assemblies
loaded via LoadFile, LoadFrom and Load don't necessarily "see"
assemblies loaded in other contexts.  See
http://blogs.msdn.com/suzcook/archive/2003/05/29/57143.aspx for more
info.

You also might try just changing to LoadFrom, LoadFile doesn't use
Fusion at all (see
http://blogs.msdn.com/suzcook/archive/2003/09/19/loadfile-vs-loadfrom.as
px).  

We actually include the following code on AssemblyResolve to bridge
contexts:

  foreach (Assembly loadedAssembly in
AppDomain.CurrentDomain.GetAssemblies())
            {
                if (loadedAssembly.FullName == assemblyFullName)
                {
                    return loadedAssembly;
                }
            }


-----Original Message-----
From: users-bounces at lists.ironpython.com
[mailto:users-bounces at lists.ironpython.com] On Behalf Of Ben Hall
Sent: Friday, May 16, 2008 5:28 PM
To: Discussion of IronPython
Subject: [IronPython] Loading IronPython assemblies dynamatically

Hello,

I have an interesting problem and I was wondering if you would be able
to help. I am trying to load the IronPython assemblies dynamically
(IronPython.dll and IronPython.Modules.dll),  and what I am doing is
this:

Assembly.LoadFile(Path.Combine(Settings.BinDirectory, assembly));

I'm then creating the Runtime and the Engine after the assemblies have
loaded.  But when I try runtime.GetEngine I get the following
exception:

  ----> System.IO.FileNotFoundException : Could not load file or
assembly 'IronPython, Version=2.0.0.2000, Culture=neutral,
PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The
system cannot find the file specified.
	at
Microsoft.Scripting.Runtime.ScriptDomainManager.LanguageRegistration.Loa
dLanguageContext(ScriptDomainManager
manager)
	at
Microsoft.Scripting.Runtime.ScriptDomainManager.GetLanguageContext(Type
type)
	at Microsoft.Scripting.Hosting.ScriptRuntime.GetEngine(Type
languageContextType)

Ok, so I hooked up to the Assembly Resolve event, and when I get to
get the engine it fires off.

Assembly name passed into the AssemblyResolve event is:
IronPython, Version=2.0.0.2000, Culture=neutral,
PublicKeyToken=31bf3856ad364e35

However, the assembly I am loading is this:
IronPython, Version=2.0.0.2000, Culture=neutral,
PublicKeyToken=31bf3856ad364e35

Same with Modules:
IronPython.Modules, Version=2.0.0.2000, Culture=neutral,
PublicKeyToken=31bf3856ad364e35

After I reload the assembly (using the same Assembly.Load) everything
works fine!

Why is this? I would prefer not to have to load my assemblies twice.
These the assemblies I downloaded from CodePlex.
Thanks

Ben
_______________________________________________
Users mailing list
Users at lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

=======
Notice: This e-mail message, together with any attachments, contains
information of Symyx Technologies, Inc. or any of its affiliates or
subsidiaries that may be confidential, proprietary, copyrighted,
privileged and/or protected work product, and is meant solely for
the intended recipient. If you are not the intended recipient, and
have received this message in error, please contact the sender
immediately, permanently delete the original and any copies of this
email and any attachments thereto.



More information about the Ironpython-users mailing list