问题描述
我正在查看此处提供的“dotnet 脚本”(csx):https://github.com/filipw/dotnet-script
我能够使基本示例正常工作。但是,我正在尝试使用“dotnet 脚本”(仅使用纯 csx)检查 ASP.NET Core 的可能性。
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!");
});
});
}
}
我遇到以下错误:
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,PublicKeyToken=adb9793829ddae60' ---> System.BadImageFormatException: Could not load file or assembly 'Microsoft.Extensions.Hosting,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,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
知道我做错了什么吗?
谢谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)