How to check if certain assemblies have been loaded into memory?

I have code that uses Crystal Reports runtime libraries to generate and discard a small dummy report to ensure libraries are loaded into memory in a timely manner before the user creates an authentic report. (This is a β€œperceived performance" issue.) Performance has improved markedly when the user generates a report, so it’s clear that everything works.

Now I need to write a unit test, which proves that Crystal libraries are really loaded into memory when it was expected, but my attempts to check what is used there with Assembly.GetExecutingAssembly().GetModules() do not help. ( GetCallingAssembly().GetModules() also no better.)

How can I check from my unit test to find out if these assemblies are loaded?

TIA

+4
c # dll
Apr 01 '14 at 11:23
source share
1 answer

The following code example uses the GetAssemblies method to list all the assemblies that have been uploaded to the application domain. Then the assemblies are displayed on the console.

 public static void Main() { AppDomain currentDomain = AppDomain.CurrentDomain; //Provide the current application domain evidence for the assembly. Evidence asEvidence = currentDomain.Evidence; //Load the assembly from the application directory using a simple name. //Create an assembly called CustomLibrary to run this sample. currentDomain.Load("CustomLibrary",asEvidence); //Make an array for the list of assemblies. Assembly[] assems = currentDomain.GetAssemblies(); //List the assemblies in the current application domain. Console.WriteLine("List of assemblies loaded in current appdomain:"); foreach (Assembly assem in assems) Console.WriteLine(assem.ToString()); } 

PS: To run this sample code, you need to create an assembly called CustomLibrary.dll or change the assembly name that is passed to the GetAssemblies method.

See here MSDN

+3
Apr 01 '14 at 11:42 on
source share



All Articles