You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
LibraryImport with CLong produces SYSLIB1051 and requires disabling runtime marshalling #73975
Creating a LibraryImport P/Invoke function with CLong parameters produces a SYSLIB1051 error saying that runtime marshalling must be disabled in order to use a CLong as a parameter.
Reproduction Steps
I have this C function signature and the corresponding P/Invoke function.
/* * int CFITS_API ffghpr(fitsfile *fptr, int maxdim, int *simple, int *bitpix, int *naxis, * long naxes[], long *pcount, long *gcount, int *extend, int *status); */[LibraryImport(cfitsio,EntryPoint="ffghpr")]internalstaticpartialErrorCodeReadImageHeader(ninthandle,intmaxdim,outintsimple,outImageTypebitpix,outintnaxis,refCLongnaxes,outCLongpcount,outCLonggcount,outintextend,outErrorCodestatus);
And the compiler will produce three errors (one for each CLong) -- error SYSLIB1051: Runtime marshalling must be disabled in this project ...
Expected behavior
CLong should work with LibraryImport without disabling runtime marshalling.
Actual behavior
CLong requires [assembly: DisableRuntimeMarshalling] in order to work.
Regression?
No response
Known Workarounds
Using a traditional DllImport works as expected.
Configuration
Windows 10 1909 x64
.NET SDK:
Version: 7.0.100-preview.7.22377.5
Commit: ba310d9309
Runtime Environment:
OS Name: Windows
OS Version: 10.0.18363
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\7.0.100-preview.7.22377.5\
Host:
Version: 7.0.0-preview.7.22375.6
Architecture: x64
Commit: eecb028078
Other information
It seems special consideration for CLong/UCLong may be required in the source generators for LibraryImport. I think there is precedence for this kind of special treatment seeing as the jit compiler also has special support for CLong/UCLong --
@alexhelms Appreciate this being called out. At this point I think we are unlikely to try and mitigate this for .NET 7, but this is something we should address in .NET 8. Please let us know if this is heavily impacting.
That is unfortunate but I understand, release is getting close! The DllImport workaround allows me to move forward and I don't require AOT support so this is not a blocker. I'm just experimenting with the new NativeLibrary feature.
That is unfortunate but I understand, release is getting close!
Right. Thanks for understanding. We will get this done in .NET 8. Please ping us early next year if you don't see any traction so we can get on this and you can try it out in an early preview.
Activity
AaronRobinsonMSFT commentedon Aug 15, 2022
@alexhelms Appreciate this being called out. At this point I think we are unlikely to try and mitigate this for .NET 7, but this is something we should address in .NET 8. Please let us know if this is heavily impacting.
alexhelms commentedon Aug 15, 2022
That is unfortunate but I understand, release is getting close! The
DllImportworkaround allows me to move forward and I don't require AOT support so this is not a blocker. I'm just experimenting with the newNativeLibraryfeature.AaronRobinsonMSFT commentedon Aug 16, 2022
Right. Thanks for understanding. We will get this done in .NET 8. Please ping us early next year if you don't see any traction so we can get on this and you can try it out in an early preview.
390620652 commentedon Jan 17, 2023