Skip to content
This repository has been archived by the owner on Jul 16, 2023. It is now read-only.

Allow razor templates with the same name in different folders with different namespaces #10

Merged
merged 1 commit into from Mar 8, 2021
Merged

Allow razor templates with the same name in different folders with different namespaces #10

merged 1 commit into from Mar 8, 2021

Conversation

TheJayMann
Copy link
Contributor

The current source generator only uses the generated class name as the hint name when adding the generated source. As the generated class name is simply the filename of the template, if two templates are in different folders with the same name, the generator fails to generate the source code, as they would have the same hint name. By using different namespaces for these templates, and including the namespace as part of the hint name, this gets around the issue by making the hint names unique.

@TheJayMann
Copy link
Contributor Author

It appears that, looking at the history of the CI check, every so often the windows build fails when trying to restore packages, claiming that the packages cannot be found.

@Tyrrrz
Copy link
Owner

Tyrrrz commented Mar 7, 2021

Thanks!

It appears that, looking at the history of the CI check, every so often the windows build fails when trying to restore packages, claiming that the packages cannot be found.

Yeah, there is some global issue with GitHub Actions + .NET on Windows that causes this. Ignore this for now.

@Tyrrrz Tyrrrz added the bug Something isn't working label Mar 7, 2021
@Tyrrrz
Copy link
Owner

Tyrrrz commented Mar 7, 2021

By the way, what kind of error message does it show when you have two generated files with the same hint name? Would we benefit from a more customized error message or is the default one clear enough to the user?

@TheJayMann
Copy link
Contributor Author

I've already packaged this locally and upgraded my project to use this local version, so I don't see the message anymore. However, from memory, I believe it said something along the lines that two source files used the same hint name, that the hint name is supposed to be unique, and, because of that, the source generator will not be used, which may cause further errors as the generated source files aren't being used. This message, as far as I can tell, only appears in the build output, and does not appear in the Error List of Visual Studio.

@TheJayMann
Copy link
Contributor Author

So, I realized that I could easily cause the issue again even with the update I did by simply making the namespaces the same. Also, I was wrong, it is put in the Error List as a warning, which was missed by me, and I previously only saw it in the build output. The error message is fairly generic, so it can be difficult to know what caused the problem unless you know how the source generator works.

Severity Code Description
Warning CS8785 Generator 'TemplateClassGenerator' 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 of the added source file must be unique within a generator.

@Tyrrrz
Copy link
Owner

Tyrrrz commented Mar 8, 2021

I see, that's not very user friendly of them. Thanks!

@Tyrrrz Tyrrrz merged commit 03ebbb6 into Tyrrrz:master Mar 8, 2021
@TheJayMann TheJayMann deleted the PreventTemplateNameClash branch March 8, 2021 20:03
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants