【问题标题】:Can not create UserControl inside new AppDomain无法在新的 AppDomain 中创建 UserControl
【发布时间】:2013-09-01 11:07:11
【问题描述】:

当我将程序集(xxx.dll)加载到新的 AppDomain 并尝试在那里创建 UserControl 时,出现异常:

Could not load file or assembly 'xxx.resources' or one of its dependencies.

当我将程序集加载到 Main AppDomain 时,它工作正常。
为什么会出现异常?

public void InitializeComponent() {
if (_contentLoaded) {
      return;
}
_contentLoaded = true;

//这里出现异常

System.Uri resourceLocater = new System.Uri("/Company.AddInApp;component/controls/usercontrol.xaml", System.UriKind.Relative);

#line 1 "..\..\..\Controls\UserControl1.xaml" stem.Windows.Application.LoadComponent(this, resourceLocater);
#line default
#line hidden
}

【问题讨论】:

  • SOS 伙计们......需要帮助......
  • 您应该使用融合日志查看器进行调试 - hanselman.com/blog/…
  • “融合日志”什么也没告诉我,它只是显示搜索路径(AppDomain 基本目录)中遗漏了哪些程序集。它还添加了 locale(ex: en-EN) 目录来搜索... (((
  • 那么,xxx.resources 程序集实际上是否存在于它搜索的任何路径中?如果不是,那么它存在于什么路径中?
  • “xxx.resources”程序集不存在...

标签: c# wpf appdomain


【解决方案1】:

我发现了错误:

var setup = new AppDomainSetup
{
        ApplicationBase = rootAddInsPath,
         ........
};
var appDomain = AppDomain.CreateDomain(...)

//I don't must do this here!!!
appDomain.AssemblyResolve += (sender, args) =>
{
     ....
}

var managerType = typeof(AddInLoadManager);
var manager =(AddInLoadManager)appDomain.CreateInstanceAndUnwrap(managerType.Assembly.FullName, managerType.FullName);

“AppDomain.AssemblyResolve”事件的正确位置是在“AddInLoadManager”类中。

感谢您的帮助@YK1

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多