hadashiA / VContainer

The extra fast, minimum code size, GC-free DI (Dependency Injection) library running on Unity Game Engine.
https://vcontainer.hadashikick.jp
MIT License
1.88k stars 163 forks source link

SourceGenerator Diagnostic -> System.ArgumentException #588

Open kandreyc opened 9 months ago

kandreyc commented 9 months ago

Hi, I'm currently migrating a big project from zenject to vcontainer, and faced issue with your source generator

System.ArgumentException: Reported diagnostic 'VCON00*any' has a source location in file '/Path/To/Script/From/Another/Asmdef.cs', which is not part of the compilation being analyzed. (Parameter 'diagnostic')

So to find the issue I had to rebuild source generator with try/catches and debug error files generation, because some asmdefs generated injectors, some not. As you can see, the problem is when source generator trying to report diagnostic with a location, that not belongs to the compilation generator is working for. (For example a base class, that is located in another csproj)

So it would be great if you will cover this case with diagnostic errors, like its ok to not generate the output in that case for this specific class, but not for a whole asmdef (because of exception being thrown, so generation is terminated), and report such errors to diagnostic, even without location, because it will at least help to find a problem without rebuilding the generator. Thanks!