-
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
ComInterfaceGenerator generates code with pointer type in generic #82504
Comments
Tagging subscribers to this area: @dotnet/interop-contrib Issue DetailsIn custom collections generated code, the code generated for the following snippet contains Input Code: using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.Marshalling;
[assembly:DisableRuntimeMarshalling]
[global::System.Runtime.InteropServices.Marshalling.GeneratedComInterfaceAttribute]
partial interface INativeAPI : IUnmanagedInterfaceType
{
[return:MarshalUsing(ConstantElementCount=10)]
System.Byte[] Method(
System.Byte[] p,
in System.Byte[] pIn,
int pRefSize,
[MarshalUsing(CountElementName = "pRefSize")] ref System.Byte[] pRef,
[MarshalUsing(CountElementName = "pOutSize")] out System.Byte[] pOut,
out int pOutSize);
}
// Try using the generated native interface
sealed class NativeAPI : IUnmanagedVirtualMethodTableProvider, INativeAPI.Native
{
public VirtualMethodTableInfo GetVirtualMethodTableInfoForKey(System.Type type) => throw null;
}
partial interface INativeAPI
{
static unsafe void* IUnmanagedInterfaceType.VirtualMethodTableManagedImplementation => null;
} Generated Code: // <auto-generated/>
unsafe partial interface INativeAPI
{
internal unsafe partial interface Native
{
[System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute]
internal static ABI_Method(void* __this_native, byte* __p_native, byte** __pIn_native__param, int pRefSize, byte** __pRef_native__param, byte** __pOut_native__param, int* __pOutSize_native__param)
{
...
try
{
...
}
catch (System.Exception __exception)
{
// error CS0306: The type 'byte*' may not be used as a type argument
__retVal_native = System.Runtime.InteropServices.Marshalling.ExceptionDefaultMarshaller<byte*>.ConvertToUnmanaged(__exception);
}
finally
{
// Cleanup - Perform required cleanup.
...
}
return __retVal_native;
}
}
}
|
We created a helper for handling this when we were doing Lines 84 to 93 in 07f5fca
|
It looks like I missed/forgot to use this for the COM exception marshalling logic. Should be pretty easy to fix. |
fixed in #82582 |
Not quite fixed, the value returned by the generic methods needs to be cast as the variable type. byte* __retVal_native;
catch (System.Exception __exception)
{
// Cannot implicity convert nint to byte*
__retVal_native = System.Runtime.InteropServices.Marshalling.ExceptionDefaultMarshaller<System.IntPtr>.ConvertToUnmanaged(__exception);
} |
In custom collections generated code, the code generated for the following snippet contains
byte*
as a generic argument, causing a compiler error.Input Code:
Generated Code:
The text was updated successfully, but these errors were encountered: