开发者

ASP.net VirtualPathProvider to dynamically load controls

I'm using VirtualPathProvider to load controls (ascx) that are not present at compile time. So when a certain path structure is requested, the VirtualPathProvider rewrites the path to the ascx and loads the dll that contains the code for that control.

Everything works fine except the dll loading. I can load the assembly but the site can't find it. If I put it on the bin folder everything works fine.

To load the assembly I'm using:

System.Reflection.Assembly.LoadFrom(file.FullName);

How can I load this assembly so it can be used when the ascx is rendered on the page?

Again, I could put the dll on the bin folder of the site but 开发者_StackOverflow中文版as this is dynamic content I prefer to keep it all as isolated.


So you're calling

System.Reflection.Assembly.LoadFrom(file.FullName);

But it doesn't throw an exception doing that, but still doesn't find your assembly when the ascx file is rendered? Are you sure your ascx file references the fully qualified assembly name?

Chances are you'll need to handle the AssemblyResolve event:

AppDomain.CurrentDomain.AssemblyResolve += OnCurrentDomainAssemblyResolve

private static Assembly OnCurrentDomainAssemblyResolve(object sender, ResolveEventArgs args)
{
    if (args.Name == "myDynamicAssemblyName") return _myPreviouslyLoadedDynamicAssemblyObtainedFromAssemblyLoadFrom;

    return null;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜