-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Analyzer for System.Runtime.CompilerServices.DisableRuntimeMarshallingAttribute
#63714
Comments
Just calling out that this is an "interesting" one where the "alternatives" are also not great. Because the JIT requires This means the next "best" thing is It would be nice if one of these generated "optimal" codegen (noting that the "standard" pattern is actually generating optimal codegen, it generates a constants, but also emits a |
What about some of the other We have things like There are things like
We have things like
Various COM functions are potentially better handled by the new low level CCW/RRW support, if that's something you're using etc |
I would rather add different analyzers for those cases. This issue is specifically for catching cases where behavior the user expects will work normally doesn't work when |
Category: Interoperability Severity:
|
In #60639, we approved the
System.Runtime.CompilerSevices.DisableRuntimeMarshallingAttribute
API. This API is primarily intended to help enable using source-generated interop and to help simplify some concepts in the interop space by disabling some features of the built-in interop system.This proposal proposes an analyzer to identify when users are using features of the built-in interop system when runtime marshalling is disabled with
[assembly:DisableRuntimeMarshalling]
. This analyzer will emit a warning diagnostic in the following scenarios (all of which fail at runtime when the P/Invoke or delegate would be called in an interop scenario):SetLastError
is set totrue
on a P/Invoke[LCIDConversionAttribute]
is used on a P/Invoke[UnmanagedFunctionPointer]
attribute.[StructLayout(LayoutKind.Auto)]
that is in a P/Invoke signature or the signature of a delegate with the[UnmanagedFunctionPointer]
attribute.The analyzer can also emit a "notice"-level diagnostic for the following scenarios that are likely user errors when
[assembly:DisableRuntimeMarshalling]
is applied. These scenarios use APIs that do not change behavior when[assembly:DisableRuntimeMarshalling]
is applied and always respect the built-in marshalling system. I suggest a "notice" level diagnostic as it's possible that the user is calling APIs defined in other assemblies that don't have[assembly:DisableRuntimeMarshalling]
applied or that the results of the APIs are correct even when marshalling is disabled.Marshal.SizeOf
is used on an unmanaged type. (We could also include a code-fix here to recommend switching toUnsafe.SizeOf
or thesizeof
keyword)Marshal.OffsetOf
is used.Marshal.StructureToPtr
orMarshal.PtrToStructure
is used. (We can include code-fixes here to use "unsafe" code or other unsafe APIs).cc: @dotnet/interop-contrib
The text was updated successfully, but these errors were encountered: