Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(non)Blittable data #26381

Closed
DanielSSilva opened this issue Jun 4, 2018 · 6 comments
Closed

(non)Blittable data #26381

DanielSSilva opened this issue Jun 4, 2018 · 6 comments

Comments

@DanielSSilva
Copy link

First of all I'm not quite familiar with marshalling and dealing with unmanaged resources.
I was migrating a project that was compiled and ran with mono and Framework v4.6.1. Basically what I had to do was only change the target framework, yet one thing that made everything stop working was trying to Pin an object into memory with GCHandle.Alloc. That threw an exception stating that
Unhandled Exception: System.ArgumentException: Object contains non-primitive or non-blittable data.

What I find weird is that this allegedly (I take the word of the owner when he says that it runs successfully) this works when running with Mono. is there any difference on how .NET core and Mono treat memory ?

I'll leave the links for the object I'm pining, as well as the line where the exception is thrown.
Line where exception is thrown
Object that I'm trying to pin

I've looked on both mono Blittable types and dotnet blittable Types but I'm not familiar with that
Is this a possible bug, or simply misunderstanding on my part?

@0xd4d
Copy link

0xd4d commented Jun 4, 2018

@DanielSSilva
Copy link
Author

That is indeed similar, but in this case I'm specifying the layout, isn't it correct?

@0xd4d
Copy link

0xd4d commented Jun 4, 2018

It's the array that is an object reference. You could perhaps change it to two fields

public ws2811_channel_t channel_0;
public ws2811_channel_t channel_1;

@jkotas
Copy link
Member

jkotas commented Jun 5, 2018

Mono does not enforce the restrictions on pinned GCHandle objects. It is
a known problem. mono/mono#4533 and linked issues have the details. This code happens to work on Mono because of this bug.

@DanielSSilva
Copy link
Author

@0xd4d changing that to two fields would break on the C code here for example, wouldn't it? Since it's iterating an array

@DanielSSilva
Copy link
Author

Nevermind, after testing I've found out that it works. Thank you very much!

@jkotas jkotas closed this as completed Jun 5, 2018
@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the 3.0 milestone Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants