LightInject icon indicating copy to clipboard operation
LightInject copied to clipboard

Upgrade to 4.0.2 breaks SignalR

Open modernist opened this issue 9 years ago • 7 comments

When upgrading from version LightInject 4.0.0 to 4.0.2 using LightInject.SignalR integration I get the following exception:

Exception of type System.Reflection.TargetInvocationException
Source: mscorlib
Message: Exception has been thrown by the target of an invocation.
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Owin.Loader.DefaultLoader.<>c__DisplayClass12.<MakeDelegate>b__b(IAppBuilder builder)
   at Owin.Loader.DefaultLoader.<>c__DisplayClass1.<LoadImplementation>b__0(IAppBuilder builder)
   at Microsoft.Owin.Hosting.Engine.HostingEngine.ResolveApp(StartContext context)
   at Microsoft.Owin.Hosting.Engine.HostingEngine.Start(StartContext context)
   at Microsoft.Owin.Hosting.Starter.DirectHostingStarter.Start(StartOptions options)
   at Microsoft.Owin.Hosting.Starter.HostingStarter.Start(StartOptions options)
   at Microsoft.Owin.Hosting.WebApp.StartImplementation(IServiceProvider services, StartOptions options)
   at Microsoft.Owin.Hosting.WebApp.Start(StartOptions options)
   at Microsoft.Owin.Hosting.WebApp.Start[TStartup](StartOptions options)
   at Server.StartServiceWebApp() in M:\Projects\Server\Server.cs:line 187

Inner Exception of type System.MissingMethodException
Source: LightInject.SignalR
Message: Method not found: 'Void LightInject.IServiceRegistry.Register(System.Linq.Expressions.Expression`1<System.Func`2<LightInject.IServiceFactory,!!0>>)'.
   at LightInject.SignalR.LightInjectDependencyResolver..ctor(IServiceContainer serviceContainer)
   at Server.Startup.Configuration(IAppBuilder app) in M:\Projects\Server\Startup.cs:line 31

modernist avatar Dec 14 '15 08:12 modernist

Try upgrading to LightInject.Interception 1.0.0.9 (Just published)

seesharper avatar Dec 14 '15 13:12 seesharper

I'm afraid the issue is not resolved with the upgrade to LightInject.Interception 1.0.0.9. I am using .NET 4.6 and It occurs when attempting to replace the Owin GlobalHost.DependencyResolver with a new instance of the LightInjectDependencyResolver class.

The exception occurs in the first line of the LightInjectDependencyResolver class constructor: https://github.com/seesharper/LightInject/blob/master/LightInject.SignalR/LightInject.SignalR.cs#L97

serviceContainer.Register<IHubActivator>(factory => new LightInjectHubActivator(serviceContainer));

Perhaps it is an issue with the conditional compilation directives used in this section: https://github.com/seesharper/LightInject/blob/master/LightInject/LightInject.cs#L208 because LightInject is compiled for .NET 4.6 whereas LightInject.SignalR is compiled for .NET 4.5. Therefore it could just be an issue with the binaries available on NuGet - I haven't checked with the source versions.

modernist avatar Dec 15 '15 13:12 modernist

@modernist I don't know if you're still fighting this issue. I was running into the same problem this morning. I ended up fixing it by switching to the latest source NuGet package and adding #define NET45 to the head of the LightInject.cs file. After that I was able to compile and launch my project without issue.

ErikCL avatar Mar 26 '16 16:03 ErikCL

I have the same issue, also using .NET 4.6.

geirsagberg avatar Apr 22 '16 11:04 geirsagberg

I am now hitting this issue. I can not use the source packages (because I am exposing the ServiceContainer to another project, and all of the types in the source packages are internal).

This means I am currently blocked on getting LightInject to work with SignalR.

I am using .NET 4.5.1, but I tried re-targetting to both .NET 4.5 and .NET 4.6 and re-installing all affected packages, and all LightInject packages, and the issue was still happening.

Versions:

  • LightInject 4.0.11
  • LightInject.Web 1.0.0.7
  • LightInject.WebApi 1.0.0.4
  • LightInject.Mvc 1.0.0.4
  • LightInject.Interception 1.0.0.11
  • LightInject.SignalR 1.0.0.1

vegardlarsen avatar Aug 23 '16 13:08 vegardlarsen

I had to workaround this issue by not using LightInject.SignalR, but manually registering my hub with the SignalR dependency resolver:

var hubConfiguration = new HubConfiguration();
hubConfiguration.Resolver.Register(typeof(MyHub), Container.Create<MyHub>());
app.MapSignalR(hubConfiguration);

This enables constructor injection in the hub, using services already registered in the LightInject Container.

geirsagberg avatar Aug 23 '16 13:08 geirsagberg

I will move SignalR into its own repo and add specific support for Net46

seesharper avatar Aug 26 '16 13:08 seesharper