dotnet / dotnet-wasi-sdk

An SDK for building .NET projects as standalone WASI-compliant modules
MIT License
279 stars 12 forks source link

runtime error with webapi project can't find Microsoft.AspNetCore.OpenApi #21

Open relcodedev opened 1 year ago

relcodedev commented 1 year ago

I created a new project with dotnet new webapi -o webapiapp. I know that the example only uses web project. Is webapi supported? The dll Micrsooft.AspNetCore.OpenApi.dll is in the output folder.

        var builder = WebApplication.CreateBuilder(args).UseWasiConnectionListener();

        // Add services to the container.

        builder.Services.AddControllers();
        // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
        builder.Services.AddEndpointsApiExplorer();
        builder.Services.AddSwaggerGen();
        builder.Services.AddApiVersioning();

        var app = builder.Build();

        // Configure the HTTP request pipeline.
        if (app.Environment.IsDevelopment())
        {
            app.UseSwagger();
            app.UseSwaggerUI();
        }

        app.UseHttpsRedirection();

        app.UseAuthorization();

        app.MapControllers();

        app.Run();

dotnet run gets error:

Unhandled Exception:
System.IO.FileNotFoundException: 
File name: 'Microsoft.AspNetCore.OpenApi'
   at System.Reflection.Assembly.Load(AssemblyName assemblyRef, StackCrawlMark& stackMark, AssemblyLoadContext assemblyLoadContext)
   at System.Reflection.Assembly.Load(String assemblyString)
   at Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartManager.<>c.<GetApplicationPartAssemblies>b__8_0(ApplicationPartAttribute name)
   at System.Linq.Enumerable.SelectArrayIterator`2[[Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartAttribute, Microsoft.AspNetCore.Mvc.Core, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Reflection.Assembly, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext()
   at System.Collections.Generic.EnumerableHelpers.ToArray[Assembly](IEnumerable`1 source, Int32& length)
   at System.Linq.Buffer`1[[System.Reflection.Assembly, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]..ctor(IEnumerable`1 source)
   at System.Linq.OrderedEnumerable`1.<GetEnumerator>d__4[[System.Reflection.Assembly, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext()
   at System.Linq.Enumerable.SelectManySingleSelectorIterator`2[[System.Reflection.Assembly, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Reflection.Assembly, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext()
   at System.Linq.Enumerable.ConcatIterator`1[[System.Reflection.Assembly, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext()
   at Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartManager.PopulateDefaultParts(String entryAssemblyName)
   at Microsoft.Extensions.DependencyInjection.MvcCoreServiceCollectionExtensions.GetApplicationPartManager(IServiceCollection services, IWebHostEnvironment environment)
   at Microsoft.Extensions.DependencyInjection.MvcCoreServiceCollectionExtensions.AddMvcCore(IServiceCollection services)
   at Microsoft.Extensions.DependencyInjection.MvcServiceCollectionExtensions.AddControllersCore(IServiceCollection services)
   at Microsoft.Extensions.DependencyInjection.MvcServiceCollectionExtensions.AddControllers(IServiceCollection services)
   at webapiapp.Program.Main(String[] args)