Skip to content

Added more namespaces to _ViewImports.cshtml #19559

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

abjerner
Copy link
Contributor

Prerequisites

  • I have added steps to test this contribution in the description below

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:

image

But accessing the view will result in a Razor compile error:

image

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 injecting IWebHostEnvironment 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 🤷‍♂️

Copy link

github-actions bot commented Jun 15, 2025

Hi there @abjerner, thank you for this contribution! 👍

While we wait for one of the Core Collaborators team to have a look at your work, we wanted to let you know about that we have a checklist for some of the things we will consider during review:

  • It's clear what problem this is solving, there's a connected issue or a description of what the changes do and how to test them
  • The automated tests all pass (see "Checks" tab on this PR)
  • The level of security for this contribution is the same or improved
  • The level of performance for this contribution is the same or improved
  • Avoids creating breaking changes; note that behavioral changes might also be perceived as breaking
  • If this is a new feature, Umbraco HQ provided guidance on the implementation beforehand
  • 💡 The contribution looks original and the contributor is presumably allowed to share it

Don't worry if you got something wrong. We like to think of a pull request as the start of a conversation, we're happy to provide guidance on improving your contribution.

If you realize that you might want to make some changes then you can do that by adding new commits to the branch you created for this work and pushing new commits. They should then automatically show up as updates to this pull request.

Thanks, from your friendly Umbraco GitHub bot 🤖 🙂

@emmagarland
Copy link
Contributor

Hi @abjerner,

Thanks for your PR to fix the missing namespace issue you're getting!

I'm just asking if anyone else in HQ gets this issue, I can't find it in the issues list.

After that, we will review and merge (I expect if it seems that others are getting this issue).

Best wishes

Emma

@emmagarland
Copy link
Contributor

Hi @abjerner

Really appreciate the effort for adding this one. However, after discussing it internally with HQ - whilst it is replicable (and slightly odd), it would be preferred not to add these namespaces as default to views. One reason being, for example, System.IO might be better in a service than a view. Also, by adding these we might end up hiding the behaviour and never working out why it is happening.

I'll be closing this particular PR, but hopefully, we can find a way to find out why these errors happen. Perhaps you would like to track it as a new issue (if not already) so others can find it and add to it with ideas of why its happening?

Thanks again,

Emma

@emmagarland
Copy link
Contributor

Closing as above

@emmagarland emmagarland closed this Jul 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants