Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

View does not refresh after change

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

like image 493
Crossfire Avatar asked Jan 29 '16 13:01

Crossfire


4 Answers

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.

like image 68
dexcell Avatar answered Oct 26 '22 19:10

dexcell


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.

like image 42
iJungleBoy Avatar answered Oct 26 '22 17:10

iJungleBoy


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

like image 42
Nerdroid Avatar answered Oct 26 '22 18:10

Nerdroid


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

like image 37
zanetti Avatar answered Oct 26 '22 19:10

zanetti