Skip to content

Recommend latest version of Microsoft.XmlSerializer.Generator #24200

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

Open
KSchlobohm opened this issue May 12, 2021 · 1 comment
Open

Recommend latest version of Microsoft.XmlSerializer.Generator #24200

KSchlobohm opened this issue May 12, 2021 · 1 comment

Comments

@KSchlobohm
Copy link
Contributor

Update samples to use latest NuGet package reference and to include a notation that the latest version is always recommended.

Would also be helpful to include a subsection that describes how to use Xml Serializer Generator in projects that are multi-targeting net48 and net5.0 on projects that are in a hybrid state while migrating.

I believe this can be accomplished using a csproj similar to:

<PropertyGroup Condition=" '$(TargetFramework)' == 'net48'">
    <GenerateSerializationAssemblies>On</GenerateSerializationAssemblies>
    <SGenUseProxyTypes>false</SGenUseProxyTypes>
  </PropertyGroup>
  <PropertyGroup Condition="'$(TargetFramework)' != 'net48' ">
    <_XmlSerializerGeneratorVersion>5.0.0</_XmlSerializerGeneratorVersion>
  </PropertyGroup>
  <ItemGroup Condition="'$(TargetFramework)' != 'net48' ">
    <PackageReference Include="Microsoft.XmlSerializer.Generator" Version="$(_XmlSerializerGeneratorVersion)" />
    <DotNetCliToolReference Include="Microsoft.XmlSerializer.Generator" Version="$(_XmlSerializerGeneratorVersion)" />
  </ItemGroup>

Addressing the multi-target scenario could help to explain how to resolve build errors that look like the following:

17>------ Build started: Project: ExampleProject, Configuration: Release Any CPU ------
17>SGEN : error : An attempt was made to load an assembly with an incorrect format: C:\dev\.nuget\packages\system.memory\4.5.1\ref\netstandard2.0\System.Memory.dll.
17>Done building project "ExampleProject.csproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

@KalleOlaviNiemitalo
Copy link

The "An attempt was made to load an assembly with an incorrect format" error, caused by the .NET Framework SGEN trying to load a reference assembly, can also occur when targeting .NET Framework and referencing a NuGet package that includes a reference assembly. This has been discussed in dotnet/msbuild#2707, dotnet/wcf#3991, and dotnet/sdk#1630. I don't think the article should recommend adding conditions that check $(TargetFramework). Rather, it should recommend using the Microsoft.XmlSerializer.Generator package on all target frameworks.

#28844 added documentation for SGenReferences and other properties. However, the article currently recommends Microsoft.XmlSerializer.Generator 1.0.0, which ignores all of those properties. Microsoft.XmlSerializer.Generator 2.1.0-preview4.19212.13 is the first version that supports those properties. The article should be changed to recommend Microsoft.XmlSerializer.Generator 2.1.0 or a higher version, or to describe which versions support the properties.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants