RicoSuter / NSwag

The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
http://NSwag.org
MIT License
6.79k stars 1.29k forks source link

Could not load type 'System.IAsyncDisposable' from assembly #2917

Open paulterinho opened 4 years ago

paulterinho commented 4 years ago

Hi all,

I'm trying to run a MSBuild aspnetcore2openapi directive in a dotnetcore 3.1 app,and I'm getting the following error (any suggestions would be most welcomed):

Here's the project I'm running it from (sample todo app):

Here's the documentation I am referencing:

Here's my MSBuild directive:

`

    <Exec Command="$(NSwagExe) openapi2tsclient /input:swagger.json /output:Scripts/MyController.ts" />
</Target>`

Here's my nswag.json file contents:


{
  "runtime": "NetCore31",
  "defaultVariables": null,
  "documentGenerator": {
    "typesToOpenApi": {
      "classNames": [],
      "defaultPropertyNameHandling": "Default",
      "defaultReferenceTypeNullHandling": "Null",
      "defaultDictionaryValueReferenceTypeNullHandling": "NotNull",
      "defaultEnumHandling": "Integer",
      "flattenInheritanceHierarchy": false,
      "ignoreObsoleteProperties": false,
      "allowReferencesWithProperties": false,
      "generateKnownTypes": true,
      "generateXmlObjects": false,
      "output": null,
      "outputType": "Swagger2",
      "newLineBehavior": "Auto",
      "assemblyPaths": [
        "bin/Debug/netcoreapp3.1/TodoApi.dll"
      ],
      "assemblyConfig": null,
      "referencePaths": [],
      "useNuGetCache": false
    }
  },
  "codeGenerators": {
    "openApiToTypeScriptClient": {
      "className": "{controller}Client",
      "moduleName": "",
      "namespace": "",
      "typeScriptVersion": 2.7,
      "template": "Fetch",
      "promiseType": "Promise",
      "httpClass": "HttpClient",
      "withCredentials": false,
      "useSingletonProvider": false,
      "injectionTokenType": "OpaqueToken",
      "rxJsVersion": 6.0,
      "dateTimeType": "Date",
      "nullValue": "Undefined",
      "generateClientClasses": true,
      "generateClientInterfaces": false,
      "generateOptionalParameters": false,
      "exportTypes": true,
      "wrapDtoExceptions": false,
      "exceptionClass": "ApiException",
      "clientBaseClass": null,
      "wrapResponses": false,
      "wrapResponseMethods": [],
      "generateResponseClasses": true,
      "responseClass": "SwaggerResponse",
      "protectedMethods": [],
      "configurationClass": null,
      "useTransformOptionsMethod": false,
      "useTransformResultMethod": false,
      "generateDtoTypes": true,
      "operationGenerationMode": "MultipleClientsFromOperationId",
      "markOptionalProperties": true,
      "generateCloneMethod": false,
      "typeStyle": "Class",
      "enumStyle": "Enum",
      "useLeafType": false,
      "classTypes": [],
      "extendedClasses": [],
      "extensionCode": null,
      "generateDefaultValues": true,
      "excludedTypeNames": [],
      "excludedParameterNames": [],
      "handleReferences": false,
      "generateConstructorInterface": true,
      "convertConstructorInterfaceData": false,
      "importRequiredTypes": true,
      "useGetBaseUrlMethod": false,
      "baseUrlTokenName": "API_BASE_URL",
      "queryNullValue": "",
      "inlineNamedDictionaries": false,
      "inlineNamedAny": false,
      "templateDirectory": null,
      "typeNameGeneratorType": null,
      "propertyNameGeneratorType": null,
      "enumNameGeneratorType": null,
      "serviceHost": null,
      "serviceSchemes": null,
      "output": null,
      "newLineBehavior": "Auto"
    },
    "openApiToCSharpClient": {
      "clientBaseClass": null,
      "configurationClass": null,
      "generateClientClasses": true,
      "generateClientInterfaces": false,
      "clientBaseInterface": null,
      "injectHttpClient": true,
      "disposeHttpClient": true,
      "protectedMethods": [],
      "generateExceptionClasses": true,
      "exceptionClass": "ApiException",
      "wrapDtoExceptions": true,
      "useHttpClientCreationMethod": false,
      "httpClientType": "System.Net.Http.HttpClient",
      "useHttpRequestMessageCreationMethod": false,
      "useBaseUrl": true,
      "generateBaseUrlProperty": true,
      "generateSyncMethods": false,
      "exposeJsonSerializerSettings": false,
      "clientClassAccessModifier": "public",
      "typeAccessModifier": "public",
      "generateContractsOutput": false,
      "contractsNamespace": null,
      "contractsOutputFilePath": null,
      "parameterDateTimeFormat": "s",
      "parameterDateFormat": "yyyy-MM-dd",
      "generateUpdateJsonSerializerSettingsMethod": true,
      "useRequestAndResponseSerializationSettings": false,
      "serializeTypeInformation": false,
      "queryNullValue": "",
      "className": "{controller}Client",
      "operationGenerationMode": "MultipleClientsFromOperationId",
      "additionalNamespaceUsages": [],
      "additionalContractNamespaceUsages": [],
      "generateOptionalParameters": false,
      "generateJsonMethods": false,
      "enforceFlagEnums": false,
      "parameterArrayType": "System.Collections.Generic.IEnumerable",
      "parameterDictionaryType": "System.Collections.Generic.IDictionary",
      "responseArrayType": "System.Collections.Generic.ICollection",
      "responseDictionaryType": "System.Collections.Generic.IDictionary",
      "wrapResponses": false,
      "wrapResponseMethods": [],
      "generateResponseClasses": true,
      "responseClass": "SwaggerResponse",
      "namespace": "com.walterp.todo",
      "requiredPropertiesMustBeDefined": true,
      "dateType": "System.DateTimeOffset",
      "jsonConverters": null,
      "anyType": "object",
      "dateTimeType": "System.DateTimeOffset",
      "timeType": "System.TimeSpan",
      "timeSpanType": "System.TimeSpan",
      "arrayType": "System.Collections.Generic.ICollection",
      "arrayInstanceType": "System.Collections.ObjectModel.Collection",
      "dictionaryType": "System.Collections.Generic.IDictionary",
      "dictionaryInstanceType": "System.Collections.Generic.Dictionary",
      "arrayBaseType": "System.Collections.ObjectModel.Collection",
      "dictionaryBaseType": "System.Collections.Generic.Dictionary",
      "classStyle": "Poco",
      "generateDefaultValues": true,
      "generateDataAnnotations": true,
      "excludedTypeNames": [],
      "excludedParameterNames": [],
      "handleReferences": false,
      "generateImmutableArrayProperties": false,
      "generateImmutableDictionaryProperties": false,
      "jsonSerializerSettingsTransformationMethod": null,
      "inlineNamedArrays": false,
      "inlineNamedDictionaries": false,
      "inlineNamedTuples": true,
      "inlineNamedAny": false,
      "generateDtoTypes": true,
      "generateOptionalPropertiesAsNullable": false,
      "generateNullableReferenceTypes": false,
      "templateDirectory": null,
      "typeNameGeneratorType": null,
      "propertyNameGeneratorType": null,
      "enumNameGeneratorType": null,
      "serviceHost": null,
      "serviceSchemes": null,
      "output": null,
      "newLineBehavior": "Auto"
    },
    "openApiToCSharpController": {
      "controllerBaseClass": null,
      "controllerStyle": "Partial",
      "controllerTarget": "AspNetCore",
      "useCancellationToken": false,
      "useActionResultType": false,
      "generateModelValidationAttributes": false,
      "routeNamingStrategy": "None",
      "basePath": null,
      "className": "{controller}",
      "operationGenerationMode": "MultipleClientsFromOperationId",
      "additionalNamespaceUsages": [],
      "additionalContractNamespaceUsages": [],
      "generateOptionalParameters": false,
      "generateJsonMethods": false,
      "enforceFlagEnums": false,
      "parameterArrayType": "System.Collections.Generic.IEnumerable",
      "parameterDictionaryType": "System.Collections.Generic.IDictionary",
      "responseArrayType": "System.Collections.Generic.ICollection",
      "responseDictionaryType": "System.Collections.Generic.IDictionary",
      "wrapResponses": false,
      "wrapResponseMethods": [],
      "generateResponseClasses": true,
      "responseClass": "SwaggerResponse",
      "namespace": "com.walterp.todo",
      "requiredPropertiesMustBeDefined": true,
      "dateType": "System.DateTimeOffset",
      "jsonConverters": null,
      "anyType": "object",
      "dateTimeType": "System.DateTimeOffset",
      "timeType": "System.TimeSpan",
      "timeSpanType": "System.TimeSpan",
      "arrayType": "System.Collections.Generic.List",
      "arrayInstanceType": "System.Collections.Generic.List",
      "dictionaryType": "System.Collections.Generic.IDictionary",
      "dictionaryInstanceType": "System.Collections.Generic.Dictionary",
      "arrayBaseType": "System.Collections.ObjectModel.Collection",
      "dictionaryBaseType": "System.Collections.Generic.Dictionary",
      "classStyle": "Poco",
      "generateDefaultValues": true,
      "generateDataAnnotations": true,
      "excludedTypeNames": [],
      "excludedParameterNames": [],
      "handleReferences": false,
      "generateImmutableArrayProperties": false,
      "generateImmutableDictionaryProperties": false,
      "jsonSerializerSettingsTransformationMethod": null,
      "inlineNamedArrays": false,
      "inlineNamedDictionaries": false,
      "inlineNamedTuples": true,
      "inlineNamedAny": false,
      "generateDtoTypes": true,
      "generateOptionalPropertiesAsNullable": false,
      "generateNullableReferenceTypes": false,
      "templateDirectory": null,
      "typeNameGeneratorType": null,
      "propertyNameGeneratorType": null,
      "enumNameGeneratorType": null,
      "serviceHost": null,
      "serviceSchemes": null,
      "output": null,
      "newLineBehavior": "Auto"
    }
  }
}

Here's the whole stacktrace:

`

1>   at System.Reflection.RuntimeAssembly.GetExportedTypes(RuntimeAssembly assembly, ObjectHandleOnStack retTypes)
1>   at System.Reflection.RuntimeAssembly.GetExportedTypes()
1>   at NSwag.Commands.Generation.OpenApiGeneratorCommandBase`1.<CreateWebHostAsync>d__119.MoveNext()
1>--- End of stack trace from previous location where exception was thrown ---
1>   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
1>   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
1>   at NSwag.Commands.Generation.AspNetCore.AspNetCoreToSwaggerCommand.<RunIsolatedAsync>d__44.MoveNext()
1>--- End of stack trace from previous location where exception was thrown ---
1>   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
1>   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
1>   at NSwag.Commands.IsolatedCommandBase`1.IsolatedCommandAssemblyLoader`1.Run(String commandType, String commandData, String[] assemblyPaths, String[] referencePaths)
1>   at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs)
1>   at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg)
1>
1>Exception rethrown at [0]:
1>   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
1>   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
1>   at NSwag.Commands.IsolatedCommandBase`1.IsolatedCommandAssemblyLoader`1.Run(String commandType, String commandData, String[] assemblyPaths, String[] referencePaths)
1>   at NSwag.Commands.IsolatedCommandBase`1.<>c__DisplayClass17_0.<RunIsolatedAsync>b__0()
1>   at System.Threading.Tasks.Task`1.InnerInvoke()
1>   at System.Threading.Tasks.Task.Execute()
1>--- End of stack trace from previous location where exception was thrown ---
1>   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
1>   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
1>   at NSwag.Commands.IsolatedCommandBase`1.<RunIsolatedAsync>d__17.MoveNext()
1>--- End of stack trace from previous location where exception was thrown ---
1>   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
1>   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
1>   at NSwag.Commands.IsolatedSwaggerOutputCommandBase`1.<RunAsync>d__13.MoveNext()
1>--- End of stack trace from previous location where exception was thrown ---
1>   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
1>   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
1>   at NSwag.Commands.Generation.AspNetCore.AspNetCoreToSwaggerCommand.<RunAsync>d__39.MoveNext()
1>--- End of stack trace from previous location where exception was thrown ---
1>   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
1>   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
1>   at NConsole.CommandLineProcessor.<ProcessSingleAsync>d__12.MoveNext()
1>--- End of stack trace from previous location where exception was thrown ---
1>   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
1>   at NConsole.CommandLineProcessor.<ProcessAsync>d__11.MoveNext()
1>--- End of stack trace from previous location where exception was thrown ---
1>   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
1>   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
1>   at NConsole.CommandLineProcessor.Process(String[] args, Object input)
1>   at NSwag.Commands.NSwagCommandProcessor.Process(String[] args)
1>C:\Users\PaulWalter\Documents\dotnetopenapi\TodoApi\TodoApi.csproj(34,3): error MSB3073: The command ""C:\Users\PaulWalter\.nuget\packages\nswag.msbuild\13.6.1\build\../tools/Win/NSwag.exe" aspnetcore2openapi /assembly:C:\Users\PaulWalter\Documents\dotnetopenapi\TodoApi\bin\Debug\netcoreapp3.1\TodoApi.dll /output:swagger.json" exited with code -1.
1>Done building project "TodoApi.csproj" -- FAILED.
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

`

paulterinho commented 4 years ago

@RicoSuter I see you've suggested using NSwag Studio. That's working correctly. Going with that solution.

Just out of curiosity though, is the above way deprecated?

RicoSuter commented on Aug 24, 2017
Can you create a repro of the problem?

Btw: You should use a nswag.json file and just run "nswag.exe run nswag.json" - much simpler to manage the config.
paulterinho commented 4 years ago

P.S. thanks for making NSWag, I've used it a ton with my Java and JavaScript projects. Mad props.

RicoSuter commented 4 years ago

The recommended way is to use aspnetcore2openapi but with an nswag.json file and the .csproj project reference setting... this should work up to core 3.1