8
votes

Dépendances Appdomain à travers les répertoires

Je crée un système de plug-in et je crée une appdomaine par plugin. Chaque plugin a son propre répertoire avec ses principales assemblées et références. Les assemblages principaux seront chargés par mon chargeur de plug-in, en plus de mes assemblages d'interface (afin que le plugin puisse interagir avec l'application).

Création de l'AppDomain: P>

*** Assembly Binder Log Entry  (12/24/2010 @ 11:03:29 AM) ***

The operation was successful.
Bind result: hr = 0x0. The operation completed successfully.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\MyProject\bin\Debug\MyProject.vshost.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = Null-Laptop-PC\Null-Laptop
LOG: Where-ref bind. Location = C:/MyProject/bin/Debug/MyProject.Library.DLL
LOG: Appbase = file:///C:/PluginDir
LOG: Initial PrivatePath = C:\PluginDir
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = MyProject.vshost.exe
Calling assembly : (Unknown).
===
LOG: This bind starts in LoadFrom load context.
WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().
LOG: Using application configuration file: C:\MyProject\bin\Debug\MyProject.vshost.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Attempting download of new URL file:///C:/MyProject/bin/Debug/MyProject.Library.DLL.
LOG: Assembly download was successful. Attempting setup of file: C:\MyProject\bin\Debug\MyProject.Library.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: MyProject.Library, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
LOG: Re-apply policy for where-ref bind.
LOG: Where-ref bind Codebase does not match what is found in default context. Keep the result in LoadFrom context.
LOG: Binding succeeds. Returns assembly from C:\MyProject\bin\Debug\MyProject.Library.dll.
LOG: Assembly is loaded in LoadFrom load context.

*** Assembly Binder Log Entry  (12/24/2010 @ 11:03:29 AM) ***

The operation was successful.
Bind result: hr = 0x0. The operation completed successfully.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\MyProject\bin\Debug\MyProject.vshost.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = Null-Laptop-PC\Null-Laptop
LOG: Where-ref bind. Location = C:\MyProject\bin\Debug\MyProject.exe
LOG: Appbase = file:///C:/MyProject/bin/Debug/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = MyProject.vshost.exe
Calling assembly : (Unknown).
===
LOG: This bind starts in LoadFrom load context.
WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().
LOG: Using application configuration file: C:\MyProject\bin\Debug\MyProject.vshost.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Attempting download of new URL file:///C:/MyProject/bin/Debug/MyProject.exe.
LOG: Assembly download was successful. Attempting setup of file: C:\MyProject\bin\Debug\MyProject.exe
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: MyProject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
LOG: Re-apply policy for where-ref bind.
LOG: Where-ref bind Codebase matches what is found in default context. Keep the result in default context.
LOG: The post-policy assembly reference requires probing again.
LOG: Switch from LoadFrom context to default context.
LOG: Using application configuration file: C:\MyProject\bin\Debug\MyProject.vshost.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Binding succeeds. Returns assembly from C:\MyProject\bin\Debug\MyProject.exe.
LOG: Assembly is loaded in default load context.
LOG: Where-ref bind Codebase matches what is found in default context. Keep the result in default context.

*** Assembly Binder Log Entry  (12/24/2010 @ 11:03:29 AM) ***

The operation was successful.
Bind result: hr = 0x0. The operation completed successfully.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\MyProject\bin\Debug\MyProject.vshost.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = Null-Laptop-PC\Null-Laptop
LOG: DisplayName = System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
 (Fully-specified)
LOG: Appbase = file:///C:/MyProject/bin/Debug/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = MyProject.vshost.exe
Calling assembly : System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\MyProject\bin\Debug\MyProject.vshost.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Binding succeeds. Returns assembly from C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll.
LOG: Assembly is loaded in default load context.

*** Assembly Binder Log Entry  (12/24/2010 @ 11:03:29 AM) ***

The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\MyProject\bin\Debug\MyProject.vshost.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = Null-Laptop-PC\Null-Laptop
LOG: DisplayName = MyProject.resources, Version=1.0.0.0, Culture=en-US, PublicKeyToken=null
 (Fully-specified)
LOG: Appbase = file:///C:/MyProject/bin/Debug/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = MyProject.vshost.exe
Calling assembly : MyProject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\MyProject\bin\Debug\MyProject.vshost.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/MyProject/bin/Debug/en-US/MyProject.resources.DLL.
LOG: Attempting download of new URL file:///C:/MyProject/bin/Debug/en-US/MyProject.resources/MyProject.resources.DLL.
LOG: Attempting download of new URL file:///C:/MyProject/bin/Debug/en-US/MyProject.resources.EXE.
LOG: Attempting download of new URL file:///C:/MyProject/bin/Debug/en-US/MyProject.resources/MyProject.resources.EXE.
LOG: All probing URLs attempted and failed.

*** Assembly Binder Log Entry  (12/24/2010 @ 11:03:29 AM) ***

The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\MyProject\bin\Debug\MyProject.vshost.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = Null-Laptop-PC\Null-Laptop
LOG: DisplayName = MyProject.resources, Version=1.0.0.0, Culture=en, PublicKeyToken=null
 (Fully-specified)
LOG: Appbase = file:///C:/MyProject/bin/Debug/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = MyProject.vshost.exe
Calling assembly : MyProject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\MyProject\bin\Debug\MyProject.vshost.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/MyProject/bin/Debug/en/MyProject.resources.DLL.
LOG: Attempting download of new URL file:///C:/MyProject/bin/Debug/en/MyProject.resources/MyProject.resources.DLL.
LOG: Attempting download of new URL file:///C:/MyProject/bin/Debug/en/MyProject.resources.EXE.
LOG: Attempting download of new URL file:///C:/MyProject/bin/Debug/en/MyProject.resources/MyProject.resources.EXE.
LOG: All probing URLs attempted and failed.

*** Assembly Binder Log Entry  (12/24/2010 @ 11:03:29 AM) ***

The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\MyProject\bin\Debug\MyProject.vshost.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = Null-Laptop-PC\Null-Laptop
LOG: DisplayName = MyProject.Library, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null, processorArchitecture=MSIL
 (Fully-specified)
LOG: Appbase = file:///C:/PluginDir
LOG: Initial PrivatePath = C:\PluginDir
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = MyProject.vshost.exe
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\MyProject\bin\Debug\MyProject.vshost.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/PluginDir/MyProject.Library.DLL.
LOG: Attempting download of new URL file:///C:/PluginDir/MyProject.Library/MyProject.Library.DLL.
LOG: Attempting download of new URL file:///C:/PluginDir/MyProject.Library.EXE.
LOG: Attempting download of new URL file:///C:/PluginDir/MyProject.Library/MyProject.Library.EXE.
LOG: All probing URLs attempted and failed.

*** Assembly Binder Log Entry  (12/24/2010 @ 11:03:28 AM) ***

The operation was successful.
Bind result: hr = 0x0. The operation completed successfully.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\MyProject\bin\Debug\MyProject.vshost.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = Null-Laptop-PC\Null-Laptop
LOG: DisplayName = MyProject
 (Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: MyProject | Domain ID: 1
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/MyProject/bin/Debug/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = MyProject.vshost.exe
Calling assembly : Microsoft.VisualStudio.HostingProcess.Utilities, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\MyProject\bin\Debug\MyProject.vshost.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/MyProject/bin/Debug/MyProject.DLL.
LOG: Attempting download of new URL file:///C:/MyProject/bin/Debug/MyProject/MyProject.DLL.
LOG: Attempting download of new URL file:///C:/MyProject/bin/Debug/MyProject.EXE.
LOG: Assembly download was successful. Attempting setup of file: C:\MyProject\bin\Debug\MyProject.exe
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: MyProject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
LOG: A partially-specified assembly bind succeeded from the application directory. Need to re-apply policy.
LOG: Using application configuration file: C:\MyProject\bin\Debug\MyProject.vshost.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Binding succeeds. Returns assembly from C:\MyProject\bin\Debug\MyProject.exe.
LOG: Assembly is loaded in default load context.

*** Assembly Binder Log Entry  (12/24/2010 @ 11:03:29 AM) ***

The operation was successful.
Bind result: hr = 0x0. The operation completed successfully.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\MyProject\bin\Debug\MyProject.vshost.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = Null-Laptop-PC\Null-Laptop
LOG: DisplayName = MyPlugin
 (Partial)
WRN: Partial binding information was supplied for an assembly:
WRN: Assembly Name: MyPlugin | Domain ID: 2
WRN: A partial bind occurs when only part of the assembly display name is provided.
WRN: This might result in the binder loading an incorrect assembly.
WRN: It is recommended to provide a fully specified textual identity for the assembly,
WRN: that consists of the simple name, version, culture, and public key token.
WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
LOG: Appbase = file:///C:/PluginDir
LOG: Initial PrivatePath = C:\PluginDir
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = MyProject.vshost.exe
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\MyProject\bin\Debug\MyProject.vshost.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/PluginDir/MyPlugin.DLL.
LOG: Assembly download was successful. Attempting setup of file: C:\PluginDir\MyPlugin.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: MyPlugin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
LOG: A partially-specified assembly bind succeeded from the application directory. Need to re-apply policy.
LOG: Using application configuration file: C:\MyProject\bin\Debug\MyProject.vshost.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Binding succeeds. Returns assembly from C:\PluginDir\MyPlugin.dll.
LOG: Assembly is loaded in default load context.

*** Assembly Binder Log Entry  (12/24/2010 @ 11:03:29 AM) ***

The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\MyProject\bin\Debug\MyProject.vshost.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = Null-Laptop-PC\Null-Laptop
LOG: DisplayName = MyPlugin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
 (Fully-specified)
LOG: Appbase = file:///C:/MyProject/bin/Debug/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = MyProject.vshost.exe
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\MyProject\bin\Debug\MyProject.vshost.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/MyProject/bin/Debug/MyPlugin.DLL.
LOG: Attempting download of new URL file:///C:/MyProject/bin/Debug/MyPlugin/MyPlugin.DLL.
LOG: Attempting download of new URL file:///C:/MyProject/bin/Debug/MyPlugin.EXE.
LOG: Attempting download of new URL file:///C:/MyProject/bin/Debug/MyPlugin/MyPlugin.EXE.
LOG: All probing URLs attempted and failed.

*** Assembly Binder Log Entry  (12/24/2010 @ 11:03:29 AM) ***

The operation was successful.
Bind result: hr = 0x0. The operation completed successfully.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\MyProject\bin\Debug\MyProject.vshost.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = Null-Laptop-PC\Null-Laptop
LOG: DisplayName = Microsoft.VisualStudio.HostingProcess.Utilities, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL
 (Fully-specified)
LOG: Appbase = file:///C:/PluginDir
LOG: Initial PrivatePath = C:\PluginDir
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = MyProject.vshost.exe
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Download of application configuration file was attempted from file:///C:/MyProject/bin/Debug/MyProject.vshost.exe.Config.
LOG: Found application configuration file (C:\MyProject\bin\Debug\MyProject.vshost.exe.Config).
LOG: Using application configuration file: C:\MyProject\bin\Debug\MyProject.vshost.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Microsoft.VisualStudio.HostingProcess.Utilities, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL
LOG: Found assembly by looking in the GAC.
LOG: Binding succeeds. Returns assembly from C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities\10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.dll.
LOG: Assembly is loaded in default load context.

*** Assembly Binder Log Entry  (12/24/2010 @ 11:03:29 AM) ***

The operation was successful.
Bind result: hr = 0x0. The operation completed successfully.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\MyProject\bin\Debug\MyProject.vshost.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = Null-Laptop-PC\Null-Laptop
LOG: DisplayName = Ionic.Zip.Reduced, Version=1.9.1.5, Culture=neutral, PublicKeyToken=edbe51ad942a3f5c
 (Fully-specified)
LOG: Appbase = file:///C:/MyProject/bin/Debug/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = MyProject.vshost.exe
Calling assembly : MyProject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\MyProject\bin\Debug\MyProject.vshost.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Ionic.Zip.Reduced, Version=1.9.1.5, Culture=neutral, PublicKeyToken=edbe51ad942a3f5c
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/MyProject/bin/Debug/Ionic.Zip.Reduced.DLL.
LOG: Assembly download was successful. Attempting setup of file: C:\MyProject\bin\Debug\Ionic.Zip.Reduced.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: Ionic.Zip.Reduced, Version=1.9.1.5, Culture=neutral, PublicKeyToken=edbe51ad942a3f5c
LOG: Binding succeeds. Returns assembly from C:\MyProject\bin\Debug\Ionic.Zip.Reduced.dll.
LOG: Assembly is loaded in default load context.


7 commentaires

Publiez la trace de l'échec Bind Vous obtenez de Fuslogvw.exe


@Abatishchev, veuillez ne pas reformater mon code; C'était complètement inutile.


Vous avez montré la liaison pour l'image Ngen-ED EXE, et non l'échec de l'échec de la DLL. Changez "Catégories de journal" à défaut.


@Hans Passant, mon erreur; J'ai posté la consignation complète dans une mise à jour.


Où est myProject.library.dll? Il ne va pas regarder dans votre répertoire EXE, vous avez modifié la base d'applications.


@Hans Passant, c'est dans le répertoire EXE. Je sais que ça ne va pas regarder là-bas; C'est pourquoi j'essaie de le charger manuellement.


Vous êtes, avec le mauvais chemin de sondage en vigueur.


3 Réponses :


3
votes

Je pense que l'exception est survenue lorsqu'elle essaie de charger l'assemblage dans le AppDomain et non du domaine que vous avez créé explicitement. Il s'agit d'un effet secondaire de l'utilisation de appdomain.load qui conduit à l'ensemble chargé dans le domaine actuel et le domaine que vous avez créé. Étant donné que l'assemblage est uniquement dans le chemin Bin (répertoire du plug-in) du domaine que vous avez créé, vous obtenez l'exception.

de MSDN liée à AppDomain.load :

L'ensemble est chargé dans les deux domaines parce que l'assemblage ne dériver de MarshalbyRefObject, et Par conséquent, la valeur de retour de la charge la méthode ne peut pas être montérale. Au lieu, Le runtime de langue commune essaie de charger l'assemblage dans l'appel Domaine d'application.


3 commentaires

Peut-être que c'est le cas. Y a-t-il un moyen de charger uniquement dans l'appdomain?


Vous pouvez essayer de déplacer l'opération de charge dans un AppDomelagnetup.appdomainInitializer Délégué qui est exécuté dans le nouveau AppDomain quand il est initialisé. De cette façon, le code ne fonctionne pas dans votre domaine principal.


J'ai essayé de définir un appdomainInitializer, mais lors de la création de l'appdomain, une exception est lancée en disant que l'assemblage contenant mon rappel n'a pas pu être chargé, alors je suis de retour à l'endroit où j'ai commencé.



2
votes

J'ai eu un problème similaire. Vous devez personnaliser la méthode utilisée pour trouver les assemblages. Les déclarations de console.debug devraient être modifiées pour compiler mais voici le GIST GRÉAL:

private static void SetupResolvingAdditionalThirdPartyDlls()
{
  AppDomain.CurrentDomain.AssemblyResolve += ResolveAssemblies;
}

private static Assembly ResolveAssemblies(object sender, ResolveEventArgs args)
{
  Assembly assembly = null;
  bool foundAssembly = false;

  Console.DebugFormat("Received request for the following dll {0}", args.Name);
  int idx = args.Name.IndexOf(',');
  if (idx > 0)
  {
    string partialName = args.Name.Substring(0, idx);
    string dllName = partialName + ".dll";
    string exeName = partialName + ".exe";

    string searchDirectory = "locationOfDirectoryToSearch";
    // Add other directories that you want to search here


    List<string> directorySearch = new List<string>
    {
      CombinePath(searchDirectory, dllName),
      CombinePath(searchDirectory, exeName),
      // Include the other directories here to this list adding both the dll and exe.
    };

    foreach (string fileName in directorySearch)
    {
      if (File.Exists(fileName))
      {
        Console.DebugFormat("Found dll {0} at {1}", args.Name, fileName);
        foundAssembly = true;
        assembly = Assembly.LoadFrom(fileName);
        break;
      }
    }

    if (assembly == null)
    {
      if (!foundAssembly)
      {
        foreach (string fileName in directorySearch)
        {
          Console.DebugFormat("Could not find dll {0} in any search path used {1}", args.Name, fileName);
        }
      }
      else
      {
        Console.DebugFormat("Could not load dll {0}", args.Name);
      }
    }
  }

  return assembly;
}


0 commentaires

9
votes

J'ai essayé une de mes tentatives de solutions:

Création d'un objet à l'aide de Ceci.AppDomain.CreateInstanceANDunWrap Code> Héritage de MarshalbyRefObject avec un Loadassembly code> méthode pour charger l'assemblage. Je reçois une exception disant que l'assemblage actuel (contenant la classe de proxy) n'a pas pu être chargé (le fichier non trouvé, comme ci-dessus), même si j'appelle manuellement this.appdomain.load (assemblage.getexecutingassembly (). GetName (). vrai)) code>. p> blockQuote>

J'ai découvert que CreateInstanceFromandunWrap code> peut accepter le chemin d'accès à un fichier d'assemblage, ce qui facilite les choses: p>

private T CreateOnAppDomain<T>() {
    var type = typeof(T);

    return (T) this.appDomain.CreateInstanceFromAndUnwrap(
        type.Assembly.Location,
        type.FullName
    );
}

public void LoadAssemblies() {
    var assemblyLoader = CreateOnAppDomain<AssemblyLoader>();

    assemblyLoader.LoadAssembly(myInterfaceAssembly.GetName(true));

    foreach (var assemblyName in this.assemblyNames) {
        assemblyLoader.LoadAssembly(new AssemblyName(assemblyName));
    }
}

class AssemblyLoader : MarshalByRefObject {
    public void LoadAssembly(AssemblyName name) {
        Assembly.Load(name);
    }
}


0 commentaires