Hi,

I hit a bug while using Python.NET in presence of generics in the root namespace (See attached C# file). I here attach a patch that solved the issue in my case.

Bests,
   Pierre-Yves.
diff -rNu pythonnet-code.orig/pythonnet/src/runtime/genericutil.cs pythonnet-code/pythonnet/src/runtime/genericutil.cs
--- pythonnet-code.orig/pythonnet/src/runtime/genericutil.cs	2013-01-30 09:53:41.048267309 +0100
+++ pythonnet-code/pythonnet/src/runtime/genericutil.cs	2013-01-30 09:54:02.401585290 +0100
@@ -37,11 +37,13 @@
         //====================================================================
 
         internal static void Register(Type t) {
-            Dictionary<string, List<string>> nsmap = null;
-            mapping.TryGetValue(t.Namespace, out nsmap);
+            Dictionary<string, List<string>> nsmap = null;
+            String nm = t.Namespace == null ? "" : t.Namespace;
+
+            mapping.TryGetValue(nm, out nsmap);
             if (nsmap == null) {
                 nsmap = new Dictionary<string, List<string>>();
-                mapping[t.Namespace] = nsmap;
+                mapping[nm] = nsmap;
             }
             string basename = t.Name;
             int tick = basename.IndexOf("`");
@@ -62,7 +64,8 @@
         //====================================================================
 
         public static List<string> GetGenericBaseNames(string ns) {
-            Dictionary<string, List<string>> nsmap = null;
+            Dictionary<string, List<string>> nsmap = null;
+            if (ns == null) { ns = ""; }
             mapping.TryGetValue(ns, out nsmap);
             if (nsmap == null) {
                 return null;
@@ -79,8 +82,9 @@
         //====================================================================
 
         public static List<Type> GenericsForType(Type t) {
-            Dictionary<string, List<string>> nsmap = null;
-            mapping.TryGetValue(t.Namespace, out nsmap);
+            Dictionary<string, List<string>> nsmap = null;
+            String ns = t.Namespace == null ? "" : t.Namespace;
+            mapping.TryGetValue(ns, out nsmap);
             if (nsmap == null) {
                 return null;
             }
@@ -114,7 +118,8 @@
         //====================================================================
 
         public static string GenericNameForBaseName(string ns, string name) {
-            Dictionary<string, List<string>> nsmap = null;
+            Dictionary<string, List<string>> nsmap = null;
+            if (ns == null) { ns = ""; }
             mapping.TryGetValue(ns, out nsmap);
             if (nsmap == null) {
                 return null;
/*
System.ArgumentNullException: Value cannot be null.
Parameter name: key
   at System.Collections.Generic.Dictionary`2.FindEntry(TKey key)
   at System.Collections.Generic.Dictionary`2.TryGetValue(TKey key, TValue& value)
   at Python.Runtime.GenericUtil.Register(Type t)
   at Python.Runtime.AssemblyManager.ScanAssembly(Assembly assembly)
   at Python.Runtime.AssemblyManager.Initialize()
   at Python.Runtime.Runtime.Initialize()
   at Python.Runtime.PythonEngine.Initialize()
   at Bug1.Program.Main(String[] args) in Z:\PythonNet\Bug1\Bug1\Program.cs:line 13
*/

using System;

class S<T>
{
}

namespace Bug1
{
    class Program
    {
        static void Main(string[] args)
        {
            Python.Runtime.PythonEngine.Initialize();
        }
    }
}
_________________________________________________
Python.NET mailing list - PythonDotNet@python.org
http://mail.python.org/mailman/listinfo/pythondotnet

Reply via email to