- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个继承自 Hub 类的 NotificationHub 类。
public class NotificationHub : Hub
{
public void Send(string userId, Notification notification)
{
Clients.User(userId)
.notificationReceived(notification);
}
}
[NullReferenceException: Object reference not set to an instance of an object.]
Microsoft.AspNet.SignalR.Hubs.SignalProxy.Invoke(String method, Object[] args) +88
Microsoft.AspNet.SignalR.Hubs.SignalProxy.TryInvokeMember(InvokeMemberBinder binder, Object[] args, Object& result) +12
CallSite.Target(Closure , CallSite , Object , <>f__AnonymousType0`4 ) +351
public class NotificationHub : Hub
{
public void Send(string userId, Notification notification)
{
var context = GlobalHost.ConnectionManager.GetHubContext<NotificationHub>();
context.Clients.User(userId)
.notificationReceived(notification);
}
}
GlobalHost.DependencyResolver.Register(typeof(IHubActivator), () => new SimpleInjectorHubActivator(container));
GlobalHost.DependencyResolver.Register(typeof(IUserIdProvider), () => new SignalRHubUserIdProvider());
public class SimpleInjectorHubActivator : IHubActivator
{
private readonly Container _container;
public SimpleInjectorHubActivator(Container container)
{
_container = container;
}
public IHub Create(HubDescriptor descriptor)
{
return (IHub) _container.GetInstance(descriptor.HubType);
}
}
最佳答案
如果您想从集线器处理程序方法之外(即不在服务器上处理消息期间)向客户端发送某些内容,则必须使用 GlobalHost.ConnectionManager.GetHubContext<NotificationHub>();
原因是当调用该方法处理某些客户端消息时,由 SignalR 和 Clients
创建集线器实例。属性已正确初始化。当您自己从服务器代码调用方法(并且可能自己创建集线器实例)时,情况并非如此。
Imho 错误消息不是很清楚,这个用例应该由 SignalR 更好地处理。无论如何,出于同样的原因,我建议将所有向客户端发送消息的方法分开,这些方法旨在从服务器代码调用到不同的类(不是从 Hub
派生的)。
关于asp.net-mvc-5 - Hub.Clients.User(userId).methodCall 总是抛出未设置为对象实例的对象引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30905333/
我有一些特定的 android 代码,我使用参数在 android 中调用一些命令。 这是我现在用来检查特定参数名称的 android 代码,如果它存在,则获取它: @Override public
我有这个简单的功能: public int id() { return 0; } 我有这个测试功能: void test() { int a = id(); int b =
是否可以从 Python 中的 operator.methodcaller 获取函数名称? import operator as op mc = op.methodcaller('foo') prin
创建插件时的默认单元测试设置如下所示: void main() { const MethodChannel channel = MethodChannel( 'com.example/
我在 StackOverflow 上的第一个问题。我希望能够做类似的事情: SomeClass mock = mock(SomeClass.class); String methodName = "s
我想获取 PosixPath 对象的列表,并根据相应的文件大小对其进行排序。我正在尝试使用排序函数来做到这一点。我要用于排序的键是 object.stat().st_size,其中 object 是一
我们有使用 Spring 框架的 NamedParameterJdbcTemplate 的应用程序执行各种 JDBC 语句。此类中的大多数方法都已重载。例如,update() 的一个版本接受一个 Ma
我有一个继承自 Hub 类的 NotificationHub 类。 public class NotificationHub : Hub { public void Send(
我在 Java 中使用 Akka 类型的 actor。我有一个 BatchManager ,它是与 Controller 的接口(interface),还有一个 JobManager ,它创建一些工作
我正在尝试使用INRIA开发的工具spoon来解析一个项目的方法调用,我已经有一个方法mysql表,其中存储了所有方法(methodid、methodname、classid、classname)。我
我是一名优秀的程序员,十分优秀!