View does not refresh after change

21,902

Solution 1

I had this problem before. My case was i run windows 10 VM Parallel on Macbook Pro, and the project files are in shared folder with mac OS.

Incase someone has the same case like me, move the project to non shared directory such as C:\ will fix the problem.

Solution 2

Here's what seems to be happening under the hood: the .net framework compiles your razor into a machine-form (DLL) and executes this. It then monitors your web folder to watch for changes, and when it detects changes, it re-compiles your razor and executes the new DLL.

In your case something seems to fail related to the monitoring file-changes. It still works on a full restart, because then compiling happens even without file-change detection. Common reasons are:

  1. You're serving the files from the network (a NAS or file-share) which doesn't allow your pc to monitor changes. This can be a missing feature (like a non SMB file-share) or a permission issue. This is very common in web-farm scenarios, but probably not your dev-scenario.
  2. Something else is already locking the files (permissions?) which prevents this monitoring hook to hold on to the files.

To confirm that this is the issue, I recommend just editing the web.config (add/remove a character) and see if then the reload is successful - just to prove it's a re-compile issue and not a visual-studio-debugging issue. Assuming this is the case, and assuming it's not a NAS, I would recommend to temporarily give the folder a "everyone - everything" permission to see if it works then, and then gradually reduce the permissions again to where you want them.

Solution 3

check your web.config and make sure you do not have fcnMode="Disabled" or fcnMode="NotSet"

use

<httpRuntime targetFramework="4.5.2" fcnMode="Default" />

or

<httpRuntime targetFramework="4.5.2" fcnMode="Single" />
  • Default For each subdirectory, the application creates an object that monitors the subdirectory. This is the default behavior.
  • Disabled File change notification is disabled.
  • NotSet File change notification is not set, so the application creates an object that monitors each subdirectory. This is the default behavior.
  • Single The application creates one object to monitor the main directory and uses this object to monitor each subdirectory.

FcnMode Enumeration

Solution 4

On Parallel virtual machines, on the Macbook Pro, if the project files are in shared folders, the recompilation mechanism will not work; Copy the folder to drive C and the problem will be solved

Solution 5

If you're running on Mac using a Parallels WM and you project is located on you Mac-volume, you can solve this with using chmod.

chmod -R 777 *
Share:
21,902
Crossfire
Author by

Crossfire

Updated on July 09, 2022

Comments

  • Crossfire
    Crossfire almost 2 years

    I am having this frustrating problem. I change text in a razor view (cshtml), Start without Debugging, refresh (Ctrl+F5) the browser but nothing happens. The strange part is that if I modify a controller's return value (say return Ok("test");) or an included static file (like CSS), refresh, the change is visible. The razor view only updates if I stop start and stop debugging every time.

    Here are things I have already tried:

    • Made sure that Detect when file is changed outside the environment is checked.
    • On run, when projects are out of date is Always build.
    • Tried this on Edge, Chrome and Firefox with and without hard refreshing.
    • Restarting Visual Studio numeral times.
    • Cleaning/rebuilding solution.
    • Doing this on new template projects.

    P.S. I see there are many similar questions, none of the answers, however, seem to fix my problem.

    Update

    This appears to be a problem on a much larger scale. If I:

    1. Create a required razor section in the parent view like this @RenderSection("css", required: true).
    2. Not implement the rendering in the child view.
    3. I (obviously) get the InvalidOperationException: The following sections have been defined but have not been rendered by the page at 'bla\bla\bla':css.
    4. Then I implement it.
    5. Save, Ctrl+F5 in Firefox. The error persists.

    At this point, VS 2015 is practically unusable because you don't know, if you're actually missing something or it's VS acting out

  • Sir CodesALot
    Sir CodesALot over 7 years
    Thanks for posting that - I can have my sanity back now!!! I ran into this issue with one of my MVC sites and it was driving me NUTS!! I noticed the fcnMode attribute. After some searching on DDG I came across your reply. I'm running Win10 in a Parallels Desktop VM using shared folders. The project I was running is located on a UNC path eg \\Mac\{DriveName}\... For anyone else running a similar environment - I had to change this to "Default" for it to work properly - even then I have to save the view a few times.
  • Mark S
    Mark S over 7 years
    im sorry but where do I put this code in web.config?? <httpRuntime targetFramework="4.5.2" fcnMode="Single"/>
  • Nerdroid
    Nerdroid over 7 years
    put it inside <system.web> </system.web>
  • robbpriestley
    robbpriestley over 6 years
    I too run Win10 in Parallels, but this didn't fix the problem for me. @dexcell provided an answer above that did, however.
  • robbpriestley
    robbpriestley over 6 years
    Running Win10 in Parallels on MacBook Pro. This fixed the problem for me.
  • Janus Kamp Hansen
    Janus Kamp Hansen over 6 years
    My finding is that if you open a terminal-window, and change to the project directory and the use chmod to change rights, it will work. use: sudo chmod -R 777 *
  • jpro
    jpro almost 6 years
    WARNING: trying this solution caused huge problems with git showing changes to every file. DO NOT TRY THIS IT IS A TERRIBLE SOLUTION.
  • smurf
    smurf almost 6 years
    I am on Win10 Parallels on Mac and my project is in C:\ and I disabled sharing of projects between Mac and Windows, but it's still not working for me.
  • dexcell
    dexcell almost 6 years
    @smurf still working with me today, i'm still using mac for .net project with parallels
  • Rob
    Rob almost 6 years
    This was my issue, I chose to move the folder into the logical Parallels VM drive rather than change permissions - certainly fixed it and I would not have worked it out without this answer
  • binki
    binki over 5 years
    Why do you say that NotSet and Default are both the default behavior? If I don’t have the attribute set at all, does that mean it shouldn’t work for me? But it did when I never had this attribute in my web.config before…
  • Nerdroid
    Nerdroid over 5 years
    @binki that was copied from Microsoft docs docs.microsoft.com/en-us/dotnet/api/…
  • binki
    binki over 5 years
    @Moes Please use a quote block to make it clearer that you’re copying from the docs verbatim: stackoverflow.com/help/referencing
  • binki
    binki over 5 years
    Also, it appears that Default is the actual default. So there’s no point in ever saying fcnMode="Default" unless you have a complex configuration with inherited values where an inherited configuration specified something other than fcnMode="Default".
  • Janus Kamp Hansen
    Janus Kamp Hansen about 5 years
    @jpro Not, if you're using git in Windows.. works fine for me.
  • seebiscuit
    seebiscuit over 4 years
    @Ashu, this answer is for .net Core (2.2+). Not sure if that still merits a downvote, since the OP's question was pretty broad (even the tags are somewhat ambiguous wrt to .net Core (Core can be implemented with the C# lang and has an MVC package)).
  • VT Chiew
    VT Chiew over 4 years
    this answer worked for me on asp.net core 2.2 and 3.1 for razor pages (the other solution is for MVC site and Mac running Parallel).
  • Ashu
    Ashu over 4 years
    I got it. actually i was on the latest version and not able to find that function but after research realized that it exits in other versions. tried to up vote it again but getting error that answer must be edited once now.
  • VT Chiew
    VT Chiew over 4 years
    For Razor Pages, the method described at docs.microsoft.com/en-us/aspnet/core/mvc/views/… works better
  • Grumme
    Grumme about 3 years
    I spent quite some time to figure this out... Thanks!