Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NSwag.Commands net6.0 cannot find System.Text.Encodings.Web 8.0.0 #4933

Open
jnyrup opened this issue Jul 9, 2024 · 0 comments
Open

NSwag.Commands net6.0 cannot find System.Text.Encodings.Web 8.0.0 #4933

jnyrup opened this issue Jul 9, 2024 · 0 comments

Comments

@jnyrup
Copy link

jnyrup commented Jul 9, 2024

I tried upgrading NSwag.Commands from 14.0.7 to 14.0.8 for a project running .net6 which then failed with the following exception:

Could not load file or assembly 'System.Text.Encodings.Web, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.

and this stack trace.

at NJsonSchema.CodeGeneration.DefaultTemplateFactory.LiquidParser..ctor()
at NJsonSchema.CodeGeneration.DefaultTemplateFactory.LiquidTemplate..cctor()

Minimal reproducible example

using NSwag.Commands.CodeGeneration;

var command = new OpenApiToCSharpClientCommand
{
    Input = "https://petstore.swagger.io/v2/swagger.json",
};

await command.RunAsync();
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
  </PropertyGroup>
	
  <ItemGroup>
    <PackageReference Include="NSwag.Commands" Version="14.0.8" />
  </ItemGroup>
</Project>

This is also reproducible by changing the TFM of NSwag.CodeGeneration.Tests from net8 to net6.

I traced this via #4913 back to sebastienros/fluid#639 which upgrade Fluid.Core from System.Text.Json 5.0.2 to 8.0.3 for the netstandard2.0 targets.

So the previously referenced Fluid.Core@2.5.0 references System.Text.Json@5.0.2, whereas the now referenced Fluid.Core@2.9.0 references System.Text.Json@8.0.3.

When looking in the generated project.assets.json for the example project above, for to me unknown reasons, it looks like it references Fluid.Core@net6, so it somehow isn't instructed to bump System.Text.Json to 8.0.3 :suspect:
I guess this is the underlying reason why NSwag.Commands doesn't "just work" for .net6.0.

Possible workarounds on my side:

  • Upgrade to .net8
  • Add <PackageReference Include="System.Text.Json" Version="8.0.3" />

Possible workaround in NSwag.CodeGeneration.csproj

  • Add <PackageReference Include="System.Text.Json" Version="8.0.3" Condition="'$(TargetFramework)'=='netstandard2.0'" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant