dotnet-wasi-sdk icon indicating copy to clipboard operation
dotnet-wasi-sdk copied to clipboard

Unable to use swagger open api

Open VenkateshSrini opened this issue 2 years ago • 6 comments

@SteveSandersonMS , I tried to use basic minimal api as a wasm. I had enabled swagger. But unfortunately, it is failing with the below 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.SelectArrayIterator2[[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](IEnumerable1 source, Int32& length) at System.Linq.Buffer1[[System.Reflection.Assembly, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]..ctor(IEnumerable1 source) at System.Linq.OrderedEnumerable1.<GetEnumerator>d__4[[System.Reflection.Assembly, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].MoveNext() at System.Linq.Enumerable.SelectManySingleSelectorIterator2[[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 Program.<Main>$(String[] args)

The sample code is attached herewith. wasm.api.csproj.zip

Could you please help?

VenkateshSrini avatar Nov 13 '22 13:11 VenkateshSrini

I am getting the same error.

relcodedev avatar Jun 02 '23 17:06 relcodedev

@SteveSandersonMS Is there any suggestion that you can provide on this

VenkateshSrini avatar Jun 03 '23 02:06 VenkateshSrini

Perhaps that assembly is loaded dynamically instead of being a proper assembly reference. I'm not sure. One thing you could try is referencing it directly. If that doesn't work I'd recommend working with the owners of that package to make sense of what it's doing to load it that isn't just a normal assembly reference.

SteveSandersonMS avatar Jun 05 '23 08:06 SteveSandersonMS

Thanks. It is referenced directly. The project was created with dotnet new webapi --use-program-main. I made the changes to use wasi and this is the error I get. It does work if I use dotnet new web --use-program-main.

relcodedev avatar Jun 05 '23 12:06 relcodedev

Thanks for the extra info.

I'm unsure why it's not working, though suspect it's something specific to how MVC is trying to load that assembly via reflection (based on your stack trace).

Since we're now switching over to the WASI support in .NET 8 Preview 4 and later, I'd recommend for any further prototyping you attempt to use that (i.e., the new wasi-experimental workload). It may well fail in the same way but if so it would be possible to file a bug about it and then hopefully we will address it, whereas no further work is going to happen in this repo here.

SteveSandersonMS avatar Jun 05 '23 13:06 SteveSandersonMS

Got it. I will test with .net 8 preview latest. Thanks.

relcodedev avatar Jun 05 '23 13:06 relcodedev