Skip to content

Could not load type 'System.Diagnostics.DebuggerHiddenAttribute' #31869

@adamsitnik

Description

@adamsitnik

There must have been some kind of a regression introduced in the last few days which broke the https://github.com/aspnet/Benchmarks/ and I can't run TechEmpower benchmarks anymore ;(

PS C:\repro> .\bin\Release\netcoreapp5.0\win-x64\publish\repro.exe
NetCoreApp location: C:\repro\bin\Release\netcoreapp5.0\win-x64\publish\System.Private.CoreLib.dll
CoreCLR version: 5.0.0-alpha.1.20078.2+b8942c37f25460bb160d0ff2fde9795d56b9bf01
CoreFx version: 5.0.0-alpha.1.20078.2+b8942c37f25460bb160d0ff2fde9795d56b9bf01
Unhandled exception. System.TypeLoadException: Could not load type 'System.Diagnostics.DebuggerHiddenAttribute' from assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
   at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
   at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
   at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(MetadataToken caCtorToken, MetadataImport& scope, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, ListBuilder`1& derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctorWithParameters, Boolean& isVarArg)
   at System.Reflection.CustomAttribute.IsCustomAttributeDefined(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, RuntimeType attributeFilterType, Int32 attributeCtorToken, Boolean mustBeInheritable)
   at System.Reflection.CustomAttribute.IsDefined(RuntimeMethodInfo method, RuntimeType caType, Boolean inherit)
   at System.Reflection.RuntimeMethodInfo.IsDefined(Type attributeType, Boolean inherit)
   at Newtonsoft.Json.Serialization.DefaultContractResolver.IsValidCallback(MethodInfo method, ParameterInfo[] parameters, Type attributeType, MethodInfo currentCallback, Type& prevAttributeType)
   at Newtonsoft.Json.Serialization.DefaultContractResolver.GetCallbackMethodsForType(Type type, List`1& onSerializing, List`1& onSerialized, List`1& onDeserializing, List`1& onDeserialized, List`1& onError)
   at Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveCallbackMethods(JsonContract contract, Type t)
   at Newtonsoft.Json.Serialization.DefaultContractResolver.InitializeContract(JsonContract contract)
   at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateObjectContract(Type objectType)
   at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract(Type objectType)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at Newtonsoft.Json.Utilities.ThreadSafeStore`2.Get(TKey key)
   at Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveContract(Type type)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.GetContractSafe(Object value)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)
   at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)
   at Newtonsoft.Json.JsonSerializer.Serialize(JsonWriter jsonWriter, Object value, Type objectType)
   at Newtonsoft.Json.JsonConvert.SerializeObjectInternal(Object value, Type type, JsonSerializer jsonSerializer)
   at Newtonsoft.Json.JsonConvert.SerializeObject(Object value, Type type, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.SerializeObject(Object value)
   at repro.Program.Main(String[] args) in C:\repro\Program.cs:line 16

Repro:

  1. Download latest .NET Core 5.0 SDK

  2. Create a console app:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="dotnet-core" value="https://dotnetfeed.blob.core.windows.net/dotnet-core/index.json" />
    <add key="dotnet-windowsdesktop" value="https://dotnetfeed.blob.core.windows.net/dotnet-windowsdesktop/index.json" />
    <add key="aspnet-aspnetcore" value="https://dotnetfeed.blob.core.windows.net/aspnet-aspnetcore/index.json" />
    <add key="aspnet-aspnetcore-tooling" value="https://dotnetfeed.blob.core.windows.net/aspnet-aspnetcore-tooling/index.json" />
    <add key="aspnet-entityframeworkcore" value="https://dotnetfeed.blob.core.windows.net/aspnet-entityframeworkcore/index.json" />
    <add key="aspnet-extensions" value="https://dotnetfeed.blob.core.windows.net/aspnet-extensions/index.json" />
    <add key="gRPC repository" value="https://grpc.jfrog.io/grpc/api/nuget/v3/grpc-nuget-dev" />
  </packageSources>
</configuration>
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp5.0</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <FrameworkReference Update="Microsoft.AspNetCore.App" RuntimeFrameworkVersion="5.0.0-preview.1.20105.1" />   
    <FrameworkReference Update="Microsoft.NETCore.App" RuntimeFrameworkVersion="5.0.0-alpha.1.20078.2" />
    <PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
    <PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.2.7" />
  </ItemGroup>
</Project>
using Microsoft.AspNetCore.Hosting;
using System;
using System.Reflection;
using System.Text.RegularExpressions;

namespace repro
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine($"NetCoreApp location: {typeof(object).Assembly.Location}");
            Console.WriteLine($"CoreCLR version: {typeof(object).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion}");
            Console.WriteLine($"CoreFx version: {typeof(Regex).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion}");

            Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(new
            {
                Metadata = new object[]
                {
                    new { Source= "Benchmarks", Name= "AspNetCoreVersion", ShortDescription = "ASP.NET Core Version", LongDescription = "ASP.NET Core Version" },
                    new { Source= "Benchmarks", Name= "CoreClrVersion", ShortDescription = "CoreCLR Version", LongDescription = "Core CLR Version" },
                    new { Source= "Benchmarks", Name= "CoreFxVersion", ShortDescription = "CoreFX Version", LongDescription = "Core FX Version" },
                    new { Source= "Benchmarks", Name= "ProcessorCount", ShortDescription = "Processor Count", LongDescription = "Processor Count", Format = "n0" },
                },
                Measurements = new object[]
                {
                    new { Timestamp = DateTime.UtcNow, Name = "AspNetCoreVersion", Value = typeof(WebHostBuilder).GetTypeInfo().Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion },
                    new { Timestamp = DateTime.UtcNow, Name = "CoreClrVersion", Value = typeof(object).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion },
                    new { Timestamp = DateTime.UtcNow, Name = "CoreFxVersion", Value = typeof(Regex).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion },
                    new { Timestamp = DateTime.UtcNow, Name = "ProcessorCount", Value = Environment.ProcessorCount }
                }
            }));
        }
    }
}
  1. Publish a self contained app (dotnet run works fine) and try to run it:
$env:DOTNET_MULTILEVEL_LOOKUP='0'
$pathToDotnet.exe publish -c Release --self-contained -r win-x64
.\bin\Release\netcoreapp5.0\win-x64\publish\repro.exe

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions