dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
14.98k stars 4.66k forks source link

Error: [MONO] * Assertion at /__w/1/s/src/mono/mono/metadata/assembly.c:1673, condition `<disabled>' not met #107730

Open risto-slice opened 1 week ago

risto-slice commented 1 week ago

Is there an existing issue for this?

Describe the bug

I am getting an Exception when my code is trying to access HttpClient methods. For example, I have the following code:

public class HomeBase : PageBase
{
    [Inject]
    protected ITest Test { get; set; }

    protected override async Task OnInitializedAsync()
    {
        Console.WriteLine("We are here!");
        try
        {
            //    var httpClient = new HttpClient { BaseAddress = new Uri("https://jsonplaceholder.typicode.com/") };
            //    var response = await httpClient.GetAsync("todos");
            //    response.EnsureSuccessStatusCode();
            //    var content = await response.Content.ReadAsStringAsync();
            //    Console.WriteLine($"Response: {content}");
            Console.WriteLine("Before calling Test");
            var x = await Test.GetAsync();
            Console.WriteLine("After calling Test");
        }
        catch (Exception ex)
        {
            Console.WriteLine($"EXCEPTION: {ex.Message}");
        }
    }
}

I left out the commented code, because that one actually works. No exception is thrown when accessing it like that. My implementation for the service is the following:

    public class Test : ITest
    {
        private readonly HttpClient _httpClient;

        public Test(HttpClient httpClient)
        {
            _httpClient = httpClient;
        }

        public async Task<string> GetAsync()
        {
            var x = (await _httpClient.GetAsync("todos")).Content.ReadAsStringAsync();

            return "test;";
        }
    }

    public interface ITest
    {
        Task<string> GetAsync();
    }

And I register it like this:

builder.Services.AddHttpClient<ITest, Test>(x =>
{
    x.BaseAddress = new Uri("https://jsonplaceholder.typicode.com/");
});

Interestingly, I tried the exact same code in a brand new project, but it works there. For some reason it does not work here. It's somehow connected to HttpClient, because when I comment out this particular line in my service: var x = (await _httpClient.GetAsync("todos")).Content.ReadAsStringAsync(); everything works just fine.

The HttpClient injected is fine, the instance is not null, the base address is set correctly and I can't find anything wrong with it. But when I have code to call GetAsync, it does NOT enter the method at all, it throws the exception before it makes the call to the method somehow. Never enters it.

Expected Behavior

The application should work when I try to access GetAsync (or any other method on HttpClient) without throwing any exceptions.

Steps To Reproduce

This is a rather large project and I am not sure how to reproduce the error. I tried on a brand new project and I did not get the same problem. But I am hoping that I could get some ideas how to find the root issue here. I would post the project, but I am not allowed to because it's private and medium-level large (has ~25 pages). Ideally if possible I would like to get better errors that might get me closer to finding the root cause.

Exceptions (if any)

[MONO] /__w/1/s/src/mono/mono/metadata/custom-attrs.c:2001 <disabled>
Error: [MONO] * Assertion at /__w/1/s/src/mono/mono/metadata/assembly.c:1673, condition `<disabled>' not met

    at ht (https://localhost:7152/_framework/dotnet.runtime.8.0.8.606dk4lxzy.js:3:12765)
    at Ll (https://localhost:7152/_framework/dotnet.runtime.8.0.8.606dk4lxzy.js:3:176248)
    at wasm://wasm/00b21c96:wasm-function[119]:0xa308
    at wasm://wasm/00b21c96:wasm-function[634]:0x3f446
    at wasm://wasm/00b21c96:wasm-function[550]:0x3bd96
    at wasm://wasm/00b21c96:wasm-function[554]:0x3beb7
    at wasm://wasm/00b21c96:wasm-function[556]:0x3befa
    at wasm://wasm/00b21c96:wasm-function[555]:0x3becd
    at wasm://wasm/00b21c96:wasm-function[1080]:0x5bbc7
    at wasm://wasm/00b21c96:wasm-function[1235]:0x6333a
ExitStatus

Uncaught ExitStatus ExitStatus
    at completePendingCall (localhost꞉7152/_framework/blazor.webassembly.js:1:4936)
    at invokeDotNetMethodAsync (localhost꞉7152/_framework/blazor.webassembly.js:1:4005)
    at invokeMethodAsync (localhost꞉7152/_framework/blazor.webassembly.js:1:5464)
    at <anonymous> (localhost꞉7152/_framework/blazor.webassembly.js:1:13003)
    at N (localhost꞉7152/_framework/blazor.webassembly.js:1:13181)
    at <anonymous> (localhost꞉7152/_framework/blazor.webassembly.js:1:54756)
    at invokeWhenHeapUnlocked (localhost꞉7152/_framework/blazor.webassembly.js:1:46658)
    at <anonymous> (localhost꞉7152/_framework/blazor.webassembly.js:1:54719)
    at N (localhost꞉7152/_framework/blazor.webassembly.js:1:54746)
    at C (localhost꞉7152/_framework/blazor.webassembly.js:1:12972)
    at dispatchGlobalEventToAllElements (localhost꞉7152/_framework/blazor.webassembly.js:1:15574)
    at onGlobalEvent (localhost꞉7152/_framework/blazor.webassembly.js:1:14767)

.NET Version

8.0.400

Anything else?

.NET 8 (Blazor WebAssembly) Visual Studio 2022

dotnet --info: .NET SDK: Version: 8.0.400 Commit: 36fe6dda56 Workload version: 8.0.400-manifests.56cd0383 MSBuild version: 17.11.3+0c8610977

Runtime Environment: OS Name: Windows OS Version: 10.0.22631 OS Platform: Windows RID: win-x64 Base Path: C:\Program Files\dotnet\sdk\8.0.400\

.NET workloads installed: Configured to use loose manifests when installing new manifests. [aspire] Installation Source: VS 17.11.35208.52, VS 17.11.35208.52 Manifest Version: 8.1.0/8.0.100 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.aspire\8.1.0\WorkloadManifest.json Install Type: FileBased

Host: Version: 8.0.8 Architecture: x64 Commit: 08338fcaa5

.NET SDKs installed: 8.0.400 [C:\Program Files\dotnet\sdk]

.NET runtimes installed: Microsoft.AspNetCore.All 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.33 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 8.0.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.33 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 8.0.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.33 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 8.0.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found: x86 [C:\Program Files (x86)\dotnet] registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables: Not set

global.json file: Not found

Learn more: https://aka.ms/dotnet/info

Download .NET: https://aka.ms/dotnet/download

dotnet-policy-service[bot] commented 1 week ago

Tagging subscribers to 'arch-wasm': @lewing See info in area-owners.md if you want to be subscribed.

lambdageek commented 1 week ago

The custom-attr.c:2001 warning is here:

https://github.com/dotnet/runtime/blob/cb77171f85a1431e67525922a53621d7475c5ebd/src/mono/mono/metadata/custom-attrs.c#L2001

The assertion is here:

https://github.com/dotnet/runtime/blob/cb77171f85a1431e67525922a53621d7475c5ebd/src/mono/mono/metadata/assembly.c#L1672-L1673

It looks like we're trying to get the list of InternalsVisibleTo attributes - we do it by trying to load all the [assembly:] custom attributes and to load the MonoMethod for all of them. That ends up failing become some attribute's definition doesn't get loaded properly.

It seems like there might be a trimmer problem - some custom attribute constructor was trimmed away but the [assembly:xyz] attribute was left in place.

Possibly mono should be more lax here. mono_custom_attrs_from_assembly_checked has an ignore_missing argument that gets propoagated down to mono_custom_attrs_from_index_checked but at this call site it is FALSE which makes us assert.

dotnet-policy-service[bot] commented 1 week ago

Tagging subscribers to this area: See info in area-owners.md if you want to be subscribed.

risto-slice commented 1 week ago

I managed to create a repo with minimal steps to reproduce this: https://github.com/risto-slice/BlazorApp.HttpClientTest/tree/master

I deleted a lot of code from my existing library that I use and left out a piece of it that causes this error. When you launch the Blazor app, it will fail with that error. However, if you remove the reference to the library and comment out the few lines of code that come from the reference, it will work again. So something from that library is causing the entire app to malfunction.

Hope that helps @lambdageek. Let me know if I can help anyhow, or if you can see a potential workaround for this problem.