[IronPython] clr.AddReference and derivatives

Dino Viehland dinov at microsoft.com
Wed Nov 12 20:06:11 CET 2008

AddReference(str) will first try Assembly.Load and then try Assembly.LoadWithPartialName - this should mean that trying w/ the strong name won't do anything because LoadWithPartialName will do that for you.  This is kind of the one-stop shopping for loading assemblies in the GAC or the app base.  If those don't work it will also ultimately search sys.path when the load fails.

AddReference(asm) will just add the assembly that you've already loaded - this is useful if you can load the assembly using some other mechanism (e.g. Assembly.LoadFrom or loading from byte array or whatever)

AddReferenceToFile(str) will search sys.path for the file and load it from there using Assembly.LoadFile.  This is good to not have the normal Assembly.Load/LoadWithPartialName mechanisms get in the way.

AddReferenceToFileAndPath(str) will take a fully qualified path, append it to sys.path, and then do Assembly.LoadFile with the path.  This is just convenience for quickly adding a fully qualified assembly.

There's also Load* variations which return the assembly object which you can dot through without altering what you can import.

Usually when debugging assembly load failures I use fuslogvw - but I don't know that it works for Silverlight.  I've pinged a CLR loader dev to see if there's an equivalent that's publicly available.  Otherwise you might try attaching windbg to iexplore and stopping on all exceptions.  With .symfix pointing to the public MS servers you *might* see enough useful data when the load fails.

-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Dan Eloff
Sent: Wednesday, November 12, 2008 10:06 AM
To: Discussion of IronPython
Subject: [IronPython] clr.AddReference and derivatives

There's half a dozen add reference methods in the clr module, I'm
guessing they all have their differences, but I'm not really sure why
you would use one over the other. I generally try AddReference first,
if that doesn't work I try it using the strong name, failing that I
fall back to AddReferenceToFile. Could someone please shed some light
on these methods?

I've got a .NET assembly that wroks great with IronPython, but I've
been having difficulty building it for silverlight. Using reflector
I've managed to verify that I'm building it with all the correct
references for silverlight. However, it still won't load. All the add
reference methods fail: IOError: Assembly could not be loaded.
(paraphrasing as this is not a development pc.) I'm guessing that
descriptive error is the fault of the CLR assembly loading code, not
IronPython. If anyone has any idea why this might happen, or something
I could try in pursuit of knowledge of the same, I'd be grateful.

Users mailing list
Users at lists.ironpython.com

More information about the Ironpython-users mailing list