I've just created new MAUI library project
and added package from nuget Microsoft.AspNetCore.SignalR.Client
nevertheless on class
level Hub
is not found and i am getting error:
The type or namespace Hub could not be found.
Strange as in other project like Blazor App
there is no issue at all doing the same. Any thoughts?
Full code:
using System;
using Microsoft.AspNetCore.SignalR;
namespace ServicesMauiLib
{
public class ChatHub : Hub
{
public Task SendMessage(string user, string message)
{
return Clients.All.SendAsync("ReceiveMessage", user, message);
}
}
}
SignalR Hub
is something that you use on a server application so it doesn't make sense to be included in Microsoft.AspNetCore.SignalR.Client
package.
The Hub
class was included in the core Microsoft.AspNetCore.SignalR
which is now deprecated.
In 3.1 we moved to the "shared framework" concept. This made it so we don't need to release a lot of the packages that were released before and they are now included by default when you build an ASP.NET Core application. This is what happened to the SignalR server packages, they are now included in the shared framework and we no longer produce a standalone package.
Another common question is "how do I write a library for server applications that uses SignalR?". This can be done by adding a reference to the shared framework in your library. See https://docs.microsoft.com/aspnet/core/fundamentals/target-aspnetcore?view=aspnetcore-6.0&tabs=visual-studio for details.
So basically you need to add the following to the .csproj
file of your library.
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>