I am trying to generate a CSharp client for my asp.net core Web Api project. I added the "PublishWithAspNetCoreTargetManifest>false" to the csproj, which didnt work and then I compiled self contained via CLI. When generating output I get the following exception however:
Could not load type 'System.Runtime.CompilerServices.TaskAwaiter`1' from assembly 'System.Runtime, Version=4.0.0.0, Culture...
Server stack trace:
at System.Reflection.CustomAttribute._CreateCaObject(RuntimeModule pModule, IRuntimeMethodInfo pCtor, Byte* ppBlob, Byte pEndBlob, Int32* pcNamedArgs)
at System.Reflection.CustomAttribute.CreateCaObject(RuntimeModule module, IRuntimeMethodInfo ctor, IntPtr& blob, IntPtr blobEnd, Int32& namedArgs)
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent)
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeMethodInfo method, RuntimeType caType, Boolean inherit)
at System.Attribute.GetCustomAttributes(MemberInfo element, Boolean inherit)
at NSwag.SwaggerGeneration.WebApi.WebApiToSwaggerGenerator.<>c.
at System.Linq.Enumerable.<>c__DisplayClass6_01.<CombinePredicates>b__0(TSource x)
at System.Linq.Enumerable.WhereArrayIterator1.MoveNext()
at NSwag.SwaggerGeneration.WebApi.WebApiToSwaggerGenerator.
Whats up here?
Can you provide a reproduction sample project?
When I try to add the assembly that fails to load into the ".NET Assembly Paths" as described in the troubleshooting, I get the following error:
Could not load file or assembly or one of its dependencies. Strong name signature could not be verified. The assembly may have been tampered with ...
Tried with: C:\Users\
EDIT: It goes away when selecting the .dll from the .net core installation. The original error still occurs then.
Here is the sample project: https://www.file-upload.net/download-12696327/BlobApiTest.zip.html
With NSwag.NPM it works when using the .NET Core binaries:
nswag run nswag.json /runtime:core2.0
With this config in the project directory:
But this is not a solution - I'd like this to work also with a full .NET process...
Ok, I will try that. Can I generate the client with code instead of the GUI? Will it also crash?
Do you know what the issue is?
I know that it worked with a blank solution. After I added some packages and logic, I started getting errors.
The problem is that NSwagStudio always generates in the same process in a seperate AppDomain (full .NET) with the command line (NSwag.NPM) you also have binaries for .NET Core and you can generate in a .NET Core process, which works...
The question is whether it makes sense to search for solutions to generate .NET Core assemblies in a full .NET process/AppDomain or if we should just refactor NSwagStudio so that it internally uses the one of the runtime specific command line exes (full .net, core...)
With these settings:

You can use the UI to configure, save the "nswag.json" file and run the command line .NET core binary against it:
nswag run nswag.json /runtime:core2.0
this works.
But id like a solution which works out of the box - in all scenarios :). But with all these different frameworks it might be a bit tricky...
Btw: With these settings I can now load the controller names (see screenshots) but generation gives mit this error:
'Could not load type 'System.Object' from assembly 'System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' because the parent does not exist.'
same as https://github.com/RSuter/NSwag/issues/918
but only if I remove the NSwag.Annotations binding redirect:

In v11.7 the annotations redirect is removed, you can use studio to create the nswag.json file and run it via cmd line and the core binaries.
I hope to find a solution for this so that it also works in a full .net process.
Implementation: https://github.com/RSuter/NSwag/issues/953
Please test the new feature with the CI build:
https://github.com/RSuter/NSwag/issues/953#issuecomment-330751737
Please discuss this in the new issue: https://github.com/RSuter/NSwag/issues/953
v11.8 has been released, please test your projects with it:

The wiki has been updated: https://github.com/RSuter/NSwag/wiki/Assembly-loading