0

I want to be able to inject dependencies with my IoC container without running into the TinyIoC.TinyIoCResolutionException exception.

My Xamarin Android app is using TinyIoC to inject dependencies. On app start up (before anything else happens) all the dependencies are registered with the container as so:

container.Register<IExampleService, ExampleService>();

I then resolve the dependencies after registering within the onCreate() method of activities as so:

container.Resolve<IExampleService>();

Now some dependencies are resolved fine, but then others throw:

TinyIoC.TinyIoCResolutionException
Message = Unable to resolve type: ExamplePackage.ExampleService
Source = Common.Shared.TinyIoC
StackTrace:
at TinyIoC.TinyIoCContainer.ConstructType(System.Type requestedType, System.Type implementationType, System.Reflection.ConstructorInfo constructor, TinyIoC.NamedParameterOverloads parameters, TinyIoC.ResolveOptions options) [0x000c4] in <e0fa358c835b42dcacf38a6ad3cc70cc>:0 
at TinyIoC.TinyIoCContainer.ConstructType(System.Type requestedType, System.Type implementationType, System.Reflection.ConstructorInfo constructor, TinyIoC.ResolveOptions options) [0x00009] in <e0fa358c835b42dcacf38a6ad3cc70cc>:0 
at TinyIoC.TinyIoCContainer+SingletonFactory.GetObject (System.Type requestedType, TinyIoC.TinyIoCContainer container, TinyIoC.NamedParameterOverloads parameters, TinyIoC.ResolveOptions options)[0x0003b] in <e0fa358c835b42dcacf38a6ad3cc70cc>:0 
at TinyIoC.TinyIoCContainer.ResolveInternal (TinyIoC.TinyIoCContainer+TypeRegistration registration, TinyIoC.NamedParameterOverloads parameters, TinyIoC.ResolveOptions options) [0x00027] in <e0fa358c835b42dcacf38a6ad3cc70cc>:0 
at TinyIoC.TinyIoCContainer.Resolve(System.Type resolveType) [0x00011] in <e0fa358c835b42dcacf38a6ad3cc70cc>:0 
at TinyIoC.TinyIoCContainer.Resolve[ResolveType] ()[0x00000] in <e0fa358c835b42dcacf38a6ad3cc70cc>:0 
at Common.Shared.IoC.Tiny.Tiny.Resolve[ResolveType] ()[0x00005] in <8ff607064979404aaa60061c0b7e19eb>:0 
at Android.App.Activity.n_OnResume (System.IntPtr jnienv, System.IntPtr native__this)[0x00009] in <4a189ea3b82b48a089ac9002b2abc206>:0 
at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.8(intptr, intptr)

I have recently updated my Target API to 28, previously it was 21. I'm not sure if this is a factor.

Kes Walker
  • 1,154
  • 2
  • 10
  • 24
  • 2
    Maybe you changed some of the constructor parameters on the type which it cannot resolve? – Cheesebaron Mar 06 '20 at 10:09
  • Interesting you should say such a thing Mr @Cheesebaron . When I remove the constructor entirely, the type resolves! If I were to have changed some of the constructor parameters within the `ExampleService` class, must I also make amendments to other parts of my code? What is the issue with changing constructor parameters??? – Kes Walker Mar 06 '20 at 10:30
  • 1
    Well it caught my eye, since the first entry in the StackTrace says something about `NamedParameterOverloads`. So it is trying to resolve a non-empty constructor in terms of parameters you can give it. Hence, if the TinyIoC cannot figure out how to resolve one of those parameters it will fail. It would have been nice if it could tell you _which_ of the parameters is failing, I don't suppose there is an inner exception which reveals more details? Make sure that the parameters it needs to resolve are also available in the container. – Cheesebaron Mar 06 '20 at 11:03
  • @Cheesebaron the plot thickens... after investigating the inner exception, I discovered an exponential number of inner exceptions (each of them `unable to resolve type` exceptions) which brings me to the root issue. Thankyou for your wisdom, I was not very familiar with inner exceptions. I will investigate this new problem, thanks again. – Kes Walker Mar 06 '20 at 11:50
  • @KesWalker did you ever *resolve* this? – Colton Scottie Oct 09 '20 at 23:32
  • @ColtonScottie it was a simple exception that was causing this exception, I had to look at the 'innerException' of this exception to see the real issue. – Kes Walker Oct 11 '20 at 19:05

0 Answers0