After upgrading from dotnet 7 to dotnet 8, nswag typescript model generation fails on my mac.
The following packages are installed:
<PackageReference Include="NSwag.AspNetCore" Version="14.0.1" />
<PackageReference Include="NSwag.MSBuild" Version="14.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
nswag.json looks like this:
{
"runtime": "Net80",
"documentGenerator": {
"webApiToOpenApi": {
"isAspNetCore": true,
"defaultPropertyNameHandling": "CamelCase",
"defaultReferenceTypeNullHandling": "NotNull",
"defaultEnumHandling": "String",
"assemblyPaths": [
"bin/$(Configuration)/net8.0/MyProject.Web.Api.dll"
]
}
},
"codeGenerators": {
"openApiToTypeScriptClient": {
"typeScriptVersion": 4.8,
"dateTimeType": "Date",
"nullValue": "Undefined",
"generateClientClasses": false,
"exceptionClass": "SwaggerException",
"typeStyle": "Interface",
"output": "../../../frontend/src/types/contracts/nswag-contracts.d.ts"
}
}
}
The csproj contains this:
<Target Name="NSwag" AfterTargets="Build">
<Exec Command="$(NSwagExe_Net80) run nswag.json /variables:Configuration=$(Configuration)" />
</Target>
Compilation fails with the following error message:
Executing file 'nswag.json' with variables 'Configuration=Debug'...
Newtonsoft.Json.JsonSerializationException: Error setting value to 'SelectedSwaggerGeneratorRaw' on 'NSwag.Commands.NSwagDocument'.
---> System.NullReferenceException: Object reference not set to an instance of an object.
at NSwag.Commands.NSwagDocumentBase.set_SelectedSwaggerGeneratorRaw(JObject value) in /_/src/NSwag.Commands/NSwagDocumentBase.cs:line 88
at Newtonsoft.Json.Serialization.ExpressionValueProvider.SetValue(Object target, Object value)
--- End of inner exception stack trace ---
at Newtonsoft.Json.Serialization.ExpressionValueProvider.SetValue(Object target, Object value)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
at NSwag.Commands.NSwagDocumentBase.FromJson[TDocument](String filePath, String data) in /_/src/NSwag.Commands/NSwagDocumentBase.cs:line 222
at NSwag.Commands.NSwagDocumentBase.LoadDocument[TDocument](String filePath, String data) in /_/src/NSwag.Commands/NSwagDocumentBase.cs:line 209
at NSwag.Commands.NSwagDocumentBase.LoadAsync[TDocument](String filePath, String variables, Boolean applyTransformations) in /_/src/NSwag.Commands/NSwagDocumentBase.cs:line 203
at NSwag.Commands.Document.ExecuteDocumentCommand.ExecuteDocumentAsync(IConsoleHost host, String filePath) in /_/src/NSwag.Commands/Commands/Document/ExecuteDocumentCommand.cs:line 64
at NSwag.Commands.Document.ExecuteDocumentCommand.RunAsync(CommandLineProcessor processor, IConsoleHost host) in /_/src/NSwag.Commands/Commands/Document/ExecuteDocumentCommand.cs:line 33
at NConsole.CommandLineProcessor.ProcessSingleAsync(String[] args, Object input)
at NConsole.CommandLineProcessor.ProcessAsync(String[] args, Object input)
at NSwag.Commands.NSwagCommandProcessor.ProcessAsync(String[] args) in /_/src/NSwag.Commands/NSwagCommandProcessor.cs:line 62
1>MyProject.Web.Api.csproj(37,9): Error MSB3073 : The command "dotnet "/Users/frank/.nuget/packages/nswag.msbuild/14.0.1/buildTransitive/../tools/Net80/dotnet-nswag.dll" run nswag.json /variables:Configuration=Debug" exited with code 255.
1>------- Finished building project: MyProject.Web.Api. Succeeded: False. Errors: 1. Warnings: 0
What’s wrong here? I haven’t touched the config files except for bumping the dotnet version from 7 to 8.