codecentric / net_automatic_interface

.Net Source Generator for Automatic Interfaces
MIT License
62 stars 14 forks source link

Null reference exception with file-scoped namepace #5

Closed G1Vh closed 2 years ago

G1Vh commented 2 years ago

If class with attribute has file-scoped namespace compilation will fail.

CSC: Warning CS8785 : Generator 'AutomaticInterfaceGenerator' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'NullReferenceException' with message 'Object reference not set to an instance of an object.'

How to test:

  1. Open TestNuget project
  2. Change TargetFrameworkto net6.0
  3. Update AutomaticInterface to 1.1.1
  4. Change block-scoped namespace to file-scoped in Test.cs
  5. Compile
ChristianSauer commented 2 years ago

Thanks for the report. For 4: can you paste a minimal code example here?

G1Vh commented 2 years ago

using AutomaticInterfaceAttribute;

namespace TestNuget;

[GenerateAutomaticInterface] public class Test: ITest { public string GetString() { return "works"; } }