How are DLLs loaded by the CLR?

前端 未结 4 694
名媛妹妹
名媛妹妹 2020-12-01 04:58

My assumption was always that the CLR loaded all of the DLLs it needed on startup of the app domain. However, I\'ve written an example that makes me question this assumption

4条回答
  •  情话喂你
    2020-12-01 05:35

    This is a little off your question, but you can load all the assemblies at once if you would prefer not having it happen on demand. Something like this should do the trick

    foreach (AssemblyName asn in Assembly.GetExecutingAssembly().GetReferencedAssemblies())
    {
        var asm = Assembly.Load(fn);
        // I've found get types does a good job of ensuring the types are loaded.
        asm.GetTypes();
    }
    

提交回复
热议问题