Compilation issue with source generator
Hello there, I am building a mapper source generator to learn Csharp. I am now testing it in a real project.
Unfortunately using it as a dependency seems to trigger the following compilation error:
I have looked up this error code but I am really unsure what could be done to diagnose this.
For reference the source generator repo is here: https://github.com/oknozor/CartographeAutomatique/tree/main
Any advice on how to troubleshot this would be appreciated.
GitHub
GitHub - oknozor/CartographeAutomatique: For now just a C# learning...
For now just a C# learning project. Contribute to oknozor/CartographeAutomatique development by creating an account on GitHub.
18 Replies
Well I think if you had taken time to open the link you would have seen the "proper unit tests"
gave it a try and samples compile and tests pass (beside the Debugger.Launch spam). guessing there is a MapTo/MapFrom in your code that trigger some bug not covered by the unit tests
Maybe unrelated but rider seem unable to resolve namespace correctly in the generated code
Can you make that screenshot bigger so that it doesn't clip the right-hand side (or just post text)?
otherwise, copy and pasting the generated code in the project as non generated code compiles
sorry about the ident, this is generated source
you can shorten the enum handling a bit to
$"Enum.Parse<{target.FullyQualifiedName()}>({sourceIdentifier})"
sure but I am not sure that will solve my issue 😦
most likely not, but will make the generated code prettier
but you have a test case in BusinessFileImport.Infrastructure.Persistence that you can try to run using the testing code and see what it complains about
that's the whole point, compilation fail and I get the following error
`
I don't have any other relevant logs.
I will try to make a smaller reproducer in a dedicated project
try with
dotnet build /bl
and look in the binary logs, maybe the error output is supressed by msbuild
can view logs with https://msbuildlog.com/Not sure where to look, but it does not seem I have additional error here.
didn't seem to provide more detail. could try running the full command manually and see if csc just crashes or output anything else
Ok I have finally managed to make it compile, I. missed an error in the generated source (calling an undeclared method).
However any error in the generated source, would still generate this
csc.dll
error code and silence the compiler errors. This would be really frustrating for end users. I am a bit puzzled because those compiler errors are correctly emitted in my test project.
Also I was relying on those to guide the user to write correct mappings attributes, instead of doing a lot of code analysis to produce the correct compiler diagnostics.
the bug seems to be somehow related to https://github.com/dotnet/roslyn/issues/24736
But this is supposed to be closed.So I'm not able to reproduce that failure method. I cloned your repo and checked out
4a3caf1
, and then modified your generator to introduce errors
And I see plenty of errors in the console when I run dotnet build
I will say your generator needs some work. Do not store symbols in your generator models; please give $ig a readIf you want to make an incremental source generator, please make sure to read through both the design document and the cookbook before starting.
guess what, I did
You did give the design doc a read? Then great, you'll know that you can't store symbols in your generator models, and you'll know why 🙂