首页 新闻 会员 周边 捐助

Blazor 报错

0
悬赏园豆:20 [已解决问题] 解决于 2022-11-09 11:41

'Microsoft.AspNetCore.Http.Connections.Client.HttpConnectionFactory' could not be located. Ensure the type is concrete and services are registered for all parameters of a public constructor.

这个问题如果我ctrl+f5就没有,部署到iis就会出现,f5调试也会报这个错误,

有没有大神能分析下哪里的问题

Code部分代码,调用一下SignalR

····
@using Microsoft.AspNetCore.SignalR.Client
@using My.Share.Models
@inject NavigationManager NavigationManager

  @code {
   private HubConnection hubConnection;
   private List<string> messages = new List<string>();
List<Side> Sides = new List<Side>();

protected async override Task OnInitializedAsync()
{
    try
    {

        hubConnection = new HubConnectionBuilder()
           .WithUrl("http://192.168.0.115:7788/myhub")
           .Build();


        hubConnection.On("Register", (string type, string id) =>
        {
            Sides.Add(new Side() { Id = id, Type = type, State = "上线" });
            //messages.Add($"管理端({data}) 上线");
            Sides = Sides.OrderBy(t => t.State).ToList();
            StateHasChanged();
        });

        hubConnection.On("UnRegister", (string data) =>
        {
            var side = Sides.FirstOrDefault(t => t.Id.Equals(data));
            if (side != null)
            {
                side.State = "下线";
            }
            Sides = Sides.OrderBy(t => t.State).ToList();
            //messages.Add($"管理端({data}) has UnRegister");
            StateHasChanged();
        });

        await hubConnection.StartAsync();

        hubConnection.SendAsync("Register","管理").Wait();
    }
    catch (Exception ex) { Console.WriteLine("Herehere" + Environment.NewLine + ex.Message); }

}

····

问题补充:

Client是在Program这么注册的:
builder.Services.AddTransient(sp => new HttpClient { BaseAddress = new Uri("http://192.168.0.115:7788") });

猝不及防的主页 猝不及防 | 老鸟四级 | 园豆:2836
提问于:2020-06-24 16:58
< >
分享
最佳答案
0

代码没问题的,清空bin,清理下工程再重新发布就可以了。
别问我怎么晓得这样处理的,我都准备去提交issue了,兄弟你不是一个人,。

收获园豆:20
扬扬S | 菜鸟二级 |园豆:230 | 2020-09-23 11:27
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册