Added more namespaces to _ViewImports.cshtml #19559
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Prerequisites
Description
Maybe I'm doing something wrong, but in new Umbraco projects, I have problems with referencen certain types from Razor views due to implicit usings, but without any errors shown in Visual Studio.
For instance, any type in the
System.IO
namespace will look fine in Visual Studio - e.g. as shown here:But accessing the view will result in a Razor compile error:
Adding a
@using System.IO
will fix the issue, but it's a bit frustrating, as Visual Studio won't show any errors, so I often end up forgetting this until I see the error when running the site.The same happens for the
Microsoft.AspNetCore.Hosting
(I use injectingIWebHostEnvironment
a lot directly in the view when debugging something), which why my PR is for these to namespaces in particular. I can't remember whether I have encountered similar issues for other namespaces, but here are probably some more as well 🤷♂️