Assembly.Load file and unloading RRS feed

  • Question

  • Hi all,

    One might think that using Assembly.Load to create an Assembly refernce in your program would get unloaded after the Assembly goes out of scope but from what I have read I am not so sure.  So given the code below does the Assembly get unloaded when the Assembly asm variable goes out of scope?

          public AnamTest ReturnTest(string testType)
             AnamTest test = null;
             Assembly asm = Assembly.LoadFile("C:\\!!CodeDOM\\TestTypes_20091128_11_22_22_693.dll");
             Type derivedType = asm.GetType("TestFactory.TestTypes." + testType);
             if (derivedType != null)
                // if the type was found then create an instance of it
                test = (AnamTest)Activator.CreateInstance(derivedType);
             return test;

    What I am thinking might be a good practice is to load the assembly into memory (byte[]) and make it only available from a Singleton.  Would that be a good practice?

    Thanks, -ja
    Saturday, November 28, 2009 7:50 PM


All replies