C
C#6d ago
Pheonick

IIncrementalGenerator and "Inheritance margin" feature hitting removed files

I've been trying to understand for a few days now if I'm doing something wrong. If I create source files based on an Attribute attached to a class and then remove the Attribute from it, the cache is not cleared out of the source file. This causes an exception in the "Inheritance margin" feature in VS: StreamJsonRpc.RemoteInvocationException: The solution does not contain the specified document. Here's a git repo where this can be easily reproduced: https://github.com/pheonick/GeneratorProject If we take the UserProject/UserClass.cs, build the project and then remove all of the [Test(...)] Attributes from the class, we'll get the exception described above. Can anyone help me understand this, please?
GitHub
GitHub - pheonick/GeneratorProject
Contribute to pheonick/GeneratorProject development by creating an account on GitHub.
1 Reply
Cali_West
Cali_West4d ago
I recently ventured into creating a source generator. Followed the same series of articles that it looks like you did. I kind of got it working. It worked when using the snapshot tester Verify. It did not work when I packaged it into a nupkg file and installed it as a package reference in a completely separate solution. It correctly installed, it saw all the namespaces in the package, but it had no idea what my attribute was. Somehow that didn't work. So I guess what I'm doing is trying to raise your issue back up to the top by commenting on it, so that maybe someone who does know what's wrong with your generator will see it and post. One thought though: isn't the generated class supposed to be partial? I can't remember

Did you find this page helpful?