CsWinRT icon indicating copy to clipboard operation
CsWinRT copied to clipboard

Doesn't work with C# nullable types

Open andrewleader opened this issue 2 years ago • 0 comments

Describe the bug When trying to build a C# class library that uses nullable types in methods, like the one seen below, I get an "Incorrect function" error, and trying to use the NuGet library from a C++ app results in class not registered. If I remove the nullable types, it all works correctly. The Windows Community Toolkit Notifications library is littered with nullables 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# nullables like bool? as seen below...

        public ToastContentBuilder AddAudio(bool? silent)
        {
            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? 😊

Version Info

CsWinRT NuGet: 1.3.3 .NET 5

andrewleader avatar Jul 25 '21 20:07 andrewleader