Question

When i load assembly(xxx.dll) into new AppDomain and trying to create UserControl there, occurs the exception:

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

When i load the assembly into Main AppDomain it works fine.
Why the exception occurs?

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

//HERE THE EXCEPTION OCCURS

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
}
Was it helpful?

Solution

I have found the mistake:

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);

Correct place for the "AppDomain.AssemblyResolve" event is inside of the "AddInLoadManager" class.

Thanks for your help @YK1

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top