codecentric / net_automatic_interface

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

Random crashes #45

Closed skarllot closed 1 week ago

skarllot commented 4 months ago

The generator is randomly crashing with the error below:

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 'ArgumentException' with message 'The hintName '<redacted>.IFileDiscovery.cs' of the added source file must be unique within a generator. (Parameter 'hintName')'.
System.ArgumentException: The hintName '<redacted>.IFileDiscovery.cs' of the added source file must be unique within a generator. (Parameter 'hintName')
at Microsoft.CodeAnalysis.AdditionalSourcesCollection.Add(String hintName, SourceText source) in Z:\BuildAgent\work\3b7ce003563d6f8f\src\Compilers\Core\Portable\SourceGeneration\AdditionalSourcesCollection.cs:line 78
at AutomaticInterface.AutomaticInterfaceGenerator.GenerateCode(SourceProductionContext context, ImmutableArray`1 enumerations)
at Microsoft.CodeAnalysis.UserFunctionExtensions.c__DisplayClass3_0`2. b__0(TInput1 input1, TInput2 input2, CancellationToken token) in Z:\BuildAgent\work\3b7ce003563d6f8f\src\Compilers\Core\Portable\SourceGeneration\UserFunction.cs:line 101

-----

System.ArgumentException: The hintName '<redacted>.IFileDiscovery.cs' of the added source file must be unique within a generator. (Parameter 'hintName')
at Microsoft.CodeAnalysis.AdditionalSourcesCollection.Add(String hintName, SourceText source) in Z:\BuildAgent\work\3b7ce003563d6f8f\src\Compilers\Core\Portable\SourceGeneration\AdditionalSourcesCollection.cs:line 78
at AutomaticInterface.AutomaticInterfaceGenerator.GenerateCode(SourceProductionContext context, ImmutableArray`1 enumerations)
at Microsoft.CodeAnalysis.UserFunctionExtensions.c__DisplayClass3_0`2. b__0(TInput1 input1, TInput2 input2, CancellationToken token) in Z:\BuildAgent\work\3b7ce003563d6f8f\src\Compilers\Core\Portable\SourceGeneration\UserFunction.cs:line 101
ChristianSauer commented 4 months ago

I've encountered this Problem before. The problem is that the created name must be unique, but the API of an interface Generator does not allow to check for that. To solve this: Can you make sure that only one interface with the name FileDiscovery exists?

skarllot commented 4 months ago

Yes, there's only one

ChristianSauer commented 4 months ago

OK, can you produce a minimal sample?

skarllot commented 1 week ago

I couldn't replay the problem anymore