I tried following some of the code from here and here, 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"
Below is my AssemblyResourceProvider and controller in my master MVC 4 project. I have also attached the whole solution itself here. Can anyone help to see what is going wrong? Thanks for any help or suggestions.
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;
}
}
And my home controller:
public ActionResult Pluggable()
{
//ViewBag.Name = name;
return View("~/Plugin/PluginView1.dll/PluginView1.Views.Home.Pluggable.cshtml");
}