Error List Navigation to RazorGenerator Views

Sep 4, 2012 at 3:09 PM

Maybe I am missing something obvious, but I cannot seem to navigate to RazorGenerator views from the Error List on build. When you double click on a compile error list item it always throws a dialog "The operation could not be completed. The system cannot find the path specified."

Example Error List entry:

Error 19 The name 'Json' does not exist in the current context c:\DLP\DE\Ed-Fi-Dashboards\Application\EdFi.Dashboards.Presentation.Web\Areas\School\areas\school\views\teachers\Get.cshtml 25 54 EdFi.Dashboards.Presentation.Web

Actual file path is: C:\DLP\DE\Ed-Fi-Dashboards\Application\EdFi.Dashboards.Presentation.Web\Areas\School\Views\Teachers\Get.cshtml

It seems that generated code namespace / virtual path attribute influences the build error file path. Is this a known issue or configuration / usage issue?

Sep 4, 2012 at 7:01 PM

I don't see this with my test project: e.g. if I put a compile error in LibraryViewProject\Views\Home\Index.cshtml, the path looks correct.

Can you help identify what could be different with your project?

Sep 4, 2012 at 8:05 PM

I will grab a copy of the test project and try to replicate the issue.


Sep 4, 2012 at 8:36 PM


I was able to replicate the issue in your test project by adding an Area and view with compile error.

Pull Request:




Sep 5, 2012 at 4:07 AM

I see, the problem is that the generator always makes the pragma start with ..\.., which just isn't correct in the general case (code here). We need to rework this logic to take into account the path to the specific view that we're processing instead of hard coding this.

Sep 5, 2012 at 4:30 AM

On second thought, I'm not sure I actually understand what's wrong. We assume that if we use a relative line pragma, it's treated as relative to the binary that the code comes from. Here in the broken case, we end up generating:

    #line 10 "..\..\Areas\Demo\Views\Demo\JsonReference.cshtml"

which actually seems correct. Yet the compiler resolves that in a funny way, ending up with Areas\Demo\areas\demo\views\demo\JsonReference.cshtml.

Maybe relative pragmas just can't be used reliably, but it would be nice to get to the botttom of the behavior.

Sep 5, 2012 at 2:11 PM

Through some trial and error this path worked:

#line 10 "..\..\..\..\Areas\Demo\Views\Demo\JsonReference.cshtml"

Sep 5, 2012 at 3:52 PM

Right, but the question is more about finding the correct algorithm to generate those from the VSIX.

The hard part here is that line pragmas are used for two unrelated things:

  1. Compile error reporting (what we're discussing here)
  2. Debugging

And I'm starting to think that it's not possible to use a pragma with a relative path that will work in both cases, since the relative resolution is not done the same way (I think).

BTW, the reason we went with relative line pragmas is to make the generated code the same on all machines. With absolute paths, each time a different dev saved the view, all the pragmas were changing since they were hard coded to the specific dev's box.

Tough problem :(

Sep 5, 2012 at 4:08 PM

Very tough problem indeed.

Forced to choose, the debug support is more useful than error list navigation. Was a pleasant surprise the first time I had to debug one of the views.

Thanks for looking into this issue,


Sep 5, 2012 at 4:12 PM

Another thing that you can do in some cases is disable line pragmas, which would map both error reporting and debugging to the generated file instead of the cshtml file.

I seem to recall that is supported by Razor, but I can't recall how. :) I'll ask around.

Sep 5, 2012 at 4:23 PM
Edited Sep 5, 2012 at 5:02 PM

@davidebbo, there's a directive that can turn off line pragmas @* DisableLinePragmas:true *@

Edit: Fixed the directive. Forgot that it was in the <key>:<value> format.

There's a also second directive "GenerateAbsolutePathLinePragmas:true" that prints out absolute line paths instead of relative ones.

Sep 5, 2012 at 5:58 PM

I just added that info to the home page