rebus-org / Rebus

:bus: Simple and lean service bus implementation for .NET
https://mookid.dk/category/rebus
Other
2.31k stars 361 forks source link

Rebus.Injection.ResolutionException with Newtonsoft.Json v12.0.3 #854

Closed gitter-me closed 4 years ago

gitter-me commented 4 years ago

Hi, I get Rebus.Injection.ResolutionException with Newtonsoft.Json v12.0.3 with the following message: "Could not resolve Rebus.Serialization.ISerializer with decorator depth 1 - registrations: Rebus.Injection.Injectionist+Handler"

The exception happens on configure:

_bus = Configure
     .With(_handlerActivator)
     .Logging(l => l.None())
     .Timeouts(t => t.StoreInMemory())
     .Transport(t => t.UseInMemoryTransport(new InMemNetwork(), "my-custom-queue"))
     .Start();

I upgrade the Json lib to v12 because I use it in other places as well. With v11 it works.

mookid8000 commented 4 years ago

Could you maybe post the whole stack trace?

gitter-me commented 4 years ago

Here it is: Could not resolve Rebus.Serialization.ISerializer with decorator depth 1 - registrations: Rebus.Injection.Injectionist+Handler

   at Rebus.Injection.Injectionist.ResolutionContext.Get[TService]()
   at Rebus.Config.RebusConfigurer.<>c.<Start>b__12_28(IResolutionContext c)
   at Rebus.Injection.Injectionist.Resolver`1.InvokeResolver(IResolutionContext context)
   at Rebus.Injection.Injectionist.ResolutionContext.Get[TService]()
   at Rebus.Config.RebusConfigurer.<>c.<Start>b__12_20(IResolutionContext c)
   at Rebus.Injection.Injectionist.Resolver`1.InvokeResolver(IResolutionContext context)
   at Rebus.Injection.Injectionist.ResolutionContext.Get[TService]()
   at Rebus.Config.RebusConfigurer.<>c.<Start>b__12_21(IResolutionContext c)
   at Rebus.Injection.Injectionist.Resolver`1.InvokeResolver(IResolutionContext context)
   at Rebus.Injection.Injectionist.ResolutionContext.Get[TService]()
   at Rebus.Config.RebusConfigurer.<>c.<Start>b__12_10(IResolutionContext c)
   at Rebus.Injection.Injectionist.Resolver`1.InvokeResolver(IResolutionContext context)
   at Rebus.Injection.Injectionist.ResolutionContext.Get[TService]()
   at Rebus.Config.RebusConfigurer.<>c.<Start>b__12_12(IResolutionContext c)
   at Rebus.Injection.Injectionist.Resolver`1.InvokeResolver(IResolutionContext context)
   at Rebus.Injection.Injectionist.ResolutionContext.Get[TService]()
   at Rebus.Config.RebusConfigurer.<>c__DisplayClass12_0.<Start>b__25(IResolutionContext c)
   at Rebus.Injection.Injectionist.Resolver`1.InvokeResolver(IResolutionContext context)
   at Rebus.Injection.Injectionist.ResolutionContext.Get[TService]()
   at Rebus.Config.RebusConfigurer.<>c__DisplayClass12_0.<Start>b__26(IResolutionContext c)
   at Rebus.Injection.Injectionist.Resolver`1.InvokeResolver(IResolutionContext context)
   at Rebus.Injection.Injectionist.ResolutionContext.Get[TService]()
   at Rebus.Injection.Injectionist.Get[TService]()
   at Rebus.Config.RebusConfigurer.Start()
   at App.Sender.SendGateway..ctor(Backend backend)

Inner exception: The type initializer for "Rebus.Serialization.Json.JsonSerializer" threw an exception.

   at Rebus.Serialization.Json.JsonSerializer..ctor()
   at Rebus.Config.RebusConfigurer.<>c.<Start>b__12_9(IResolutionContext c)
   at Rebus.Injection.Injectionist.Resolver`1.InvokeResolver(IResolutionContext context)
   at Rebus.Injection.Injectionist.ResolutionContext.Get[TService]()

Inner exception: Could not load file or assembly "Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" or one of its dependencies. The system cannot find the specified file.

   at Rebus.Serialization.Json.JsonSerializer..cctor()
mookid8000 commented 4 years ago

Funny. I mean, it's pretty obvious that you've updated the Newtonsoft JSON.NET dependency from version 11 to 12, but the NuGet client usually handles that somehow, e.g. by inserting assembly binding directives if necessary.

I seem to recall having updated JSON.NET to version 12 myself in several projects without any problems.

Could you maybe try and do a reinstall of Rebus? (e.g. like update-package rebus -reinstall in the package manager console)

gitter-me commented 4 years ago

the NuGet client usually handles that somehow, e.g. by inserting assembly binding directives if necessary.

The binding redirect was my issue.

mookid8000 commented 4 years ago

Perfect! Good to hear you made it work 🙂