RicoSuter / NSwag

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

Upgrade <code>14.0.3.0</code> "NetCore21" to type 'NSwag.Commands.Runtime' Requested value 'NetCore21' was not found. #4783

Open OzBob opened 7 months ago

OzBob commented 7 months ago

Upgraded to v14 from v13 now opening a .nswag file like:

{
  "runtime": "NetCore21",
  "defaultVariables": null,
  "documentGenerator": {
    "fromDocument": {
      "json": "{\r\n  \"openapi\": \"3.0.1\",\r\n  \"info\": {\r\n    \"title\": \"i6\",\r\n    \"description\": \"Insolvency API to support Company 

get the following error:

Newtonsoft.Json.JsonSerializationException: Error converting value "NetCore21" to type 'NSwag.Commands.Runtime'. Path 'runtime', line 2, position 24. ---> System.ArgumentException: Requested value 'NetCore21' was not found.
   at Newtonsoft.Json.Utilities.EnumUtils.ParseEnum(Type enumType, NamingStrategy namingStrategy, String value, Boolean disallowNumber)
   at Newtonsoft.Json.Converters.StringEnumConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
   --- End of inner exception stack trace ---
   at Newtonsoft.Json.Converters.StringEnumConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Object existingValue)
   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.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)
   at NSwag.Commands.NSwagDocumentBase.LoadDocument[TDocument](String filePath, String data)
   at NSwag.Commands.NSwagDocumentBase.<LoadAsync>d__35`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at NSwagStudio.ViewModels.MainWindowModel.<>c__DisplayClass38_0.<<OpenDocumentAsync>b__0>d.MoveNext() in /_/src/NSwagStudio/ViewModels/MainWindowModel.cs:line 160
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MyToolkit.Mvvm.ViewModelBase.<>c__DisplayClass14_0.<<RunTaskAsync>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at MyToolkit.Mvvm.ViewModelBase.<RunTaskAsync>d__12`1.MoveNext()

when run dotnet --list-runtimes get

Microsoft.AspNetCore.App 8.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.19 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

when run dotnet --list-sdks get

2.1.202 [C:\Program Files\dotnet\sdk]
2.1.526 [C:\Program Files\dotnet\sdk]
2.1.818 [C:\Program Files\dotnet\sdk]
2.2.106 [C:\Program Files\dotnet\sdk]

I'll change the definition manually to Net60, but FYI - there maybe regression tests for you to run.

Numpsy commented 7 months ago

I think support for .NET Core 2.1 was removed in v14?

OzBob commented 7 months ago

Thanks for the update. As there will be more sdk versions slowly go out of support as the years crawl by, do you think it would be a good feature to trap this specific error and report it in a more friendly way or even auto update the .nswag file?

Numpsy commented 7 months ago

It sounds like something where it'd be nicer if NSwagStudio would either read the old runtime and then tell you it's obsolete or default to the current version for unknown values, but I don't know what ramifications that might have for the command line tools.

ericanderson73 commented 2 months ago

Is there anyway to stop NswagStudio from upgrading from a version 13.x? We cannot get off of .Net Core 2.1 atm, and every day after uninstalling 14.x and reinstalling 13.x, NswagStudio has auto updated itself to 14.x again.

lahma commented 2 months ago

Is there anyway to stop NswagStudio from upgrading from a version 13.x? We cannot get off of .Net Core 2.1 atm, and every day after uninstalling 14.x and reinstalling 13.x, NswagStudio has auto updated itself to 14.x again.

Sorry to add insult to the injury, but NSwagStudio automatic updates are probably least of your problems if you're still on NET 2.1 😉