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

Regression in the 4.0.x version for the .Net Framework 4.x, for Value objects without STJ serialization #597

Closed
dmitriyse opened this issue May 17, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@dmitriyse
Copy link

Describe the bug

The code generation is broken for the .Net472 target in the Vogen 4.0.4 package.
See the steps to reproduce.

Steps to reproduce

Program.cs

// See https://aka.ms/new-console-template for more information

using Vogen;

// Vogen    | Net472          | Net8.0       |
// ---------------------------------------
// 4.0.4    | Compile Error   | Ok           |
// 3.0.24   | Ok              | Ok           |
[ValueObject(conversions:Conversions.None)]
public partial class MyValueObj
{

}

ConsoleApp.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net472</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <LangVersion>12</LangVersion>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Vogen" Version="4.0.4" />
  </ItemGroup>

</Project>

Build Error:

ConsoleApp\obj\Debug\net472\Vogen\Vogen.ValueObjectGenerator\SystemTextJsonConverterFactory_g.cs(27,54,27,58): error CS0234: The type or namespace name 'Json' does not exist in the namespace 'System.Text' (are you missing an assembly 

Expected behaviour

Version 4.0.x continues to work as 3.0.x for .Net472

@dmitriyse dmitriyse added the bug Something isn't working label May 17, 2024
@SteveDunn
Copy link
Owner

Thanks for the bug report @dmitriyse ! Apologies, this is due to a new feature in 4.0 that generates a 'factory' of System.Text.Json converters. The purpose of which is to tell STJ at compile time what converters there are. This is used in STJ source generation.

By default, this is set to generate the converter factory. This wouldn't cause problems on .NET core (> 5.0) apps, as the package and types are included by default.

The generator now checks to see if STJ is included and doesn't generate anything if it isn't included.

This will be available in the next release.

Thank again for the bug report!

@SteveDunn
Copy link
Owner

Fixed in 4.0.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants