user1629977
user1629977

Reputation: 437

Resolution failed with error: No public constructor is available

I am using WCF web services and it was using OLD unity 2.0. So i updated Unity and other reference with latest version 5.0. I am getting exception:

Resolution failed with error: No public constructor is available for type xyz.Services.Contracts.Security.IAuthenticationService.

For more detailed information run Unity in debug mode: new UnityContainer().AddExtension(new Diagnostic())

Exception of type 'Unity.Exceptions.InvalidRegistrationException' was thrown.

Really i tried many things but not success. please any expert have a look.

Upvotes: 2

Views: 13865

Answers (2)

Estuardo
Estuardo

Reputation: 1

I know this is a bit old, but I had the same issue for days! My solution is based on Xamarin.Forms 5.0.0.2578, I upgraded Prism.Unity.Forms to the last version (at the time of this writting v.8.1.97). Once installed, Xamarin.Forms.DependencyService.Resolve and Xamarin.Forms.DependencyService.Get stop working it always returned null no matter what. I don't know why the setFormsDependencyResolver from IPlatformInitializer did nothing.

  public App(IPlatformInitializer initializer)
   : base(initializer, setFormsDependencyResolver: true) { }

I tried installing the latest versions of all related available packages from prism and Unity with no vail. After a lot of googling without any luck, I went back to my old project to see what was different. The only thing I've found was the package version. Needless to say I had to downgrade and the only package version that worked was the v.7.2.0.1422. If you want to give it a try:

  • Remove all Prism & Unity packages (unless you have reasons for not to do so)
  • Install just the Prism.Unity.Forms v.7.2.0.1422 (Please note that my project is Xamarin.Forms no UWP/WPF)
  • Compile & Run.

I hope it helps.

Upvotes: 0

grammophone
grammophone

Reputation: 699

I came across the same error upgrading from Unity version 3.5 to 5.11. In my case, during resolution the exception was the same ResolutionFailedException with message "No public constructor is available for IMyInterface" and having the same inner exception InvalidRegistrationException.

Well, the error messages and types of exceptions were misleading in my case; there was no registration problem nor did I ask for a public constructor for the interface. It seems that there has been a breaking change in the Resolve method overload which takes an instance name. Null names are no longer equivalent to empty string names. Replace your empty string name to null or use the other overload which doesn't specify an instance name:

var service = container.Resolve<xyz.Services.Contracts.Security.IAuthenticationService>();

OR

var service = container.Resolve<xyz.Services.Contracts.Security.IAuthenticationService>(null);

Upvotes: 4

Related Questions