[Python.NET] Errors with Python.Net 2.0 SP 1

Nicolas Lelong nico_ml at mgdesign.fr
Fri Jan 25 09:44:08 CET 2008

After having setup a minimum repro case for a MSDN Forum (http://forums.microsoft.com/Forums/ShowPost.aspx?PostID=2735385&SiteID=1), I came up with a simple workaround that suits me for now...

The problems comes for the AssemblyManager, it seems that on dynamic Assemblies, the AssemblyLoad event is called before the Assembly object is properly set up, and that the GetTypes() call issued in ScanAssembly messes up the internal state of the newly created Assembly....

As, dynamic assemblies are empty when created, there's no point is scanning them - at least, this is the case of assemblies created by Python.Runtime.CodeGenerator and Python.Runtime.NativeCall.

So, checking is an assembly is dynamic before calling ScanAssembly does the trick, see the following patch :

Index: pythonnet/src/runtime/assemblymanager.cs
--- pythonnet/src/runtime/assemblymanager.cs    (révision 90)
+++ pythonnet/src/runtime/assemblymanager.cs    (copie de travail)
@@ -87,7 +87,12 @@
         static void AssemblyLoadHandler(Object ob, AssemblyLoadEventArgs args){
             Assembly assembly = args.LoadedAssembly;
-            ScanAssembly(assembly);
+            // .NET v2.0 SP1 bug workaround ; ScanAssembly called on newly created DynamicAssembly causes problems
+            // only scan non-dynamic assemblies...
+            if ( !(assembly is System.Reflection.Emit.AssemblyBuilder) )
+            {
+                ScanAssembly(assembly);
+            }

It fixes the issue, as I'm quite new to .NET I may miss something obvious...

Any thoughts ?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/pythondotnet/attachments/20080125/3f30ee74/attachment.htm 

More information about the PythonDotNet mailing list