GNOME Bugzilla – Bug 796287
C# BasicTutorial6 doesn't work in Windows
Last modified: 2018-11-03 11:09:18 UTC
Created attachment 372254 [details] Modified version which imports a correct dll and doesn't crash on unknown type. Hello BasicTutorial6.cs doesn't work in Windows. It imports g_quark_to_string from the Linux library and throws when printing field information, because GstBitmask type is unknown. Here's modified version. I have no idea how to make different DllImports for different platforms. I have also wrapped the calls in the PrintField function, so that it shows an error message instead of crashing. Hope it helps, Tom
Created attachment 372275 [details] [review] tutorial6: Do not use linux specific .so names for the glib And let the glib-2.0.dll.config do its job
Would that work for you?
Well, the attached code works for me :) You mean config like this: http://www.mono-project.com/docs/advanced/pinvoke/dllmap/ It doesn't work in .Net, only in Mono. But I guess it should be fine. In this case, the code should DllImport Windows dll names, and use config file to remap. For the sake of tutorial, it'd probably be enough to just put a commented line or preprocessor directive for Windows or Linux. However, the second problem (missing GstBitmask type) is more serious because it crashes on Windows, so the try-catch is much better solution. I think it would be nice to have a set of tutorials which work on Windows. Cheers, Tom
Hello I looked a bit more into this, and the problem seems to be in glib-sharp. The code throws in the method ToRegisteredType, in the line 315 (https://github.com/GtkSharp/GtkSharp/blob/develop/Source/Libs/GLibSharp/Value.cs#L315) There, it's looking for a constructor with a GLib.Value parameter, but Bitmask doesn't have such constructor, so it throws. It has a constructor which accepts IntPtr. As a proof of concept, I tried with reflection and managed to create a valid object of type Bitmask. Here's some code, in case you want to play with it: var typeField = typeof(GLib.Value).GetField("type", BindingFlags.NonPublic| BindingFlags.Instance); var typeFieldValue = (IntPtr)typeField.GetValue(value); var lookupType = GLib.GType.LookupType(typeFieldValue); // ToRegisteredType is looking for this constructor. var ciInvalid = lookupType.GetConstructor(new[] { typeof(GLib.Value) }); // this one exists var ciOk = lookupType.GetConstructor(new[] { typeof(IntPtr) }); var valuePtr = GLib.Marshaller.StructureToPtrAlloc(value); Bitmask bitMask = (Bitmask)ciOk.Invoke(new object[] { valuePtr }); Tom
Comment on attachment 372275 [details] [review] tutorial6: Do not use linux specific .so names for the glib Attachment 372275 [details] pushed as a4223fc - tutorial6: Do not use linux specific .so names for the glib
-- GitLab Migration Automatic Message -- This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/gstreamer/gstreamer-sharp/issues/6.