{"id":984,"date":"2013-11-15T08:04:00","date_gmt":"2013-11-15T08:04:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/webdev\/2013\/11\/15\/asp-net-performance-managed-runtime-loader\/"},"modified":"2013-11-15T08:04:00","modified_gmt":"2013-11-15T08:04:00","slug":"asp-net-performance-managed-runtime-loader","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/dotnet\/asp-net-performance-managed-runtime-loader\/","title":{"rendered":"ASP.NET Performance: Managed runtime loader"},"content":{"rendered":"<div class=\"WordSection1\">\n<p><em>Editor note: This blog is originally published by <a href=\"http:\/\/blogs.msdn.com\/272012\/ProfileUrlRedirect.ashx\">Jose Reyes &#8211; ASP.NET<\/a><\/em><em> on 02-29-2012 in <\/em><a href=\"http:\/\/blogs.msdn.com\/b\/web_performance_blog\/\"><em>Web Performance Blog<\/em><\/a><em>, which will be obsolete soon.&nbsp; Future ASP.NET related performance blogs will be posted here.<\/em><\/p>\n<h2><span style=\"font-variant: normal !important\">Introduction<\/span><\/h2>\n<p class=\"MsoNormal\">There is a file called aspnet.config in the .Net framework installation. This file is used to specify startup flags for both ASP.NET and CLR for those settings that are needed very early in the worker process lifetime, when the config system is not yet present.<\/p>\n<p class=\"MsoNormal\">In IIS 7.5 we added an attribute to the &lt;applicationPools&gt; configuration collection called CLRConfigFile, on the applicationHost.config file, which allows you to specify your own aspnet.config, for a particular application pool.<\/p>\n<p class=\"MsoNormal\">There is another attribute on the &lt;applicationPools&gt; called managedRuntimeLoader, which specify the library in charge of loading CLR. By default, this task is executed by ASP.NET native layer, in the webengine4.dll. If no loader is specified, or if an error occurs, the loading falls back to IIS itself.<\/p>\n<h2><span style=\"font-variant: normal !important\">IIS 7.5 issue.<\/span><\/h2>\n<p class=\"MsoNormal\">There was a problem in IIS 7.5, in which the managedRuntimeLoader was never provided with the path to this CLRConfigFile, so it was forced to use the one in the framework directory. So if you wanted to use the CLRConfigFile, to setup different CLR flags for an application pool, you will need to set the attribute AND explicitly clear the managedRuntimeLoader attribute on the application pool <a href=\"http:\/\/www.iis.net\/ConfigReference\/system.applicationHost\/applicationPools\/add\">definition<\/a> on applicationHost.config:<\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp; &#8230;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"color: blue;font-family: consolas;font-size: 9.5pt\">&lt;<\/span><span style=\"color: #a31515;font-family: consolas;font-size: 9.5pt\">system.applicationHost<\/span><span style=\"color: blue;font-family: consolas;font-size: 9.5pt\">&gt;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp; &#8230;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"color: blue;font-family: consolas;font-size: 9.5pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;<\/span><span style=\"color: #a31515;font-family: consolas;font-size: 9.5pt\">applicationPools<\/span><span style=\"color: blue;font-family: consolas;font-size: 9.5pt\">&gt;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"color: blue;font-family: consolas;font-size: 9.5pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;!&#8211;<\/span><span style=\"color: green;font-family: consolas;font-size: 9.5pt\"> Set the CLRConfigFile and clear managedRuntimeLoader <\/span><span style=\"color: blue;font-family: consolas;font-size: 9.5pt\">&#8211;&gt;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"color: blue;font-family: consolas;font-size: 9.5pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;<\/span><span style=\"color: #a31515;font-family: consolas;font-size: 9.5pt\">add<\/span><span style=\"color: red;font-family: consolas;font-size: 9.5pt\">name<\/span><span style=\"color: blue;font-family: consolas;font-size: 9.5pt\">=<\/span><span style=\"font-family: consolas;font-size: 9.5pt\">&#8220;<span style=\"color: blue\">MyAppPool<\/span>&#8220;<span style=\"color: red\">CLRConfigFile<\/span><span style=\"color: blue\">=<\/span>&#8220;<span style=\"color: blue\">c:myconfigsmyapp1aspnet.config<\/span>&#8220;<span style=\"color: red\">managedRuntimeLoader<\/span><span style=\"color: blue\">=<\/span>&#8220;&#8221;<span style=\"color: blue\"> \/&gt;<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp; &#8230;<\/span><\/p>\n<p class=\"MsoNormal\">&nbsp;<\/p>\n<p class=\"MsoNormal\">The second step shouldn&rsquo;t be necessary and is confusing. The clearing of the attributes basically forces the fall back to IIS runtime loader, which uses the correct CLRConfigFile.<\/p>\n<p class=\"MsoNormal\">This has been fixed on IIS 8, where you only need to set the CLRConfigFile attribute.<\/p>\n<p class=\"MsoNormal\">To verify this is working, you can change one parameter on the aspnet.config such as disabling the server garbage collector. <em>(Note: Disabling the server garbage collector is a good thing if you want to save memory, at the expense of throughput. Typical use of this is hosting scenarios, where web sites has low traffic and higher site density is desirable.)<\/em><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"color: blue;font-family: consolas;font-size: 9.5pt\">&lt;<\/span><span style=\"color: #a31515;font-family: consolas;font-size: 9.5pt\">configuration<\/span><span style=\"color: blue;font-family: consolas;font-size: 9.5pt\">&gt;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"color: blue;font-family: consolas;font-size: 9.5pt\">&nbsp;&nbsp;&nbsp; &lt;<\/span><span style=\"color: #a31515;font-family: consolas;font-size: 9.5pt\">runtime<\/span><span style=\"color: blue;font-family: consolas;font-size: 9.5pt\">&gt;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"color: blue;font-family: consolas;font-size: 9.5pt\">&nbsp; &#8230;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"color: blue;font-family: consolas;font-size: 9.5pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;<\/span><span style=\"color: #a31515;font-family: consolas;font-size: 9.5pt\">gcServer<\/span><span style=\"color: red;font-family: consolas;font-size: 9.5pt\">enabled<\/span><span style=\"color: blue;font-family: consolas;font-size: 9.5pt\">=<\/span><span style=\"font-family: consolas;font-size: 9.5pt\">&#8220;<span style=\"color: blue\">false<\/span>&#8220;<span style=\"color: blue\">\/&gt;<\/span><\/span><\/p>\n<p class=\"MsoNormal\">&nbsp;<\/p>\n<p class=\"MsoNormal\">Attaching a debugger to the worker process and using SOS command !eeversion will show the garbage collector mode being used:<\/p>\n<p class=\"MsoNormal\" style=\"margin-bottom: 0pt\"><span style=\"line-height: 115%;font-family: 'Courier New';font-size: 9pt\">C:&gt;cdb.exe -pn w3wp.exe<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin-bottom: 0pt\"><span style=\"line-height: 115%;font-family: 'Courier New';font-size: 9pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin-bottom: 0pt\"><span style=\"line-height: 115%;font-family: 'Courier New';font-size: 9pt\">Microsoft (R) Windows Debugger Version 6.13.0009.1140 X86<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin-bottom: 0pt\"><span style=\"line-height: 115%;font-family: 'Courier New';font-size: 9pt\">Copyright (c) Microsoft Corporation. All rights reserved.<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin-bottom: 0pt\"><span style=\"line-height: 115%;font-family: 'Courier New';font-size: 9pt\">&nbsp; &hellip;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin-bottom: 0pt\"><span style=\"line-height: 115%;font-family: 'Courier New';font-size: 9pt\">0:044&gt; .loadby sos clr<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin-bottom: 0pt\"><span style=\"line-height: 115%;font-family: 'Courier New';font-size: 9pt\">0:044&gt; !eeversion<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin-bottom: 0pt\"><span style=\"line-height: 115%;font-family: 'Courier New';font-size: 9pt\">4.0.30319.239 retail<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin-bottom: 0pt\"><span style=\"background: yellow;line-height: 115%;font-family: 'Courier New';font-size: 9pt\">Workstation mode<\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin-bottom: 0pt\"><span style=\"line-height: 115%;font-family: 'Courier New';font-size: 9pt\">SOS Version: 4.0.30319.239 retail build<\/span><\/p>\n<p class=\"MsoNormal\">&nbsp;<\/p>\n<p class=\"MsoNormal\">Make sure your box has more than one logical core; otherwise workstation mode will always be used.<\/p>\n<h2><span style=\"font-variant: normal !important\">Implementing a loader<\/span><\/h2>\n<p>Implementing a loader is probably not needed, but if you want to do it, you will need a native DLL that exports a function named <span style=\"font-family: consolas;font-size: 9.5pt\">LoadManagedRuntime<\/span>. In IIS 8 you can also export LoadManagedRuntimeEx. The function signature is shown below:<\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">HRESULT <span style=\"color: blue\">__stdcall<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">LoadManagedRuntime(<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _In_ PCWSTR pwszRuntimeVersion,<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span class=\"es-code\">__deref_out<\/span><span style=\"font-family: consolas;font-size: 9.5pt\"> IUnknown ** ppManagedRuntimeHost)<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">{<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp;&nbsp;&nbsp; <span style=\"color: blue\">return<\/span> LoadRuntimeInternal(pwszRuntimeVersion, ppManagedRuntimeHost);<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">}<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">HRESULT <span style=\"color: blue\">__stdcall<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">LoadManagedRuntimeEx(<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _In_ PCWSTR pwszRuntimeVersion,<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _In_ PCWSTR pszClrConfigFile,<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span class=\"es-code\">__deref_out<\/span><span style=\"font-family: consolas;font-size: 9.5pt\"> IUnknown ** ppManagedRuntimeHost)<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">{<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp;&nbsp;&nbsp; <span style=\"color: blue\">return<\/span> LoadRuntimeInternal(pwszRuntimeVersion, ppManagedRuntimeHost, pszClrConfigFile);<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">}<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">HRESULT LoadRuntimeInternal(_In_ PCWSTR pwszRuntimeVersion, __deref_out IUnknown** ppHost <span style=\"color: green\">\/*= NULL*\/<\/span>, _In_ PCWSTR pwszAspNetHostConfig <span style=\"color: green\">\/*= NULL*\/<\/span>) {<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp;&nbsp;&nbsp; HMODULE hModule = NULL;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp;&nbsp;&nbsp; HRESULT hr = S_OK;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp;&nbsp;&nbsp; IUnknown *pHost = NULL;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp;&nbsp;&nbsp; PFNCorBindToRuntimeHost pCorBindToRuntimeHost;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp;&nbsp;&nbsp; TCHAR szPath[MAX_PATH + 1];<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp;&nbsp;&nbsp; TCHAR szAspConfig[MAX_PATH + 1];<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp;&nbsp;&nbsp; ExpandEnvironmentStrings(L<span style=\"color: #a31515\">&#8220;%windir%\\system32\\mscoree.dll&#8221;<\/span>, szPath, MAX_PATH);<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp;&nbsp;&nbsp; <span style=\"color: blue\">if<\/span>(pwszAspNetHostConfig == NULL) {<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ExpandEnvironmentStrings(ASPNET_CONFIG, szAspConfig, MAX_PATH);<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pwszAspNetHostConfig = szAspConfig;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp;&nbsp;&nbsp; hModule = LoadLibrary(szPath);<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp;&nbsp;&nbsp; ON_NULL_EXIT(hModule);<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp;&nbsp;&nbsp; pCorBindToRuntimeHost = (PFNCorBindToRuntimeHost)GetProcAddress(hModule, <span style=\"color: #a31515\">&#8220;CorBindToRuntimeHost&#8221;<\/span>);<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp;&nbsp;&nbsp; ON_NULL_EXIT(pCorBindToRuntimeHost);<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp;&nbsp;&nbsp; hr = pCorBindToRuntimeHost(<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; L<span style=\"color: #a31515\">&#8220;v4.0.30319&#8221;<\/span>,<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; L<span style=\"color: #a31515\">&#8220;svr&#8221;<\/span>,<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pwszAspNetHostConfig,<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NULL, <span style=\"color: green\">\/\/ reserved<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; STARTUP_CONCURRENT_GC|STARTUP_LOADER_OPTIMIZATION_MULTI_DOMAIN_HOST|STARTUP_LOADER_SAFEMODE|STARTUP_DISABLE_COMMITTHREADSTACK|STARTUP_HOARD_GC_VM,<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CLSID_CLRRuntimeHost,<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IID_IUnknown,<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (VOID**)&amp;pHost);<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">Cleanup:<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp;&nbsp;&nbsp; <span style=\"color: blue\">if<\/span> (pHost != NULL &amp;&amp; ppHost != NULL) {<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pHost-&gt;AddRef();<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *ppHost = pHost;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp;&nbsp;&nbsp; <span style=\"color: blue\">if<\/span>(hModule != NULL) {<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FreeLibrary(hModule);<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp;&nbsp;&nbsp; }<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp;&nbsp;&nbsp; <span style=\"color: blue\">return<\/span> hr;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">}<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp;<\/span><\/p>\n<p>See the attached project for the full sample code. The sample can be compiled into a native DLL and the managedRuntimeLoader attribute can be set to point to that DLL.<\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp; &#8230;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"color: blue;font-family: consolas;font-size: 9.5pt\">&lt;<\/span><span style=\"color: #a31515;font-family: consolas;font-size: 9.5pt\">system.applicationHost<\/span><span style=\"color: blue;font-family: consolas;font-size: 9.5pt\">&gt;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp; &#8230;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"color: blue;font-family: consolas;font-size: 9.5pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;<\/span><span style=\"color: #a31515;font-family: consolas;font-size: 9.5pt\">applicationPools<\/span><span style=\"color: blue;font-family: consolas;font-size: 9.5pt\">&gt;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"color: blue;font-family: consolas;font-size: 9.5pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;!&#8211;<\/span><span style=\"color: green;font-family: consolas;font-size: 9.5pt\"> Set the CLRConfigFile and managedRuntimeLoader <\/span><span style=\"color: blue;font-family: consolas;font-size: 9.5pt\">&#8211;&gt;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"color: blue;font-family: consolas;font-size: 9.5pt\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;<\/span><span style=\"color: #a31515;font-family: consolas;font-size: 9.5pt\">add<\/span><span style=\"color: red;font-family: consolas;font-size: 9.5pt\">name<\/span><span style=\"color: blue;font-family: consolas;font-size: 9.5pt\">=<\/span><span style=\"font-family: consolas;font-size: 9.5pt\">&#8220;<span style=\"color: blue\">MyAppPool<\/span>&#8220;<span style=\"color: red\">CLRConfigFile<\/span><span style=\"color: blue\">=<\/span>&#8220;<span style=\"color: blue\">c:myconfigsmyapp1aspnet.config<\/span>&#8220;<span style=\"color: red\">managedRuntimeLoader<\/span><span style=\"color: blue\">=<\/span>&#8220;<span style=\"color: blue\">c:mynativedllsmyruntimeloader.dll<\/span>&#8220;<span style=\"color: blue\"> \/&gt;<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp; &#8230;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\"><span style=\"font-family: consolas;font-size: 9.5pt\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"text-align: left;line-height: normal;margin-bottom: 0pt\" align=\"left\">Note that debugging such a code on IIS will require the use of <a href=\"http:\/\/blogs.msdn.com\/b\/junfeng\/archive\/2004\/04\/28\/121871.aspx\">&ldquo;Image File Execution Options&rdquo;<\/a>, since the code is executed very early on the worker process lifecycle. An easier way to test might be to load the library yourself and call the functions, the way IIS would (see the test project).<\/p>\n<h2><span style=\"font-variant: normal !important\">Conclusion<\/span><\/h2>\n<p class=\"MsoNormal\">IIS 7.5 required for you to clean the managedRuntimeLoader attribute, if you wanted to change CLR parameters on your own CLRConfigFile.<\/p>\n<p class=\"MsoNormal\">Implementation of a managed runtime loader requires a native DLL which exports a <span style=\"line-height: 115%;font-family: consolas;font-size: 9.5pt\">LoadManagedRuntime() and\/or LoadManagedRuntimeEx().<\/span><\/p>\n<p class=\"MsoNormal\">Thanks for reading.<\/p>\n<p>Originally posted at <a href=\"http:\/\/blogs.msdn.com\/b\/josere\/\">http:\/\/blogs.msdn.com\/b\/josere\/<\/a><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Editor note: This blog is originally published by Jose Reyes &#8211; ASP.NET on 02-29-2012 in Web Performance Blog, which will be obsolete soon.&nbsp; Future ASP.NET related performance blogs will be posted here. Introduction There is a file called aspnet.config in the .Net framework installation. This file is used to specify startup flags for both ASP.NET [&hellip;]<\/p>\n","protected":false},"author":410,"featured_media":58792,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[197],"tags":[31,108],"class_list":["post-984","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-aspnet","tag-asp-net","tag-performance"],"acf":[],"blog_post_summary":"<p>Editor note: This blog is originally published by Jose Reyes &#8211; ASP.NET on 02-29-2012 in Web Performance Blog, which will be obsolete soon.&nbsp; Future ASP.NET related performance blogs will be posted here. Introduction There is a file called aspnet.config in the .Net framework installation. This file is used to specify startup flags for both ASP.NET [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/984","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/users\/410"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/comments?post=984"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/984\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media\/58792"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media?parent=984"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/categories?post=984"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/tags?post=984"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}