CsWinRT
CsWinRT copied to clipboard
Doesn't work with C# System.Uri
Describe the bug
When trying to build a C# class library that uses System.Uri
in methods, like the one seen below, I get an "Incorrect function" error. And then trying to consume the library from a C++ app fails at runtime with a class not registered exception. If I omit using System.Uri
, it works fine. The Windows Community Toolkit Notifications library is littered with System.Uri and this blocks attempting to make a CsWinRT version of the library for C++ apps.
To Reproduce
Have a C# class library that uses CsWinRT and has a public method that uses C# System.Uri
as seen below...
public ToastContentBuilder AddAudio(System.Uri uri)
{
return this;
}
Build the project. Notice a warning appears while building...
1>CSC : warning CS8785: Generator 'SourceGenerator' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'Win32Exception' with message 'Incorrect function'
Attempt to consume the library (as a NuGet in my case) from a C++ app. Notice you get a class not registered exception when trying to access anything from the library in that class.
Expected behavior
It should work? 😊 If you change System.Uri
to string
, it builds without a warning and is consumable.
Version Info
CsWinRT NuGet: 1.3.3 .NET 5
@andrewleader Is this a C#/WinRT component? As in, <CsWinRTComponent>true</CsWinRTComponent>
in the project file?
@j0shuams correct, <CsWinRTComponent>true</CsWinRTComponent>
in the C# class library that's exposing a method that uses System.Uri.
It seems that setting <CsWinRTWindowsMetadata>10.0.19041.0</CsWinRTWindowsMetadata>
might be a workaround for this, but not sure why yet.