title: Consuming a Razor Class Library with Partial Views in .Net Framework Project
body: <p>I have recently come across Razor Class Libraries and am not 100% sure of what can / can't be achieved with them, but am very much liking the concept of being able to create views (and partial views) which can be shared within multiple web projects.</p>
  
  <p>However, whilst I know a bit of C# and am quite familiar with the conversion tools, I am 1000 times more proficient with VB.Net and consequently most of my work is coded that way. .NET Core, as far as I can deduce does not support VB.NET.</p>
  
  <p>I followed the tutorial and downloaded the sample code from here <a href="https://docs.microsoft.com/en-us/aspnet/core/razor-pages/ui-class?view=aspnetcore-3.1&amp;tabs=visual-studio" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/aspnet/core/razor-pages/ui-class?view=aspnetcore-3.1&amp;tabs=visual-studio</a></p>
  
  <p>With this I was able to build a solution containing a RCL and a .NetCore website which uses views and partial views from the RCL.</p>
  
  <p>I was able to build multiple .NETCore Websites and all I had to do was to add a reference to the RCL Project and they would all use the shared partial views in the RCL... everything worked well.</p>
  
  <p>EXCEPT, I don't want a .NETCore website project because I want to stick with VB.NET, so I read up and am told that the RCL I have created using .netstandard2.0 should be compatible with the .Net Framework.</p>
  
  <p><strong>Note; Essentially, for the immediate requirements, I intend to use an RCL predominently for creating partial views to be shared across multiple projects. I am happy to create them using C# for the project logic, and a lot of my code logic already exists in VB class libraries which I can import, but don't want to have to rewrite or relearn everything I have already done in the main bulk of my projects.</strong></p>
  
  <p>Upgrading all my work to .NetCore would be a nightmare in one go anyway...</p>
  
  <p>So....</p>
  
  <ul>
  <li>I created a VB Web Application targeting .Net Framework 4.7.2.</li>
  <li>I add a reference to my RCL</li>
  <li>I ran a Build to check there were no version conflicts or reference incompatibilities</li>
  <li>I ran the website to check no build errors that weren't caught by Visual Studio</li>
  </ul>
  
  <p>All the above worked fine, the reference added OK, no problems at all.</p>
  
  <p>BUT... I cannot work out how to get the partial views in the RCL to be accessible to the website.</p>
  
  <p>I am constantly getting the error</p>
  
  <pre><code>The partial view '****' was not found or no view engine supports the searched locations.
  </code></pre>
  
  <p>Can anyone tell me</p>
  
  <ul>
  <li>How to hook up a Razor Class Library in order for Partial Views to be consumed in a .Net Framework Project?</li>
  <li>Am I (quite likely knowing me) trying to do something that is simply not meant to work like that?!</li>
  </ul>
  
  <p><strong>EDIT...</strong></p>
  
  <p>Quite reasonably asked by Ben in the comments below, to clarify exactly what I'm doing</p>
  
  <p>Firstly. I am literally just experimenting with a new Solution, so each time I am adding Projects I am literally just going to "Add New project  > <em>select</em>". I am not editing the projects beyond the templates created by Visual Studio (2019 Community Edition if it makes any difference) except to add the reference to my RCl.</p>
  
  <p>The RCL has a single partial view which I am trying to display, it's contents are:</p>
  
  <pre><code>@using RazorUIClassLib
  &lt;h1&gt;This is nothing but a test&lt;/h1&gt;
  </code></pre>
  
  <p>Where obviously <code>RazorUIClassLib</code> is the name of the RCL... there is nothing else in it at all at this stage.</p>
  
  <p>File structure is</p>
  
  <pre><code>&gt; Pages &gt; Shared &gt; Test.cshtml
  </code></pre>
  
  <p>I have a C# .NETCore Project called <code>WebApp1</code> which is the exact Project from the example downloaded from the link above has a relevant file structure</p>
  
  <pre><code>&gt; Pages &gt; Index.cshtml
  </code></pre>
  
  <p>In Index.cshtml I have added this line:</p>
  
  <pre><code>&lt;partial name="Test"/&gt;
  </code></pre>
  
  <p>(Note; Visual Studio seems a little iffy about finding the Test file as intellisense (ReSharper) is saying <code>cannot resolve partial view'Test'</code>, but it runs fine)</p>
  
  <p>I have a second C# .netcore project which I added to make sure there wasn't something "special" about the one I downloaded from the example code, that is structured exactly as the Visual Studio Template, and has a slightly different file structure:</p>
  
  <blockquote>
    <p>Views > Home > Index.cshtml</p>
  </blockquote>
  
  <p>The same single line of code is added to this file as above and works just the same (all I did after adding this brand new project was to add this line and the reference to my RCL Project)</p>
  
  <p>The <strong>problem</strong> Project is a VB Project, which obviously is targeting .Net Framework NOT CORE. It is literally just the default file structure created by Visual Studio when adding a new MVC Project to the Solution, so we have</p>
  
  <blockquote>
    <p>Views > Home > Index.vbhtml  </p>
  </blockquote>
  
  <p>Again, I have done nothing to it except to add the reference to my RCL Project and this line:</p>
  
  <pre><code>@Html.Partial("Test")
  </code></pre>
  
  <p>I have also tried</p>
  
  <pre><code>@Html.Partial("/Pages/Shared/Test")
  @Html.Partial("~/Pages/Shared/Test")
  @Html.Partial("/RazorUIClassLib/Pages/Shared/Test")
  @Html.Partial("~/RazorUIClassLib/Pages/Shared/Test")
  </code></pre>
  
  <p>And also all the above with the .cshtml file extension.</p>
  
  <p>In all cases I get varying forms of this error:</p>
  
  <pre><code>The partial view 'Test' was not found or no view engine supports the searched locations. The following locations were searched:
  ~/Views/Home/Test.aspx
  ~/Views/Home/Test.ascx
  ~/Views/Shared/Test.aspx
  ~/Views/Shared/Test.ascx
  ~/Views/Home/Test.cshtml
  ~/Views/Home/Test.vbhtml
  ~/Views/Shared/Test.cshtml
  ~/Views/Shared/Test.vbhtml
  </code></pre>
  
  <p>Clearly from the error it is expecting to find the Partial in the <code>Views</code> Directory, but as I mention, if I add the full path I still get the same error but with different "I tried looking here" type notes.</p>
  
  <p>I keep saying that I haven't changed anything to clarify that I have not made any routing alterations... am wondering if I should, but if so, not sure what!</p>