CsWinRT icon indicating copy to clipboard operation
CsWinRT copied to clipboard

component authoring fails with unhelpful error if no TargetFrameworkVersion is set

Open stevenbrix opened this issue 1 year ago • 0 comments

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

  1. create .NET8 class library
  2. add package reference to cswinrt
  3. set <CSWinRTComponent>true</CSWinRTComponent> in the csproj
  4. change TargetFramework to net8.0-windows
  5. build

Expected behavior this would provide an error that the project isn't configured correctly

Version Info 2.0.7

stevenbrix avatar Apr 29 '24 15:04 stevenbrix