LokiMidgard / PartialMixins

Extends C# with Mixins.
MIT License
24 stars 2 forks source link

NullReference in VS2022 (17.1) #11

Closed AliveDevil closed 2 years ago

AliveDevil commented 2 years ago

Getting a Error_mixins.cs for this project^1 with a NullReference.

#error System.NullReferenceException: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
#error    bei PartialMixins.PartialMixin.ExecuteInternal(GeneratorExecutionContext context)
#error    bei PartialMixins.PartialMixin.Execute(GeneratorExecutionContext context)
#error 

dotnet build output:

Microsoft (R)-Build-Engine, Version 17.1.0+ae57d105c für .NET
Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten.

  Wiederherzustellende Projekte werden ermittelt...
  Alle Projekte sind für die Wiederherstellung auf dem neuesten Stand.
workspace\Desktop\partials\PartialMixins\PartialMixins.PartialMixin\Error_mixins.cs(2,8): error CS1029: #error: "System.NullReferenceException: Object reference not set to an instance of an object." [workspace\Desktop\partials\partials.csproj]
workspace\Desktop\partials\PartialMixins\PartialMixins.PartialMixin\Error_mixins.cs(3,11): error CS1029: #error: "at PartialMixins.PartialMixin.ExecuteInternal(GeneratorExecutionContext context)" [workspace\Desktop\partials\partials.csproj]
workspace\Desktop\partials\PartialMixins\PartialMixins.PartialMixin\Error_mixins.cs(4,11): error CS1029: #error: "at PartialMixins.PartialMixin.Execute(GeneratorExecutionContext context)" [workspace\Desktop\partials\partials.csproj]
workspace\Desktop\partials\PartialMixins\PartialMixins.PartialMixin\Error_mixins.cs(5,8): error CS1029: #error: "" [workspace\Desktop\partials\partials.csproj]

Fehler beim Buildvorgang.

workspace\Desktop\partials\PartialMixins\PartialMixins.PartialMixin\Error_mixins.cs(2,8): error CS1029: #error: "System.NullReferenceException: Object reference not set to an instance of an object." [workspace\Desktop\partials\partials.csproj]
workspace\Desktop\partials\PartialMixins\PartialMixins.PartialMixin\Error_mixins.cs(3,11): error CS1029: #error: "at PartialMixins.PartialMixin.ExecuteInternal(GeneratorExecutionContext context)" [workspace\Desktop\partials\partials.csproj]
workspace\Desktop\partials\PartialMixins\PartialMixins.PartialMixin\Error_mixins.cs(4,11): error CS1029: #error: "at PartialMixins.PartialMixin.Execute(GeneratorExecutionContext context)" [workspace\Desktop\partials\partials.csproj]
workspace\Desktop\partials\PartialMixins\PartialMixins.PartialMixin\Error_mixins.cs(5,8): error CS1029: #error: "" [workspace\Desktop\partials\partials.csproj]
    0 Warnung(en)
    4 Fehler

Verstrichene Zeit 00:00:04.29
AliveDevil commented 2 years ago

After further analysis: currentMixinAttribute.ConstructorArguments[0] is of type CodeAnalysis.TypedConstant^1, cast to INamedTypeSymbol is successful. updatedImplementationSymbol is assigned null, due to compilation.GetTypeByMetadataName. ^2 typeParameterMappings is length 0. Assigning null (updatedImplementationSymbol) to implementationSymbol results in NullRef in foreach^3.

AliveDevil commented 2 years ago

Found a clue here: https://github.com/LokiMidgard/PartialMixins/blob/b835668306da09acc0a553a24593241a17e3403c/PartialMixins/PartialMixin.cs#L238-L243 This^1 needs to either call GetFullQualifiedName(implementationSymbol, true) or GetName requires different logic. Currently logic results in creating a type name of name (ns).Fully.Qualified.TypeName, which resolves to something like Some.Namespace.Some.Namespace.Type.

LokiMidgard commented 2 years ago

Thanks fro the analysis, It will propably be some days before I can look at this. But if you want feel free to create a Pull Request.

znakeeye commented 2 years ago

VS 2022 (17.3.1). I got the same error, but the compiler instead complained about #13. Digging around in the generated code, I found this:

Error_mixins.cs

#error System.NullReferenceException: Object reference not set to an instance of an object.
#error    at PartialMixins.PartialMixin.ExecuteInternal(GeneratorExecutionContext context)
#error    at PartialMixins.PartialMixin.Execute(GeneratorExecutionContext context)
#error 

Did you guys find a solution?

AliveDevil commented 2 years ago

No, I stopped trying to get mixin code at all in C#.

LokiMidgard commented 2 years ago

Thank you @AliveDevil for your analysis.
It helped.