Skip to content

ApiCompat errors when building System.Runtime inside Visual Studio #68699

Closed
dotnet/arcade
#9254

Description

@ViktorHofer
2>------ Build started: Project: System.Runtime (src\System.Runtime), Configuration: Debug Any CPU ------
2>C:\Users\vihofer\.nuget\packages\microsoft.dotnet.apicompat\7.0.0-beta.22179.1\build\Microsoft.DotNet.ApiCompat.targets(94,5): error : Compat issues with assembly System.Runtime:
2>C:\Users\vihofer\.nuget\packages\microsoft.dotnet.apicompat\7.0.0-beta.22179.1\build\Microsoft.DotNet.ApiCompat.targets(94,5): error : CannotRemoveAttribute : Attribute 'Microsoft.Cci.DummyTypeReference' exists on 'System.Lazy<T>' in the implementation but not the reference.
2>C:\Users\vihofer\.nuget\packages\microsoft.dotnet.apicompat\7.0.0-beta.22179.1\build\Microsoft.DotNet.ApiCompat.targets(94,5): error : CannotRemoveAttribute : Attribute 'Microsoft.Cci.DummyTypeReference' exists on 'System.Memory<T>' in the implementation but not the reference.
2>C:\Users\vihofer\.nuget\packages\microsoft.dotnet.apicompat\7.0.0-beta.22179.1\build\Microsoft.DotNet.ApiCompat.targets(94,5): error : CannotRemoveAttribute : Attribute 'Microsoft.Cci.DummyTypeReference' exists on 'System.ReadOnlyMemory<T>' in the implementation but not the reference.
2>C:\Users\vihofer\.nuget\packages\microsoft.dotnet.apicompat\7.0.0-beta.22179.1\build\Microsoft.DotNet.ApiCompat.targets(94,5): error : CannotRemoveAttribute : Attribute 'Microsoft.Cci.DummyTypeReference' exists on 'System.ReadOnlySpan<T>' in the implementation but not the reference.
2>C:\Users\vihofer\.nuget\packages\microsoft.dotnet.apicompat\7.0.0-beta.22179.1\build\Microsoft.DotNet.ApiCompat.targets(94,5): error : CannotRemoveAttribute : Attribute 'Microsoft.Cci.DummyTypeReference' exists on 'System.Span<T>' in the implementation but not the reference.
2>C:\Users\vihofer\.nuget\packages\microsoft.dotnet.apicompat\7.0.0-beta.22179.1\build\Microsoft.DotNet.ApiCompat.targets(94,5): error : CannotRemoveAttribute : Attribute 'Microsoft.Cci.DummyTypeReference' exists on 'System.CodeDom.Compiler.IndentedTextWriter.OutputTabsAsync()' in the implementation but not the reference.
2>C:\Users\vihofer\.nuget\packages\microsoft.dotnet.apicompat\7.0.0-beta.22179.1\build\Microsoft.DotNet.ApiCompat.targets(94,5): error : CannotRemoveAttribute : Attribute 'Microsoft.Cci.DummyTypeReference' exists on 'System.CodeDom.Compiler.IndentedTextWriter.WriteAsync(System.Char)' in the implementation but not the reference.
2>C:\Users\vihofer\.nuget\packages\microsoft.dotnet.apicompat\7.0.0-beta.22179.1\build\Microsoft.DotNet.ApiCompat.targets(94,5): error : CannotRemoveAttribute : Attribute 'Microsoft.Cci.DummyTypeReference' exists on 'System.CodeDom.Compiler.IndentedTextWriter.WriteAsync(System.Char[], System.Int32, System.Int32)' in the implementation but not the reference.
2>C:\Users\vihofer\.nuget\packages\microsoft.dotnet.apicompat\7.0.0-beta.22179.1\build\Microsoft.DotNet.ApiCompat.targets(94,5): error : CannotRemoveAttribute : Attribute 'Microsoft.Cci.DummyTypeReference' exists on 'System.CodeDom.Compiler.IndentedTextWriter.WriteAsync(System.ReadOnlyMemory<System.Char>, System.Threading.CancellationToken)' in the implementation but not the reference.
2>C:\Users\vihofer\.nuget\packages\microsoft.dotnet.apicompat\7.0.0-beta.22179.1\build\Microsoft.DotNet.ApiCompat.targets(94,5): error : CannotRemoveAttribute : Attribute 'Microsoft.Cci.DummyTypeReference' exists on 'System.CodeDom.Compiler.IndentedTextWriter.WriteAsync(System.String)' in the implementation but not the reference.
2>C:\Users\vihofer\.nuget\packages\microsoft.dotnet.apicompat\7.0.0-beta.22179.1\build\Microsoft.DotNet.ApiCompat.targets(94,5): error : CannotRemoveAttribute : Attribute 'Microsoft.Cci.DummyTypeReference' exists on 'System.CodeDom.Compiler.IndentedTextWriter.WriteAsync(System.Text.StringBuilder, System.Threading.CancellationToken)' in the implementation but not the reference.
2>C:\Users\vihofer\.nuget\packages\microsoft.dotnet.apicompat\7.0.0-beta.22179.1\build\Microsoft.DotNet.ApiCompat.targets(94,5): error : CannotRemoveAttribute : Attribute 'Microsoft.Cci.DummyTypeReference' exists on 'System.CodeDom.Compiler.IndentedTextWriter.WriteLineAsync()' in the implementation but not the reference.
2>C:\Users\vihofer\.nuget\packages\microsoft.dotnet.apicompat\7.0.0-beta.22179.1\build\Microsoft.DotNet.ApiCompat.targets(94,5): error : CannotRemoveAttribute : Attribute 'Microsoft.Cci.DummyTypeReference' exists on 'System.CodeDom.Compiler.IndentedTextWriter.WriteLineAsync(System.Char)' in the implementation but not the reference.
2>C:\Users\vihofer\.nuget\packages\microsoft.dotnet.apicompat\7.0.0-beta.22179.1\build\Microsoft.DotNet.ApiCompat.targets(94,5): error : CannotRemoveAttribute : Attribute 'Microsoft.Cci.DummyTypeReference' exists on 'System.CodeDom.Compiler.IndentedTextWriter.WriteLineAsync(System.Char[], System.Int32, System.Int32)' in the implementation but not the reference.
2>C:\Users\vihofer\.nuget\packages\microsoft.dotnet.apicompat\7.0.0-beta.22179.1\build\Microsoft.DotNet.ApiCompat.targets(94,5): error : CannotRemoveAttribute : Attribute 'Microsoft.Cci.DummyTypeReference' exists on 'System.CodeDom.Compiler.IndentedTextWriter.WriteLineAsync(System.ReadOnlyMemory<System.Char>, System.Threading.CancellationToken)' in the implementation but not the reference.
2>C:\Users\vihofer\.nuget\packages\microsoft.dotnet.apicompat\7.0.0-beta.22179.1\build\Microsoft.DotNet.ApiCompat.targets(94,5): error : CannotRemoveAttribute : Attribute 'Microsoft.Cci.DummyTypeReference' exists on 'System.CodeDom.Compiler.IndentedTextWriter.WriteLineAsync(System.String)' in the implementation but not the reference.
2>C:\Users\vihofer\.nuget\packages\microsoft.dotnet.apicompat\7.0.0-beta.22179.1\build\Microsoft.DotNet.ApiCompat.targets(94,5): error : CannotRemoveAttribute : Attribute 'Microsoft.Cci.DummyTypeReference' exists on 'System.CodeDom.Compiler.IndentedTextWriter.WriteLineAsync(System.Text.StringBuilder, System.Threading.CancellationToken)' in the implementation but not the reference.
2>C:\Users\vihofer\.nuget\packages\microsoft.dotnet.apicompat\7.0.0-beta.22179.1\build\Microsoft.DotNet.ApiCompat.targets(94,5): error : CannotRemoveAttribute : Attribute 'Microsoft.Cci.DummyTypeReference' exists on 'System.Collections.ArrayList' in the implementation but not the reference.
2>C:\Users\vihofer\.nuget\packages\microsoft.dotnet.apicompat\7.0.0-beta.22179.1\build\Microsoft.DotNet.ApiCompat.targets(94,5): error : CannotRemoveAttribute : Attribute 'Microsoft.Cci.DummyTypeReference' exists on 'System.Collections.Hashtable' in the implementation but not the reference.
2>C:\Users\vihofer\.nuget\packages\microsoft.dotnet.apicompat\7.0.0-beta.22179.1\build\Microsoft.DotNet.ApiCompat.targets(94,5): error : CannotRemoveAttribute : Attribute 'Microsoft.Cci.DummyTypeReference' exists on 'System.Collections.ObjectModel.Collection<T>' in the implementation but not the reference.
2>C:\Users\vihofer\.nuget\packages\microsoft.dotnet.apicompat\7.0.0-beta.22179.1\build\Microsoft.DotNet.ApiCompat.targets(94,5): error : CannotRemoveAttribute : Attribute 'Microsoft.Cci.DummyTypeReference' exists on 'System.Collections.ObjectModel.ReadOnlyCollection<T>' in the implementation but not the reference.
2>C:\Users\vihofer\.nuget\packages\microsoft.dotnet.apicompat\7.0.0-beta.22179.1\build\Microsoft.DotNet.ApiCompat.targets(94,5): error : CannotRemoveAttribute : Attribute 'Microsoft.Cci.DummyTypeReference' exists on 'System.Collections.ObjectModel.ReadOnlyDictionary<TKey, TValue>' in the implementation but not the reference.
2>C:\Users\vihofer\.nuget\packages\microsoft.dotnet.apicompat\7.0.0-beta.22179.1\build\Microsoft.DotNet.ApiCompat.targets(94,5): error : CannotRemoveAttribute : Attribute 'Microsoft.Cci.DummyTypeReference' exists on 'System.Collections.ObjectModel.ReadOnlyDictionary<TKey, TValue>.KeyCollection' in the implementation but not the reference.
2>C:\Users\vihofer\.nuget\packages\microsoft.dotnet.apicompat\7.0.0-beta.22179.1\build\Microsoft.DotNet.ApiCompat.targets(94,5): error : CannotRemoveAttribute : Attribute 'Microsoft.Cci.DummyTypeReference' exists on 'System.Collections.ObjectModel.ReadOnlyDictionary<TKey, TValue>.ValueCollection' in the implementation but not the reference.
2>C:\Users\vihofer\.nuget\packages\microsoft.dotnet.apicompat\7.0.0-beta.22179.1\build\Microsoft.DotNet.ApiCompat.targets(94,5): error : CannotRemoveAttribute : Attribute 'Microsoft.Cci.DummyTypeReference' exists on 'System.IO.BufferedStream.DisposeAsync()' in the implementation but not the reference.
2>C:\Users\vihofer\.nuget\packages\microsoft.dotnet.apicompat\7.0.0-beta.22179.1\build\Microsoft.DotNet.ApiCompat.targets(94,5): error : CannotRemoveAttribute : Attribute 'Microsoft.Cci.DummyTypeReference' exists on 'System.IO.FileStream.DisposeAsync()' in the implementation but not the reference.
2>C:\Users\vihofer\.nuget\packages\microsoft.dotnet.apicompat\7.0.0-beta.22179.1\build\Microsoft.DotNet.ApiCompat.targets(94,5): error : CannotRemoveAttribute : Attribute 'Microsoft.Cci.DummyTypeReference' exists on 'System.IO.TextReader.ReadToEndAsync(System.Threading.CancellationToken)' in the implementation but not the reference.
2>C:\Users\vihofer\.nuget\packages\microsoft.dotnet.apicompat\7.0.0-beta.22179.1\build\Microsoft.DotNet.ApiCompat.targets(94,5): error : CannotRemoveAttribute : Attribute 'Microsoft.Cci.DummyTypeReference' exists on 'System.Reflection.TypeInfo.DeclaredNestedTypes.get()' in the implementation but not the reference.
2>C:\Users\vihofer\.nuget\packages\microsoft.dotnet.apicompat\7.0.0-beta.22179.1\build\Microsoft.DotNet.ApiCompat.targets(94,5): error : CannotRemoveAttribute : Attribute 'Microsoft.Cci.DummyTypeReference' exists on 'System.Reflection.TypeInfo.GetDeclaredMethods(System.String)' in the implementation but not the reference.
2>C:\Users\vihofer\.nuget\packages\microsoft.dotnet.apicompat\7.0.0-beta.22179.1\build\Microsoft.DotNet.ApiCompat.targets(94,5): error : CannotRemoveAttribute : Attribute 'Microsoft.Cci.DummyTypeReference' exists on 'System.Threading.Timer' in the implementation but not the reference.
2>C:\Users\vihofer\.nuget\packages\microsoft.dotnet.apicompat\7.0.0-beta.22179.1\build\Microsoft.DotNet.ApiCompat.targets(94,5): error : CannotRemoveAttribute : Attribute 'Microsoft.Cci.DummyTypeReference' exists on 'System.Threading.Tasks.ConcurrentExclusiveSchedulerPair' in the implementation but not the reference.
2>C:\Users\vihofer\.nuget\packages\microsoft.dotnet.apicompat\7.0.0-beta.22179.1\build\Microsoft.DotNet.ApiCompat.targets(94,5): error : CannotRemoveAttribute : Attribute 'Microsoft.Cci.DummyTypeReference' exists on 'System.Threading.Tasks.Task' in the implementation but not the reference.
2>C:\Users\vihofer\.nuget\packages\microsoft.dotnet.apicompat\7.0.0-beta.22179.1\build\Microsoft.DotNet.ApiCompat.targets(94,5): error : CannotRemoveAttribute : Attribute 'Microsoft.Cci.DummyTypeReference' exists on 'System.Threading.Tasks.Task<TResult>' in the implementation but not the reference.
2>C:\Users\vihofer\.nuget\packages\microsoft.dotnet.apicompat\7.0.0-beta.22179.1\build\Microsoft.DotNet.ApiCompat.targets(94,5): error : CannotRemoveAttribute : Attribute 'Microsoft.Cci.DummyTypeReference' exists on 'System.Threading.Tasks.TaskAsyncEnumerableExtensions.ToBlockingEnumerable<T>(System.Collections.Generic.IAsyncEnumerable<T>, System.Threading.CancellationToken)' in the implementation but not the reference.
2>C:\Users\vihofer\.nuget\packages\microsoft.dotnet.apicompat\7.0.0-beta.22179.1\build\Microsoft.DotNet.ApiCompat.targets(94,5): error : CannotRemoveAttribute : Attribute 'Microsoft.Cci.DummyTypeReference' exists on 'System.Threading.Tasks.TaskScheduler' in the implementation but not the reference.
2>C:\Users\vihofer\.nuget\packages\microsoft.dotnet.apicompat\7.0.0-beta.22179.1\build\Microsoft.DotNet.ApiCompat.targets(94,5): error : CannotRemoveAttribute : Attribute 'Microsoft.Cci.DummyTypeReference' exists on 'System.Threading.Tasks.ValueTask' in the implementation but not the reference.
2>C:\Users\vihofer\.nuget\packages\microsoft.dotnet.apicompat\7.0.0-beta.22179.1\build\Microsoft.DotNet.ApiCompat.targets(94,5): error : CannotRemoveAttribute : Attribute 'Microsoft.Cci.DummyTypeReference' exists on 'System.Threading.Tasks.ValueTask<TResult>' in the implementation but not the reference.
2>System.Runtime -> C:\git\runtime5\artifacts\bin\System.Runtime\Debug\net7.0\System.Runtime.dll
2>Done building project "System.Runtime.csproj".
========== Build: 2 succeeded, 0 failed, 4 up-to-date, 0 skipped ==========

Repro:

.\build.cmd libs
.\build.cmd -vs System.Runtime
Build the source project of System.Runtime
Build the source project of System.Runtime again after applying a comment change

If a binlog is required, make sure to set the env vars described in https://github.com/dotnet/project-system-tools/blob/main/README.md#getting-higher-fidelity-logs-from-vs-vs2022-onwards to get more diagnostics.

Apparently these errors also don't fail the build of System.Runtime, which is yet another bug.

@ericstj can you please take a look?

Activity

  1. added this to the 7.0.0 milestone on Apr 29, 2022
  2. ghost added
    untriaged
    on Apr 29, 2022
  3. ericstj commented on Apr 29, 2022

    @ericstj
    Member

    Apparently these errors also don't fail the build of System.Runtime, which is yet another bug.

    It looks like the ExitCode may have always returned 0 but the non-zero exit code came from Exec which returned -1 when the command logged errors:
    https://github.com/dotnet/msbuild/blob/10dbde3bf1986251a5e958af8c7391ad0d9e7f11/src/Utilities/ToolTask.cs#L761-L765
    So we lost that when moving to ApiCompatTask. Probably we just need to do something similar before returning here: https://github.com/dotnet/arcade/blob/2a91e85b18e375ccb015f52ca3fe01e07601998e/src/Microsoft.DotNet.ApiCompat/src/ApiCompatTask.cs#L210

    An observation: the first build is building System.Private.Corelib and not System.Runtime which seems unusual to me. So the first build never has a chance to run APICompat which is why it passes.

    I can reproduce the same behavior you see in the IDE by running from the command-line using MSBuild.

    C:\src\dotnet\runtime\src\libraries\System.Runtime\src>msbuild /p:BuildProjectReferences=false System.Runtime.csproj /bl
    

    Likely this didn't happen before because API compat was run out of proc. I can run the desktop version of API compat from the commandline in its current form and also reproduce the issue:

    \Users\ericstj\.nuget\packages\microsoft.dotnet.apicompat\7.0.0-beta.22179.1\tools\net472\Microsoft.DotNet.ApiCompat.exe C:\src\dotnet\runtime\artifacts\obj\System.Runtime\Debug\net7.0\System.Runtime.dll -i C:\src\dotnet\runtime\artifacts\bin\System.Runtime\ref\Debug\net7.0\,C:\src\dotnet\runtime\artifacts\bin\coreclr\windows.x64.Debug\IL\,C:\src\dotnet\runtime\artifacts\bin\System.Private.Uri\Debug\net7.0\,C:\src\dotnet\runtime\artifacts\bin\microsoft.netcore.app.ref\ref\net7.0\ --contract-depends C:\src\dotnet\runtime\artifacts\bin\coreclr\windows.x64.Debug\IL\,C:\src\dotnet\runtime\artifacts\bin\System.Private.Uri\Debug\net7.0\ --enforce-optional-rules -l implementation -r reference --exclude-attributes C:\src\dotnet\runtime\eng\DefaultGenApiDocIds.txt,C:\src\dotnet\runtime\eng\ApiCompatExcludeAttributes.txt -b MatchingRefApiCompatBaseline.txt
    

    Of course we never did that before because we'd always run the .NETCore version out of proc (even in VS).

    CCI needs to know the core-assembly in order to resolve types and you'll see these Microsoft.Cci.DummyTypeReference types when it gets it wrong. So probably the resolution of the System.Runtime implementation facade never worked well on .NETFramework. One of CCI's quirks is that it falls back to using the executing core assembly if it can't find one.
    https://github.com/microsoft/cci/blob/659f31f9736a1e8ded870ee2132d91f87505148e/CoreObjectModel/MetadataHelper/Core.cs#L189-L197
    That explains why it fails on .NETFramework but works on .NETCore.

  4. ericstj commented on Apr 30, 2022

    @ericstj
    Member

    Just got a bit more time and debugged this and confirm that it chooses mscorlib for the core assembly:

      Name Value Type
    ▶ CoreAssemblySymbolicIdentity {Assembly(Name=mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)} Microsoft.Cci.AssemblyIdentity

    There's some logic in CCI.Extensions that tries to find the core assembly by looking for typerefs to common types. https://github.com/microsoft/cci/blob/659f31f9736a1e8ded870ee2132d91f87505148e/PEReaderAndWriter/PEReader/PEFileToObjectModel.cs#L225-L344
    The problem is that this fails for System.Runtime facade since it only references 18 types (mostly attributes) and none of those are in that list. Had that probed the ExportedTypeTable (where TypeForwards are defined) it would have found them.
    After that it looks for type defs for object (fails since we forward it) and then it looks for references to System.Runtime or mscorlib (both fail of course).

    We have a parameter called --contract-core-assembly which was added here https://mseng.visualstudio.com/Tools/_git/CoreFxTools/commit/a6ac67be62dd772841bb29459f41b93f781276dc?path=/Src/Microsoft.Cci.Extensions/HostEnvironment.cs&_a=contents
    That doesn't quite solve this case, as it assumes that the core-assembly is part of the set of contracts, which is not the case here for System.Runtime's implementation - the core assembly should be System.Private.Corelib and that assembly should not be part of the contract set (since it won't exist in references). We could build upon that hack to allow it to load a core-assembly from the probing paths but then we'd have to specify that in the project.

    The best fix here would be to change CCI to consider the ExportedTypeTable but that's not likely to happen since we can't change CCI. I think we might be able to implement that in CCI extensions but I'll need to see.

  5. ericstj commented on May 2, 2022

    @ericstj
    Member

    I have a fix for this and the issue that prevents the build from failing. Will test and put up a PR in arcade.

  6. ViktorHofer commented on May 2, 2022

    @ViktorHofer
    MemberAuthor

    Thanks Eric for your investigation and help.

  7. added and removed
    untriaged
    on May 2, 2022
  8. ghost locked as resolved and limited conversation to collaborators on Jun 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions