16

I've upgraded from ReSharper 7 on vs2012 pro to ReSharper 8.1 on vs2013 pro, and ReSharper is now warning me a lot of my partial views cannot be resolved. It seems to be only happening:

  • In ASP master pages (i.e. not razor)
  • When the .ascx partial is in the same controller folder as the partial

E.g. Home.Master, located in ~/Views/Home/Home.Master renders UserProfile.ascx, located in ~/Views/Home/UserProfile.ascx. Both <%: Html.RenderPartial("UserProfile") %> and <%: Html.RenderPartial("~/Views/Home/UserProfile.ascx"%> are flagged by ReSharper as invalid.

Additionally, shared partials in the ~/views/shared folder seem to be picked up fine when I reference just by name:

RenderPartial by view name working correctly

However, referencing the view by path doesn't seem to work:

enter image description here

(NB. Both images are taken inside Home.Master, in ~/Views/Home)

When I run the application, the partials work correctly, so it seems to be a change in ReSharper 8.1. Is there anything I can do to fix this?

berkeleybross
  • 1,314
  • 2
  • 13
  • 27
  • 2
    This looks like a good question for the resharper team and not StackOverflow. – Brad Christie Feb 04 '14 at 21:47
  • 3
    The stack overflow help topics specifically mention questions which cover "software tools commonly used by programmers" are appropriate. While I think this is a bug with ReSharper, I'm hoping that it is actually something I am doing wrong - hence asking on stack overflow – berkeleybross Feb 04 '14 at 21:56
  • 1
    I'm having a similar issue, but for me it's only within the Razor pages. What's more worrying is there doesn't appear to be anything about it on JetBrain's forums. If I find a solution, I'll post back here. – BJury Feb 12 '14 at 10:42
  • It's easily reproducible in a bare bones project, so I've submitted it as a bug to JetBrains. – BJury Feb 12 '14 at 17:41

3 Answers3

9

It's a bug in ReSharper.

The best thing for now is to set it to ignore this type of error.

You can do this by selecting 'inspection options' from the 'red light bulb' on the left hand side and setting it to another option. Hopefully it will be fixed soon!

Edit: See this ticket for the problem. http://youtrack.jetbrains.com/issue/RSRP-395642

BJury
  • 2,526
  • 3
  • 16
  • 27
6

There's a simpler fix I've got around it by using relative references. So in my case I had a view in another project (and if you try to go outside of the current project without starting with a forward slash "/" you'll get a warning like this. For your problem change the line that reads

<%Html.RenderPartial("UserProfile")%>

to

<%Html.RenderPartial("../../Views/Home/UserProfile")%>

or

<%Html.Partial("../../Views/Home/UserProfile.cshtml")%>

Not sure if this is the exact path in your solution but hopefully you understand what I am saying - you cannot use the tilde (~) symbol. You have to use HTML's navigation symbol. Not ideal obviously but I dare say it is better than changing inspection rules.

Also - if you do need to remove an inspection, just comment it out by adding the line

// ReSharper disable once Mvc.PartialViewNotResolved
... // code goes here

or

// ReSharper disable Mvc.PartialViewNotResolved
... // code goes here 
// ReSharper restore once Mvc.PartialViewNotResolved

You can use T4 templates POCO string properties to generate the paths. It's a good idea to update these T4 generated classes regularly and use them inside your code.

csharpforevermore
  • 1,472
  • 15
  • 27
  • 2
    but this way you'll have a lot of headache if you ever decide to move stuff around, since your path configuration is not in one place, but scattered around all the (partial) views – Mladen B. Jan 05 '18 at 13:56
0

I was getting this error today from ReSharper 2018.2.3 when did this:

@Html.Partial("_StatusMessage", Model.StatusMessage)

I also noticed a warning from the IHtmlHelper.Partial method itself:

Use of IHtmlHelper.Partial may result in application deadlocks. Consider using <partial> Tag Helper or IHtmlHelper.PartialAsync.

So I changed the code to:

<partial name="_StatusMessage" model="Model.StatusMessage" />

That fixed it for me.

crgolden
  • 4,332
  • 1
  • 22
  • 40