You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After I have ported some class libraries to .NET Standard 2.0, I get the following error message when building a .NET Framework 4.8 project which references a .NET Standard 2.0 project: The type 'System.Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.
After some investigation I found out that the build only fails when GenerateSerializationAssemblies is set to On and SGenUseProxyTypes is set to false in the .NET Framework project. When I set SGenUseProxyTypes to true or remove it the build succeeds.
I hope this is the right place for this bug report.
To Reproduce
Create a new class library with .NET Framework 4.8 and rename the default class to NetFramework
Add the following two lines to the *.csproj file of the .NET 4.8 project (to the first PropertyGroup) <GenerateSerializationAssemblies>On</GenerateSerializationAssemblies> <SGenUseProxyTypes>false</SGenUseProxyTypes>
Create a new class library with .NET Standard 2.0 and rename the default class to NetStandard
In the .NET 4.8 Project add a reference to the .NET Standard 2.0 class library
Create a public property in the .NET 4.8 class library with the type NetStandard public NetStandard.NetStandard NetStandard { get; set; }
Build the solution in visual studio -> build fails
Attached you'll find a small repro with both projects.
Exceptions
CS0012 The type 'System.Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
Further technical details
dotnet --info:
.NET SDK (reflecting any global.json):
Version: 6.0.101
Commit: ef49f62
Runtime Environment:
OS Name: Windows
OS Version: 10.0.19042
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\6.0.101\
Host (useful for support):
Version: 6.0.1
Commit: 3a25a7f1cc
The error happens regardless of whether the project targeting .NET 4.8 is a legacy project or a .NET SDK project.
MSBuild runs C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\sgen.exe with a /reference option that includes C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\Facades\netstandard.dll, but sgen.exe then runs csc.exe with a series of /R options that does not include /R:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\Facades\netstandard.dll". If I run csc.exe directly, with the same command line plus that option, then it succeeds.
I think this would need a fix in sgen.exe, but is that even open source?
#10255 (comment) suggests using Microsoft.XmlSerializer.Generator instead of sgen.exe. If I remove the GenerateSerializationAssemblies MSBuild property, and add both a PackageReference and a DotNetCliToolReference as instructed in https://docs.microsoft.com/dotnet/core/additional-tools/xml-serializer-generator, then the build succeeds and the generated serializer does read the Class1.NetStandard property.
It's a bit surprising though; I thought DotNetCliToolReference was being deprecated (#3115) and replaced with tool manifests. dotnet/docs#26253 has been filed.
#10255 (comment) suggests using Microsoft.XmlSerializer.Generator instead of sgen.exe. If I remove the GenerateSerializationAssemblies MSBuild property, and add both a PackageReference and a DotNetCliToolReference as instructed in https://docs.microsoft.com/dotnet/core/additional-tools/xml-serializer-generator, then the build succeeds and the generated serializer does read the Class1.NetStandard property.
It's a bit surprising though; I thought DotNetCliToolReference was being deprecated (#3115) and replaced with tool manifests. dotnet/docs#26253 has been filed.
With the XML serializer generator it actually works.
It isn't the best solution because I have to update 20+ projects but if SGEN.exe won't be ported to .NET Core, it may be the only solution.
Describe the bug
After I have ported some class libraries to .NET Standard 2.0, I get the following error message when building a .NET Framework 4.8 project which references a .NET Standard 2.0 project:
The type 'System.Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.
After some investigation I found out that the build only fails when
GenerateSerializationAssemblies
is set toOn
andSGenUseProxyTypes
is set tofalse
in the .NET Framework project. When I setSGenUseProxyTypes
to true or remove it the build succeeds.I hope this is the right place for this bug report.
To Reproduce
NetFramework
<GenerateSerializationAssemblies>On</GenerateSerializationAssemblies>
<SGenUseProxyTypes>false</SGenUseProxyTypes>
NetStandard
NetStandard
public NetStandard.NetStandard NetStandard { get; set; }
Attached you'll find a small repro with both projects.
Exceptions
CS0012 The type 'System.Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
Further technical details
.NET SDK (reflecting any global.json):
Version: 6.0.101
Commit: ef49f62
Runtime Environment:
OS Name: Windows
OS Version: 10.0.19042
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\6.0.101\
Host (useful for support):
Version: 6.0.1
Commit: 3a25a7f1cc
DotNetStandard_SGenUseProxyTypes.zip
)
The text was updated successfully, but these errors were encountered: