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");
}
Here is my AssemblyResourceVirtualFile that I used in a project before:
public class AssemblyResourceVirtualFile : VirtualFile
{
string path;
public AssemblyResourceVirtualFile(string virtualPath) : base(virtualPath)
{
path = VirtualPathUtility.ToAppRelative(virtualPath);
}
public override System.IO.Stream Open()
{
string[] parts = path.Split('/');
string assemblyName = parts[2];
string resourceName = parts[3];
assemblyName = Path.Combine(HttpRuntime.BinDirectory, assemblyName);
System.Reflection.Assembly assembly = System.Reflection.Assembly.LoadFile(assemblyName);
if (assembly != null)
{
Stream resourceStream = assembly.GetManifestResourceStream(resourceName);
return resourceStream;
}
return null;
}
}
Really the only difference is I've made it so you can stick break points in there and walk to see what it finds. Put your break point in and walk the code, is the assembly == null? If not, is resourceStream null?