0

次のコードを試しました:

AppDomain ad = AppDomain.CreateDomain("Test");      
_Assembly = parDomain.Load(AssemblyName.GetAssemblyName(@"C:\SomeDLLPath\PhysicsTest.dll"));
// Some work with assembly
AppDomain.Unload(ad);

上げるFileNotFoundException that cannot load file or assembly "TestClass, Version=1.0.0.0, ..."

このドメインにアセンブリをロードすると、すべて問題ありません。

_Assembly = Assembly.LoadFile(@"C:\SomeDLLPath\PhysicsTest.dll");

しかし、これもアンロードする必要があります。

私はそれについて多くのスレッドを見ましたが、それらを理解できません...

4

1 に答える 1

1

MSDNから

引用符

アセンブリを含むすべてのアプリケーション ドメインをアンロードせずに、個々のアセンブリをアンロードする方法はありません。アセンブリが範囲外になっても、実際のアセンブリ ファイルは、それを含むすべてのアプリケーション ドメインがアンロードされるまで読み込まれたままになります。

AppDomain MSDNをアンロードする方法は次のとおりです。

using System;
using System.Reflection;

class AppDomain2
{
    public static void Main()
    {
        Console.WriteLine("Creating new AppDomain.");
        AppDomain domain = AppDomain.CreateDomain("MyDomain", null);

        Console.WriteLine("Host domain: " + AppDomain.CurrentDomain.FriendlyName);
        Console.WriteLine("child domain: " + domain.FriendlyName);
        AppDomain.Unload(domain);
        try
        {
            Console.WriteLine();
            Console.WriteLine("Host domain: " + AppDomain.CurrentDomain.FriendlyName);
            // The following statement creates an exception because the domain no longer exists.
            Console.WriteLine("child domain: " + domain.FriendlyName);
        }
        catch (AppDomainUnloadedException e)
        {
            Console.WriteLine(e.GetType().FullName);
            Console.WriteLine("The appdomain MyDomain does not exist.");
        }
    }
}
于 2012-05-13T19:32:42.760 に答える