-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
UnmanagedCallersOnly functions with bool/char parameters should be an error #64086
Comments
This is a case where the exact behavior of For RyuJIT, this should work with the new DisableRuntimeMarshallingAttribute. |
@tannergooding does |
It is no different from other invalid combinations of types or interop marshalling attributes on e.g. DllImport. They are only caught at runtime. Roslyn does not flag them as errors. It is intentional design.
No. |
'bool' isn't a blittable type, so it can't be used in an [UnmanagedCallersOnly] method. FWIW it's a bug in the C# compiler to not complain about this: dotnet/roslyn#64086. Fixes this crash in the AOT compiler: > * Assertion at /Users/runner/work/1/s/src/mono/mono/mini/aot-compiler.c:5142, condition `is_ok (error)' not met, function:add_wrappers, method CoreMedia.CMBufferQueue:GetDataReady (intptr,intptr) with UnmanagedCallersOnlyAttribute has non-blittable parameters or return type assembly:<unknown assembly> type:<unknown type> member:(null) Also exclude some unused delegates from .NET code.
…5986) 'bool' isn't a blittable type, so it can't be used in an [UnmanagedCallersOnly] method. FWIW it's a bug in the C# compiler to not complain about this: dotnet/roslyn#64086. Fixes this crash in the AOT compiler: > * Assertion at /Users/runner/work/1/s/src/mono/mono/mini/aot-compiler.c:5142, condition `is_ok (error)' not met, function:add_wrappers, method CoreMedia.CMBufferQueue:GetDataReady (intptr,intptr) with UnmanagedCallersOnlyAttribute has non-blittable parameters or return type assembly:<unknown assembly> type:<unknown type> member:(null) Also exclude some unused delegates from .NET code.
Disallowing |
This issue is very similar to #57025, where you said the break was acceptable: #57025 (comment) The only difference I see is that this case is scenario dependent, since the My personal take is that the compiler does not allow any other non-blittable types in the signature of a Another point is that not many people know exactly which types are blittable or not, so this is a very easy mistake to make (I didn't know, and I've written quite a few P/Invokes over the years, and neither did you guys when you implemented support for |
These are very different. The number of methods that have
The compiler does not process this attribute and has no behavior associated with it. Closing this as there does not seem to be concensus from runtime team that this should be an error. Will reconsider if that conseus happens. |
Just noting I think the behavior is fine "as is" today. Users can make it work and it will trivially fail at runtime if the code gets used. The runtime could potentially improve the exception message to call out |
This does make sense. @rolfbjarne Would updating the error message be a reasonable compromise? |
Version Used:
Steps to Reproduce:
See:
Code:
Note:
char
has the exact same problem.Expected Behavior:
A compiler error:
Actual Behavior:
Compilation succeeds, but an exception is thrown at runtime:
This bug is very similar to #57025, where the same problem occurred, except with
ref
parameters instead ofbool
/char
parameters.The text was updated successfully, but these errors were encountered: