-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
[MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1, ArraySubType = UnmanagedType.LPUTF8Str)] results in "Cannot marshal 'parameter #3': Unknown error." #7315
Comments
I observe the same MarshalDirectiveException (message
The marshalling and call above work on Windows (1.0.3 and 1.1.0 tested): I also looked at the tests/src/Interop/StringMarshalling and do not see any ANSI tests, so I am wondering if this is a missing feature as well, and curious to know why it works on Windows but not Linux? |
@ChrisBirkett This is a different issue. We support "ANSI" marshaling in linux - in that context it simply means UTF-8 marshaling ("ANSI" is such an overloaded term...). We don't support BSTR/AnsiBSTR in linux, though. They are very Windows/COM specific (especially AnsiBSTR which is a VB6 thing). Would it make sense for you to simply switch to |
@yizhang82 So hopefully UnmanagedType.LPStr is UTF-8 on both Linux and Windows, can you clarify please? |
@ro-jo LPStr is UTF-8 in linux but in windows it still needs to be "ANSI" (a misnomer). Changing it to UTF-8 in Windows is a breaking change for everybody else. You probably should use LPUTF8Str. |
@GrabYourPitchforks How passionate are you about this support? I am just trying to understand if this is something we will ever update the built-in system to support or if we should defer to whatever happens with source generated P/Invokes. |
Details on what needs to happen in order to support this. The crux of the issue is we rely on OLE The starting point for this logic would be below. Notice the switch statement doesn't handle runtime/src/coreclr/src/vm/mlinfo.cpp Lines 5147 to 5189 in 103fa2c
|
Since the code-generators do not currently work on custom native code, I do expect a fix on this.
Therefore I feel scared when @yizhang82 says:
Since .NET is now a first-class x-platform thing, I do expect the same behavior on every platform. |
@raffaeler I agree it is the "simplest" but that is relative. Plumbing this support through the various layers with confidence of not impacting any other behavior is non-trivial and a serious concern for us. Examples of where we've tried to enable new functionality or enrich code is #48193 and the sequence #50137, #50655, and #50735. This isn't to say we won't consider this but our strong desire is to focus on source generators which provide better performance and stability overall. Given the relative low interest on this issue since it was opened in 2017 it is unlikely it will be addressed in the built-in system. Manually marshalling arrays is always an option albeit less than ideal for most people. If this becomes an acute problem for the community it is absolutely something we will consider though. However, even if it were fixed it is unlikely we would backport this to previous runtimes so at this point focusing our effort on source generators seems to be the path forward here. |
@AaronRobinsonMSFT I understand the difficulties but the source generators solve just one of the many use-cases. I currently had to start a project interoperating with Rust, and I am studying the language from scratch. There are tons of python libraries and mountains of bad interop code that crashes. And I can continue a long list of cases where there is no Win32 or WinRT as possible solutions. For sure, if you asked me the same question 15 years ago, I would have answered that it could be sufficient for the eternity, but the reality (and companies) hugely changed :) This is the reason why I asked you (maybe you remember) a cross-platform ABI. WinRT would be perfect, but it has been restricted to Windows, and doesn't fit the current needs for many projects. |
@raffaeler That was not stated nor was it intended to be implied in my statement above. Source generators are a platform agnostic Roslyn extension that can be used on all platforms. The Interop team is prototyping such a generator in runtimelab. The prototype works on all .NET Core platforms (i.e., Windows, macOS, Linux) which can be observed from the CI definitions in the repo.
Yes, I do recall talking together at the MVP summit. At present, the WinRT ABI is still relegated to Windows and supported in .NET 5+ through the C#/WinRT tooling. The C#/WinRT tool is built upon the .NET 5 This means that the To further reinforce this statement see the following issues that should demonstrate our intense focus on the cross-platform scenario support:
|
Great. I will take a look to the lab. I hope there is some language-neutral way to instruct the code generator, so that I can create the interop layer to any language just "suggesting" the call with a high-level metadata.
I remember you telling me about the ComWrappers. I stay tuned and hope to see it in action soon. Thanks for the other links, I am going to read them :) |
Now that the LibraryImport generator (i.e., source generated |
I am trying out the UTF8 pinvoke marshalling. I have the following that works as expected:
However, this one does not...
It throws a MarshalDirectiveException with the message
"Cannot marshal 'parameter dotnet/coreclr#3': Unknown error."
I see that in tests/src/Interop/StringMarshalling/UTF8/UTF8Test.cs, there is not a test for such a case, so I am guessing that perhaps it was overlooked and has not been implemented yet. (Or, if there is a mistake on my part, the error message could be improved.)
The text was updated successfully, but these errors were encountered: