After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 796287 - C# BasicTutorial6 doesn't work in Windows
C# BasicTutorial6 doesn't work in Windows
Status: RESOLVED OBSOLETE
Product: GStreamer
Classification: Platform
Component: gst-sharp
1.14.0
Other Windows
: Normal normal
: git master
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2018-05-20 22:02 UTC by tomislavtustonic
Modified: 2018-11-03 11:09 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Modified version which imports a correct dll and doesn't crash on unknown type. (7.38 KB, text/plain)
2018-05-20 22:02 UTC, tomislavtustonic
  Details
tutorial6: Do not use linux specific .so names for the glib (837 bytes, patch)
2018-05-21 08:35 UTC, Thibault Saunier
committed Details | Review

Description tomislavtustonic 2018-05-20 22:02:30 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
Comment 1 Thibault Saunier 2018-05-21 08:35:22 UTC
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
Comment 2 Thibault Saunier 2018-05-21 08:36:15 UTC
Would that work for you?
Comment 3 tomislavtustonic 2018-05-21 21:25:00 UTC
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
Comment 4 tomislavtustonic 2018-05-21 23:57:38 UTC
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 5 Thibault Saunier 2018-06-05 13:52:36 UTC
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
Comment 6 GStreamer system administrator 2018-11-03 11:09:18 UTC
-- 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.