Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Assertion at /__w/1/s/src/mono/mono/metadata/assembly.c:1673, condition `' not met

$
0
0

I am getting the following error in console:Error: [MONO] * Assertion at /__w/1/s/src/mono/mono/metadata/assembly.c:1673, condition `<disabled>' not met

error pic

I have a component and this is my 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. 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 my Program.cs is like this:

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

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 remove all HttpClient dependencies in Test and simply return a value, it works just fine.

It's a semi big project and I don't know what could be causing this, nor this error is helpful in any way, form or shape and I am lost what to do. It's been 2-3 days now of trying different things, but nothing worked/helped so far. Any help is appreciated.

Update: Using .NET 8 (Blazor WebAssembly). Also, if I comment out this line in my Test class:var x = (await _httpClient.GetAsync("todos")).Content.ReadAsStringAsync(); it 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 make calls, it does NOT enter the method at all, it throws the exception before it makes the call to the method somehow. Never enters it.


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>