CsWinRT
CsWinRT copied to clipboard
component authoring fails with unhelpful error if no TargetFrameworkVersion is set
Since there aren't default templates for creating runtime components, one has to start with a regular class library and start modifying the .csproj from there. if you don't set the TargetFramework correctly to something like net8.0-windows10.0.19041.0 you'll get random errors. instead, the error isn't helpful and if you enable logging, the log file just shows this:
Generating assembly AppService version 1.0.0.0
Found 1 types
defining type: Class AppService.Class1
writing custom mapped interfaces for AppService.Class1
add method from symbol: .ctor
custom mapping System.Object to System.Object from mscorlib
attribute type found
adding attribute type
System.NullReferenceException: Object reference not set to an instance of an object.
at Generator.WinRTTypeWriter.AddType(INamedTypeSymbol type, Boolean treatAsProjectedType)
at Generator.WinRTTypeWriter.AddCustomAttributes(String attributeTypeName, IList`1 primitiveTypes, IList`1 primitiveValues, EntityHandle parentHandle)
at Generator.WinRTTypeWriter.AddActivatableAttribute(EntityHandle parentHandle, UInt32 version, String factoryInterface)
at Generator.WinRTTypeWriter.AddComponentType(INamedTypeSymbol type, Action visitTypeDeclaration)
at Generator.WinRTTypeWriter.VisitClassDeclaration(ClassDeclarationSyntax node)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxWalker.Visit(SyntaxNode node)
at Generator.ComponentGenerator.Generate()
To Reproduce
- create .NET8 class library
- add package reference to cswinrt
- set
<CSWinRTComponent>true</CSWinRTComponent>in the csproj - change
TargetFrameworktonet8.0-windows - build
Expected behavior this would provide an error that the project isn't configured correctly
Version Info 2.0.7