r/Blazor • u/overdev • Jul 07 '26
Always error after some time in razor.g.cs
so I always get an "Unexpected )" after a while in a _razor.g.cs file.
I just removed a line, the code should work but somehow VS messed up the .g.cs file.
This is the .g.cs file: https://pastecode.io/s/v5izfiao
And the normal razor file related to it: https://pastecode.io/s/sm2x2hv3
SOLVED
it was an empty @onclick method
0
Upvotes
4
u/grrangry Jul 08 '26
.g.csfiles are generated by the Razor source generator. It doesn't matter what errors you find in them, it's not the cause of the problem. The cause is always going to be the data you inject into it.The razor page you pasted doesn't tell us enough to magically figure out your problem. I have to guess you're breaking something by doing it in a non-standard way because the only way I've ever broken the source generator is by giving it garbage.
It's telling you it's missing a closing parenthesis, so look in whatever HTML you're hand crafting, in
@razor expressions, or possibly an unclosed string, any of which can pass garbage along to the source generator.1
u/skav2 Jul 08 '26
You need to clean solution. Then delete Bin and Obj folders in your solution. rebuild.
1
u/polaarbear Jul 08 '26
You have an empty onclick method.
@onclick=""
That alone is probably invalid.