8000 does “dotnet script” (csx) support ASP.NET Core app development? · Issue #602 · dotnet-script/dotnet-script · GitHub
[go: up one dir, main page]

Skip to content
does “dotnet script” (csx) support ASP.NET Core app development? #602
Closed
@jagchat

Description

@jagchat

I am able to get basic examples working fine. However, I am trying to check the possibility of ASP.NET Core using "dotnet script" (just using plain csx).

main.csx:

#r "netcoreapp3.1\Microsoft.AspNetCore.dll" 
#r "netcoreapp3.1\Microsoft.AspNetCore.Hosting.dll" 
#r "netcoreapp3.1\Microsoft.Extensions.DependencyInjection.dll" 
#r "netcoreapp3.1\Microsoft.Extensions.Hosting.dll"
#load "Startup.csx"

using System;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

public static IHostBuilder CreateHostBuilder(string[] args) =>
    Host.CreateDefaultBuilder(args)
        .ConfigureWebHostDefaults(webBuilder =>
        {
            webBuilder.UseStartup<Startup>();
        });

CreateHostBuilder(null).Build().Run();

Startup.csx:

#r "netcoreapp3.1\Microsoft.AspNetCore.Diagnostics.dll" 
#r "netcoreapp3.1\Microsoft.AspNetCore.Hosting.dll" 
#r "netcoreapp3.1\Microsoft.AspNetCore.Http.dll" 
#r "netcoreapp3.1\Microsoft.Extensions.DependencyInjection.dll" 
#r "netcoreapp3.1\Microsoft.Extensions.Hosting.dll" 

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
    }

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }

        app.UseRouting();

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapGet("/", async context =>
            {
                await context.Response.WriteAsync("Hello World!");
            });
        });
    }
}

And I experience the following error:

System.BadImageFormatException: Could not load file or assembly 'Microsoft.Extensions.Hosting, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. Reference assemblies should not be loaded for execution.  They can only be loaded in the Reflection-only loader context. (0x80131058)
File name: 'Microsoft.Extensions.Hosting, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' ---> System.BadImageFormatException: Could not load file or assembly 'Microsoft.Extensions.Hosting, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL'. Reference assemblies should not be loaded for execution.  They can only be loaded in the Reflection-only loader context. (0x80131058)
File name: 'Microsoft.Extensions.Hosting, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL' ---> System.BadImageFormatException: Cannot load a reference assembly for execution.
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromPath(IntPtr ptrNativeAssemblyLoadContext, String ilPath, String niPath, ObjectHandleOnStack retAssembly)
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath)
   at System.Reflection.Assembly.LoadFrom(String assemblyFile)
   at System.Reflection.Assembly.LoadFromResolveHandler(Object sender, ResolveEventArgs args)
   at System.Runtime.Loader.AssemblyLoadContext.InvokeResolveEvent(ResolveEventHandler eventHandler, RuntimeAssembly assembly, String name)
   at System.Runtime.Loader.AssemblyLoadContext.OnAssemblyResolve(RuntimeAssembly assembly, String assemblyFullName)
   at Submission#0.CreateHostBuilder(String[] args)
   at Submission#0.<<Initialize>>d__0.MoveNext() in C:\temp\sample01\main.csx:line 51
--- End of stack trace from previous location ---
   at Dotnet.Script.Core.ScriptRunner.Execute[TReturn](String dllPath, IEnumerable`1 commandLineArgs) in /private/var/folders/6j/4hkjjhd50fg27s933nctz0480000gn/T/tmp3iI6tV/Dotnet.Script.Core/ScriptRunner.cs:line 52

What am I doing irrelevant?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0