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

Microsoft.XmlSerializer.Generator 2.0.0 - Could not load System.Runtime 4.2.1.0 #1390

Closed
EddieDemon opened this issue Aug 31, 2019 · 13 comments · Fixed by #40216
Closed

Microsoft.XmlSerializer.Generator 2.0.0 - Could not load System.Runtime 4.2.1.0 #1390

EddieDemon opened this issue Aug 31, 2019 · 13 comments · Fixed by #40216
Assignees
Milestone

Comments

@EddieDemon
Copy link

[EDIT] Investigation Completed.

Two additional issues have been identified from the investigation.
#597
#630

We will leave this issue open and update it as they get fixed.
See down below for a workaround.


Hi there!

I'm trying to generate an xml serialization assembly but I keep on stranding with the following:

SGEN : warning SGEN1: Could not load file or assembly 'System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL'.

I've seen several posts pointing to edit the configuration file of Visual Studio but that was no solution in my case.

I tried both version 1.0.0 and 2.0.0, neither of them work, however version 1.0.0 doesn't generate any specific log output. Both versions end their logging with similar lines;

Assembly '[path to project]\obj\Debug\netcoreapp2.2\library.dll' does not contain any types that can be serialized using XmlSerializer.
1>%USERPROFILE%.nuget\packages\microsoft.xmlserializer.generator\2.0.0\build\Microsoft.XmlSerializer.Generator.targets(16,5): warning : SGEN: Fail to generate the serializer for library.dll. Please follow the instructions at https://go.microsoft.com/fwlink/?linkid=858594 and try again.

Interestingly enough, though, is that I got no issue on another device. This proofs that it is a local issue. I'd still like to be able to use the generator on my main device, what am I missing that this does not work?

@jasantosw
Copy link

jasantosw commented Oct 28, 2019

Hello, I'm having the same SGEN1 warnings building a simple project in VS2019 16.3.1 that targets the netcoreapp2.1 framework and uses version 2.1.0 of the .NET Core Xml Serialization Generator:

1>------ Rebuild All started: Project: ConsoleApp2, Configuration: Debug Any CPU ------
1>ConsoleApp2 -> C:\Users\jasw\source\repos\ConsoleApp2\ConsoleApp2\bin\Debug\netcoreapp2.1\ConsoleApp2.dll
1>[Microsoft (R) .NET Core Xml Serialization Generation Utility, Version 2.1.0]
1>Copyright (C) Microsoft Corporation. All rights reserved.
1>SGEN : warning SGEN1: Could not load file or assembly 'System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL'.
1>SGEN : warning SGEN1: Could not load file or assembly 'System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL'.
1>Assembly '[path to project]\obj\Debug\netcoreapp2.1\ConsoleApp2.dll' does not contain any types that can be serialized using XmlSerializer.
1>%USERPROFILE%.nuget\packages\microsoft.xmlserializer.generator\2.1.0\build\Microsoft.XmlSerializer.Generator.targets(38,5): warning : SGEN: Failed to generate the serializer for ConsoleApp2.dll. Please follow the instructions at https://go.microsoft.com/fwlink/?linkid=858594 and try again.
1>Done building project "ConsoleApp2.csproj".
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

The project only has a Class1 class with two string properties and a Program class with a Main method that creates an XmlSerializer for Class1. The .csproj file is as follows:

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

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFrameworks>netcoreapp2.1</TargetFrameworks>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
    <IncludeSGenFilesOutputGroup>Off</IncludeSGenFilesOutputGroup>
    <SGenUseProxyTypes>False</SGenUseProxyTypes>
  </PropertyGroup>
  
  <ItemGroup>
    <PackageReference Include="Microsoft.XmlSerializer.Generator" Version="2.1.0" />
  </ItemGroup>

  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.XmlSerializer.Generator" Version="2.1.0" />
  </ItemGroup>

</Project>

Interestingly, going back to the version 1.0.0 of the package makes the SGEN1 warnings disappear, but it still reports that the assembly does not contain any types that can be serialized using XmlSerializer, and the XmlSerializers assembly is not created. And going back to the netcoreapp2.0 framework, version 1.0.0 of the .NET Core Xml Serialization Generator works ok.

Am I missing something? Is there something I can do to make it work?

Thank you for your help.

@balaji764612
Copy link

Hi,
I have been trying this for a week and it doesnt work the way it is specified in https://docs.microsoft.com/en-us/dotnet/core/additional-tools/xml-serializer-generator

I tried the same steps as in the link and still I see the error as described here.

Thanks for your help!

@StephenBonikowsky
Copy link
Member

Sorry for the delay in responding to this issue.

We are attempting to reproduce the issues you have described to see if we can get an idea of what might be causing the problems you are seeing.

@mconnew
Copy link
Member

mconnew commented Nov 26, 2019

I've tracked down the cause of the problem. The good news is there's a temporary workaround until we produce a fixed package. To work around it, you will need to modify the contents of the package. You will need to edit the file "%USERPROFILE%.nuget\packages\microsoft.xmlserializer.generator\2.1.0\lib\netstandard2.0\dotnet-Microsoft.XmlSerializer.Generator.runtimeconfig.json" to replace the tfm and version with the version of .NET Core that you are developing with. For example, if you are developing with .NET Core 2.1, your file would look like this:

{
  "runtimeOptions": {
    "tfm": "netcoreapp2.1",
    "framework": {
      "name": "Microsoft.NETCore.App",
      "version": "2.1.0"
    }
  }
}

If you aren't comfortable with using a modified version of the package, an alternative would be to separate out your data classes into a separate library project which targets netstandard2.0.

We will update this issue when we have published a fixed nuget package.

@balaji764612
Copy link

balaji764612 commented Nov 28, 2019 via email

@jasantosw
Copy link

Thank you Matt. I tried on a separate library project that targets netstandard2.1 and received the following error:

SGEN : warning SGEN1: Could not load file or assembly 'netstandard, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL'.

Do you have a temporary workaround for this case?

Thanks for your help.

@StephenBonikowsky
Copy link
Member

@jasantosw netstandard2.1 isn't supported by netcoreapp2.1. In the workaround that @mconnew provided, change it from netcoreapp2.1 to netcoreapp3.0.

See here for the support table:
https://docs.microsoft.com/en-us/dotnet/standard/net-standard

@StephenBonikowsky StephenBonikowsky transferred this issue from dotnet/corefx Jan 7, 2020
@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added the untriaged New issue has not been triaged by the area owner label Jan 7, 2020
@StephenBonikowsky StephenBonikowsky added this to the 3.1.x milestone Jan 7, 2020
@StephenBonikowsky StephenBonikowsky added area-Serialization and removed untriaged New issue has not been triaged by the area owner labels Jan 7, 2020
@maryamariyan maryamariyan added the untriaged New issue has not been triaged by the area owner label Feb 23, 2020
@galvesribeiro
Copy link
Member

galvesribeiro commented Mar 9, 2020

Hello folks! I'm getting the same problem here.

SGEN : warning SGEN1: Could not load file or assembly 'System.Runtime, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL'. [/Users/guto/dev/repos/XXXXX/YYYYY.csproj]
  Assembly '/Users/guto/dev/repos/XXXXX/obj/Debug/netcoreapp3.1/YYYYY.dll' does not contain any types that can be serialized using XmlSerializer.
/Users/guto/.nuget/packages/microsoft.xmlserializer.generator/2.2.0/build/Microsoft.XmlSerializer.Generator.targets(38,5): warning : SGEN: Failed to generate the serializer for YYYYY.dll. Please follow the instructions at https://go.microsoft.com/fwlink/?linkid=858594 and try again. 

Any idea when that would be fixed? I mean, the workaround works on my machine but it would be a pain to do that on a CI machine...

Thanks!

@NUnitTester
Copy link

Hi!

I think it's a really important problem. I have waste many time on it.

Please solve it soon.

Thanks!

@HongGit HongGit removed the untriaged New issue has not been triaged by the area owner label Jun 25, 2020
@gavnlh
Copy link

gavnlh commented Jul 22, 2020

I'm trying to connect to SQL Server Reporting Services to generate multiple PDF files (Invoices) without needing to display any UI - so just need the service connection to ReportExecution2005.asmx. I have code that works fine in a Net Framework WinForms project, but cannot get it to work with Net Core 3.1 in a WPF project.

I've tried to use the method suggested at https://docs.microsoft.com/en-us/dotnet/core/additional-tools/xml-serializer-generator , but these instructions cannot be followed verbatim in a Net Core 3.1 WPF project (are there any specific instructions for such?).

Despite trying ALL of the suggested solutions I can find, I cannot get to create an xmlserializers.dll at build (see Rebuild output lower down), and at runtime obviously get the exception below:

======== in 'reference.cs ' ===========
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
System.Threading.Tasks.Task<REService.LoadReportResponse> REService.ReportExecutionServiceSoap.LoadReportAsync(REService.LoadReportRequest request)
{
return base.Channel.LoadReportAsync(request); // THROWS EXCEPTION: System.IO.FileNotFoundException: 'Could not load file or assembly 'C:\Users??\source\repos????????\bin\Release\netcoreapp3.1????????.XmlSerializers.dll'.
}

2>------ Rebuild All started: Project: ????????, Configuration: Release Any CPU ------
2>???????? -> C:\Users??\source\repos????????\bin\Release\netcoreapp3.1????????.dll
2>[Microsoft (R) .NET Core Xml Serialization Generation Utility, Version 2.2.1]
2>Copyright (C) Microsoft Corporation. All rights reserved.
2>SGEN : warning SGEN1: Could not load file or assembly 'System.ServiceModel.Primitives, Version=4.7.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL'. Reference assemblies should not be loaded for execution. They can only be loaded in the Reflection-only loader context. (0x80131058)
2>SGEN : warning SGEN1: Cannot load a reference assembly for execution.
2>SGEN : warning SGEN1: Could not load file or assembly 'PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Reference assemblies should not be loaded for execution. They can only be loaded in the Reflection-only loader context. (0x80131058)
2>SGEN : warning SGEN1: Cannot load a reference assembly for execution.
2>SGEN : warning SGEN1: Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL'. Reference assemblies should not be loaded for execution. They can only be loaded in the Reflection-only loader context. (0x80131058)
2>SGEN : warning SGEN1: Cannot load a reference assembly for execution.
2>A BadImageFormatException has been thrown while parsing the signature. This is likely due to lack of a generic context. Ensure genericTypeArguments and genericMethodArguments are provided and contain enough context.
2>Could not load file or assembly 'System.ServiceModel.Primitives, Version=4.7.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Reference assemblies should not be loaded for execution. They can only be loaded in the Reflection-only loader context. (0x80131058)
2>Cannot load a reference assembly for execution.
2>C:\Users??.nuget\packages\microsoft.xmlserializer.generator\2.2.1\build\Microsoft.XmlSerializer.Generator.targets(37,5): warning MSB3073: The command "dotnet Microsoft.XmlSerializer.Generator "obj\Release\netcoreapp3.1????????.dll" --force --quiet obj\Release\netcoreapp3.1\sgen.rsp" exited with code 1.
2>C:\Users??.nuget\packages\microsoft.xmlserializer.generator\2.2.1\build\Microsoft.XmlSerializer.Generator.targets(38,5): warning : SGEN: Failed to generate the serializer for ????????.dll. Please follow the instructions at https://go.microsoft.com/fwlink/?linkid=858594 and try again.
2>Done building project "????????.csproj".
========== Rebuild All: 2 succeeded, 0 failed, 0 skipped ==========

========= Contents of 'ConnectedService.json' (and reference classes successfully generated when adding service connection to project) ===========
{
"ProviderId": "Microsoft.VisualStudio.ConnectedService.Wcf",
"Version": "15.0.40203.910",
"GettingStartedDocument": {
"Uri": "https://go.microsoft.com/fwlink/?linkid=858517"
},
"ExtendedData": {
"inputs": [
"http://??.??.??.??/ReportServer/ReportExecution2005.asmx"
],
"collectionTypes": [
"System.Array",
"System.Collections.Generic.Dictionary`2"
],
"namespaceMappings": [
"*, REService"
],
"references": [
"Microsoft.Bcl.AsyncInterfaces, {Microsoft.Bcl.AsyncInterfaces, 1.1.0}",
"Microsoft.Bcl.HashCode, {Microsoft.Bcl.HashCode, 1.1.0}",
"Microsoft.Data.SqlClient, {Microsoft.Data.SqlClient, 1.0.19269.1}",
"Microsoft.EntityFrameworkCore, {Microsoft.EntityFrameworkCore, 3.1.1}",
"Microsoft.EntityFrameworkCore.Abstractions, {Microsoft.EntityFrameworkCore.Abstractions, 3.1.1}",
"Microsoft.EntityFrameworkCore.Relational, {Microsoft.EntityFrameworkCore.Relational, 3.1.1}",
"Microsoft.EntityFrameworkCore.SqlServer, {Microsoft.EntityFrameworkCore.SqlServer, 3.1.1}",
"Microsoft.Extensions.Caching.Abstractions, {Microsoft.Extensions.Caching.Abstractions, 3.1.1}",
"Microsoft.Extensions.Caching.Memory, {Microsoft.Extensions.Caching.Memory, 3.1.1}",
"Microsoft.Extensions.Configuration, {Microsoft.Extensions.Configuration, 3.1.1}",
"Microsoft.Extensions.Configuration.Abstractions, {Microsoft.Extensions.Configuration.Abstractions, 3.1.1}",
"Microsoft.Extensions.Configuration.Binder, {Microsoft.Extensions.Configuration.Binder, 3.1.1}",
"Microsoft.Extensions.Configuration.FileExtensions, {Microsoft.Extensions.Configuration.FileExtensions, 3.1.1}",
"Microsoft.Extensions.Configuration.Json, {Microsoft.Extensions.Configuration.Json, 3.1.1}",
"Microsoft.Extensions.DependencyInjection, {Microsoft.Extensions.DependencyInjection, 3.1.1}",
"Microsoft.Extensions.DependencyInjection.Abstractions, {Microsoft.Extensions.DependencyInjection.Abstractions, 3.1.1}",
"Microsoft.Extensions.FileProviders.Abstractions, {Microsoft.Extensions.FileProviders.Abstractions, 3.1.1}",
"Microsoft.Extensions.FileProviders.Physical, {Microsoft.Extensions.FileProviders.Physical, 3.1.1}",
"Microsoft.Extensions.FileSystemGlobbing, {Microsoft.Extensions.FileSystemGlobbing, 3.1.1}",
"Microsoft.Extensions.Logging, {Microsoft.Extensions.Logging, 3.1.1}",
"Microsoft.Extensions.Logging.Abstractions, {Microsoft.Extensions.Logging.Abstractions, 3.1.1}",
"Microsoft.Extensions.Options, {Microsoft.Extensions.Options, 3.1.1}",
"Microsoft.Extensions.Options.ConfigurationExtensions, {Microsoft.Extensions.Options.ConfigurationExtensions, 3.1.1}",
"Microsoft.Extensions.Primitives, {Microsoft.Extensions.Primitives, 3.1.1}",
"Newtonsoft.Json, {Newtonsoft.Json, 12.0.3}",
"System.Collections.Immutable, {System.Collections.Immutable, 1.7.0}",
"System.ComponentModel.Annotations, {System.ComponentModel.Annotations, 4.7.0}",
"System.Diagnostics.DiagnosticSource, {System.Diagnostics.DiagnosticSource, 4.7.0}"
],
"targetFramework": "netcoreapp3.1",
"typeReuseMode": "All"
}
}

@ericstj
Copy link
Member

ericstj commented Jul 31, 2020

@gavnlh you have a different error. SGEN1: Cannot load a reference assembly for execution.

I believe that's also been reported here: #40010

@gavnlh
Copy link

gavnlh commented Aug 6, 2020

@ericstj I've no problem trying to use SQL Reporting Services with NET Framework. All issues are with NET Core 3.1 and simply trying to use SQL Reporting Services and/or a ReportViewer in a WPF project under NET Core. There seem to be many issues with NET Core which mean that SQL Reporting Services cannot be used at present - seems a gaping hole in MS strategy.

@ericstj
Copy link
Member

ericstj commented Aug 6, 2020

@gavnlh I’m not suggesting your issue is resolved. I believe the issue you are reporting is the same as #40010. Please engage with the owners of the XlmSerializer.Generator in that issue.

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

Successfully merging a pull request may close this issue.