SteveSandersonMS / dotnet-wasi-sdk

Packages for building .NET projects as standalone WASI-compliant modules
518 stars 36 forks source link

Unable to use swagger open api #47

Open VenkateshSrini opened 2 years ago

VenkateshSrini commented 2 years ago

@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.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.

$(String[] args)

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

Could you please help?

relcodedev commented 1 year ago

I am getting the same error.

VenkateshSrini commented 1 year ago

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

SteveSandersonMS commented 1 year ago

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.

relcodedev commented 1 year ago

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.

SteveSandersonMS commented 1 year ago

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.

relcodedev commented 1 year ago

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