Note that there are some explanatory texts on larger screens.

plurals
  1. POPluggable MVC view return null
    primarykey
    data
    text
    <p>I tried following some of the code from <a href="https://stackoverflow.com/questions/236972/using-virtualpathprovider-to-load-asp-net-mvc-views-from-dlls">here</a> and <a href="http://www.wynia.org/wordpress/2008/12/aspnet-mvc-plugins/" rel="nofollow noreferrer">here</a>, but I am getting an error on the page when trying to reference the remote view located in a separate project: "Value cannot be null. Parameter name: stream"</p> <p>Below is my AssemblyResourceProvider and controller in my master MVC 4 project. I have also attached the whole solution itself <a href="http://temp-share.com/show/f3YgFO3Qn" rel="nofollow noreferrer">here</a>. Can anyone help to see what is going wrong? Thanks for any help or suggestions.</p> <pre><code>public class AssemblyResourceProvider : System.Web.Hosting.VirtualPathProvider { private bool IsAppResourcePath(string virtualPath) { string checkPath = VirtualPathUtility.ToAppRelative(virtualPath); return checkPath.StartsWith("~/Plugin/", StringComparison.InvariantCultureIgnoreCase); } public override bool FileExists(string virtualPath) { return IsAppResourcePath(virtualPath) || base.FileExists(virtualPath); } public override VirtualFile GetFile(string virtualPath) { return IsAppResourcePath(virtualPath) ? new AssemblyResourceVirtualFile(virtualPath) : base.GetFile(virtualPath); } public override CacheDependency GetCacheDependency(string virtualPath, IEnumerable virtualPathDependencies, DateTime utcStart) { return !IsAppResourcePath(virtualPath) ? base.GetCacheDependency(virtualPath, virtualPathDependencies, utcStart) : null; } } public class AssemblyResourceVirtualFile : VirtualFile { string path; public AssemblyResourceVirtualFile(string virtualPath) : base(virtualPath) { path = VirtualPathUtility.ToAppRelative(virtualPath); } public override Stream Open() { string[] parts = path.Split('/'); string assemblyName = parts[2]; string resourceName = parts[3]; var assembly = Assembly.LoadFile(Path.Combine(HttpRuntime.BinDirectory, assemblyName)); return assembly != null ? assembly.GetManifestResourceStream(resourceName) : null; } } </code></pre> <p>And my home controller:</p> <pre><code>public ActionResult Pluggable() { //ViewBag.Name = name; return View("~/Plugin/PluginView1.dll/PluginView1.Views.Home.Pluggable.cshtml"); } </code></pre> <p><img src="https://i.stack.imgur.com/ihWs7.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload