Skip to content

.NET Framework 4.8 build with SGen.exe fails when referencing a .NET Standard 2.0 project #78660

@MaaadMax

Description

@MaaadMax

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 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: ef49f6213a

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-NetSDKuntriagedIssues and PRs which have not yet been triaged by a lead

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions