I've created multiple new BlazorServer projects in vs code using dotnet new blazorserver on multiple pcs and I always get this error.
The type or namespace name 'Shared' does not exist in the namespace 'BlazorServerTutorial' (are you missing an assembly reference?) [BlazorServerTutorial]
Compiles and runs with no problems but its quite annoying to have a constant error showing.
Has anyone else been able to resolve this issue?
Example
The answer is that the namespace is "inferred" (best word I can think of), i.e. there are Razor files in the Shared folder without a @namespace entry. When the Razor compiler builds them into classes the correct namespace information is added. Visual Studio understands this, but Visual Studio Code obviously doesn't.
The simple fix is to add a @namespace xxxxxx.Shared entry to one of the Razor files in Shared. VSC then see's the namespace directly and the error message goes away. It's the same for any directory with Razor files and inferred namespaces.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With