From 6f16031661db330e02246b9766704abc8c4f34e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20G=2E=20Aragoneses?= Date: Sat, 24 Aug 2013 00:11:05 +0200 Subject: [PATCH] glib: fix NRE regression after interface naming changed ListBase was throwing a NullReferenceException in DataMarshal() due to the fact that Reflection was being used to find the adapter name of the interface generated by the bindings, which has recently changed [1]. [1] https://github.com/mono/gtk-sharp/commit/6cb03440c1a3fb52c23d5d681e44f772d687333c --- glib/ListBase.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/glib/ListBase.cs b/glib/ListBase.cs index 3077b80b9..5f1d63fa0 100644 --- a/glib/ListBase.cs +++ b/glib/ListBase.cs @@ -168,7 +168,7 @@ namespace GLib { else if (element_type.IsValueType) ret = Marshal.PtrToStructure (data, element_type); else if (element_type.IsInterface) { - Type adapter_type = element_type.Assembly.GetType (element_type.FullName + "Adapter"); + Type adapter_type = element_type.Assembly.GetType (InterfaceToAdapterTypeName (element_type)); System.Reflection.MethodInfo method = adapter_type.GetMethod ("GetObject", new Type[] {typeof(IntPtr), typeof(bool)}); ret = method.Invoke (null, new object[] {data, false}); } else @@ -180,6 +180,16 @@ namespace GLib { return ret; } + static string InterfaceToAdapterTypeName (Type type) + { + string fullname = type.Namespace; + if (!String.IsNullOrEmpty (fullname)) { + fullname += "."; + } + fullname += type.Name.Substring (1); // IActivatable -> Activatable + return fullname + "Adapter"; + } + [DllImport ("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)] static extern void g_free (IntPtr item);