Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何测试某些程序集是否已加载到内存中?_C#_.net_Dll - Fatal编程技术网

C# 如何测试某些程序集是否已加载到内存中?

C# 如何测试某些程序集是否已加载到内存中?,c#,.net,dll,C#,.net,Dll,我有一些代码使用Crystal Reports运行时库生成和丢弃一个小的虚拟报告,以确保在用户创建真正的报告之前及时将这些库加载到内存中。(这是一个“感知性能”问题。)当用户生成报告时,性能得到了显著提高,因此显然所有的功能都可以正常工作 现在,我需要编写一个单元测试,以证明Crystal库确实已按预期加载到内存中-但是,我尝试使用Assembly.getExecutionGassembly().GetModules()来测试内存中的内容没有帮助。(GetCallingAssembly().Ge

我有一些代码使用Crystal Reports运行时库生成和丢弃一个小的虚拟报告,以确保在用户创建真正的报告之前及时将这些库加载到内存中。(这是一个“感知性能”问题。)当用户生成报告时,性能得到了显著提高,因此显然所有的功能都可以正常工作

现在,我需要编写一个单元测试,以证明Crystal库确实已按预期加载到内存中-但是,我尝试使用
Assembly.getExecutionGassembly().GetModules()
来测试内存中的内容没有帮助。(
GetCallingAssembly().GetModules()
也没有更好。)

如何从单元测试中检查这些程序集是否已加载


TIA

以下代码示例使用GetAssemblys方法获取已加载到应用程序域中的所有程序集的列表。然后将这些部件显示到控制台

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());
    }
注意:要运行此代码示例,您需要创建一个名为CustomLibrary.dll的程序集,或者更改传递给GetAssemblys方法的程序集名称


请参见

上的此处。使用Process.GetModules()方法的结果是否有任何不同?这在System.NotSupportedException中不再起作用。NotSupportedException:'此方法隐式使用CAS策略,该策略已被.NET Framework淘汰。为了出于兼容性原因启用CAS策略,请使用NetFx40_LegacySecurityPolicy配置开关。有关详细信息,请参阅。'var assemblies=AppDomain.CurrentDomain.GetAssemblies();