AssemblyResolve不火 [英] AssemblyResolve Does not fire

查看:140
本文介绍了AssemblyResolve不火的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个asp.net应用程序。我想动态加载一些组件。

I have an asp.net application. I want to load some assemblies dynamically.

这是在应用程序启动我的code

this is my code on application start

    protected void Application_Start(Object sender, EventArgs e)
        {
            LoadPrivateAssemblies();
        }
    private static void LoadPrivateAssemblies()
        {
            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomainAssemblyResolve;

            Assembly.Load("MyDLL");
        }
    static Assembly CurrentDomainAssemblyResolve(object sender, ResolveEventArgs args)
        {
            //loads and returns assembly successfully.
        }

这code正常工作除了当一个嵌套C#code调用从我的动态的dll类内部一个asp.net页面(而不是code-后面)

this code works fine except when a nested c# code calls a class from my dynamic dll Inside an asp.net page (not code-behind)

示例:

<%if(MyDLL.TestObject.Value){%>white some ting<%}%>

我应该怎么办?

我想如果我知道当创建一个新的AppDomain,它可以解决我的问题。

I think If I know When a new AppDomain is created, it may solve my problem.

推荐答案

我发现问题是因为的Assembly.Load(字节); 不坚持的组件应用程序域。是否有任何身体知道如何使用坚持加载的程序集的Assembly.Load(字节); 中的AppDomain

I found that the problem is because Assembly.Load(bytes); does not persist the assembly in appdomain. does any body know how to persist loaded assembly using Assembly.Load(bytes); in appdomain ?

我终于决定改用的LoadFile方法,而不是负担。

finally I decided to switch to LoadFile method instead of load.

修改

最后,我从 Assemly.Load切换(字节[]) Assembly.LoadFile(串)

但它并不能解决问题本身。我已经加入&LT;%@大会名称=MYDLL%&GT; 我所有的ASPX文件有标记C#code emebeded

But it did not correct the problem itself. I have added <%@Assembly name="MyDLL"%> To All of my ASPX files that has markup C# code emebeded.

这解决了我的问题。

感谢您的回答。我投了答案,帮助我,但因为没有人是不够完整的,我不能接受你的解决方案。

Thanks to your answers. I have voted up answers that helped me, but I can not accept your solutions because no one is not complete enough.

这篇关于AssemblyResolve不火的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆