As far as I know, codes written in any .NET language can not be executed without CLR.
Please take this code
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllersWithViews();
using var app = builder.Build();
app.UseStaticFiles();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapDefaultControllerRoute();
});
app.Run();
}
The documentation says CreateBuilder adds an IServer instance by calling the UseIIS method to boot the CoreCLR and host the app inside of the IIS worker process (w3wp.exe or iisexpress.exe).
I can not understand a bit how the CLR can be started from the Main() method. Then Who is converting this Main() IL to machine code?
Or am I missing something?

Sachin SinghPosted Feb 17, 2022, 3:05 PM
So, what i think is
HTTP.sys----->IIS--->AspNetCoreModule---> aspnetcorev2_inprocess.dll ---->hostfxr--->find and
start CLR and call manged Main()---->CreateBuilder()---->UseIIS()----->It just tells the CLR to host the app inside w3wp.exe.
So, booting the CLR basically means hosting the app inside the w3wp process and not re-starting the CLR.
Please correct me, if I am not getting the point. for reference, details of UseIIS()
public static IWebHostBuilder UseIIS(this IWebHostBuilder hostBuilder)
{
if (hostBuilder == null)
{
throw new ArgumentNullException(nameof(hostBuilder));
}
// Check if in process();();(new IISServerSetupFilter(iisConfigData.pwzVirtualApplicationPath));(_ => new ServerIntegratedAuth()(
if (OperatingSystem.IsWindows() && NativeMethods.IsAspNetCoreModuleLoaded())
{
var iisConfigData = NativeMethods.HttpGetApplicationProperties();
// Trim trailing slash to be consistent with other servers
var contentRoot = iisConfigData.pwzFullApplicationPath.TrimEnd(Path.DirectorySeparatorChar);
hostBuilder.UseContentRoot(contentRoot);
return hostBuilder.ConfigureServices(
services =>
{
services.AddSingleton(new IISNativeApplication(new NativeSafeHandle(iisConfigData.pNativeApplication)));
services.AddSingleton
services.AddTransient
services.AddSingleton
services.AddAuthenticationCore();
services.AddSingleton
{
IsEnabled = iisConfigData.fWindowsAuthEnabled || iisConfigData.fBasicAuthEnabled,
AuthenticationScheme = IISServerDefaults.AuthenticationScheme
});
services.Configure
options =>
{
options.ServerAddresses = iisConfigData.pwzBindings.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
options.ForwardWindowsAuthentication = iisConfigData.fWindowsAuthEnabled || iisConfigData.fBasicAuthEnabled;
options.MaxRequestBodySize = iisConfigData.maxRequestBodySize;
options.IisMaxRequestSizeLimit = iisConfigData.maxRequestBodySize;
}
);
});
}
return hostBuilder;
}
}