Resolution failed with error: No public constructor is available - asp.net

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.

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);

Related

.NET Core Dependency Injection giving "Ambiguous Constructor" errors after update to version 5.0.0

I have a number of classes that consume API services and whose constructors follow the pattern below:
public class SomeClass
{
public SomeClass(IHttpClientFactory factory, ILogger<SomeClass> logger = null)
{
// ...
}
public SomeClass(HttpClient client, ILogger<SomeClass> logger = null)
{
// ...
}
}
The first constructor is the one used by .NET Core's built-in dependency injection (by calling IServicesCollection.AddHttpClient() from the Startup.ConfigureServices() method, and then calling IHttpClientFactory.CreateClient() in the constructor); the second constructor is mostly used for unit testing, to allow a HttpClient (or mock) to be passed in. This has worked fine until now, but this morning I started getting errors like the one below:
An unhandled exception has occurred
System.InvalidOperationException:
Unable to activate type
'Service'.
The following constructors are ambiguous:Void
.ctor(System.Net.Http.IHttpClientFactory,
Microsoft.Extensions.Logging.ILogger`1[Service])Void
.ctor(System.Net.Http.HttpClient,
Microsoft.Extensions.Logging.ILogger`1[Service])
at
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateConstructorCallSite(ResultCache
lifetime, Type serviceType, Type implementationType, CallSiteChain
callSiteChain)
... long stack trace elided...
This was working up till now. It seems strange that the dependency injection mechanism considers the constructors to be ambiguous when IHttpClientFactory and HttpClient do not share any common interfaces.
I updated both Visual Studio 19 to the latest version (16.8.2) and all NuGet packages in the solution at the weekend. The Microsoft.Extensions.DependencyInjection package is now version 5.0.0; previously it was version 3.1.9. I have worked around the issue for now by removing the constructors that take the HttpClient argument and replaced the code in my tests to use a mock IHttpClientFactory instead, so the actual impact was low. However, it would be help my peace of mind, if nothing else, to understand why this broke in the first place. Is there some aspect of configuring .NET Core dependency injection that I have overlooked? Or has the strategy to resolve dependencies changed subtly between versions 3.1.9 and 5.0.0?

Entity Framework Sql Azure mapping error

Setup:
Asp.NET Web Api 2 (Running in Azure Cloud service, 3 instances), Entity Framework 6.1 and Sql Azure
Problem
My application started reporting a ton of weird errors all of a sudden.
When using EF to get entities from the database these types of errors are reported:
"The '{PropertyName}' property on '{TableName}' could not be set to a 'System.String' value. You must set this property to a non-null value of type 'System.Int64'"
And
"The '{PropertyName}' property on '{TableName}' could not be set to a 'System.Int64' value. You must set this property to a non-null value of type 'System.String'."
My interpretation is that the database is returning non-matching objects compared to what I'm trying to map against, but I can't see why that would start happening out of the blue, after running just fine for millions of requests.
While I was writing this I rebooted the api instances and now the errors are gone.
Any help in figuring this out will be highly appreciated.
Turned out the probable cause was a mistake in the setup of the unit of work pattern. Note to self: Do not create a new dbcontext to replace a dbcontext that is being used :)

WCF Exception : There was an error while trying to deserialize parameter

My WCF service is developed in .Net 3.0 and developed application which is consuming WCF in 3.5. When I try to consume my WCF then I am getting below error --
"The formatter threw an exception while trying to deserialize the
message: There was an error while trying to deserialize parameter
criteria. The InnerException message was 'Invalid enum value
'Positions' cannot be deserialized into type 'SecurityContents'.
Ensure that the necessary enum values are present and are marked with
EnumMemberAttribute attribute if the type has DataContractAttribute
attribute.'. Please see InnerException for more details."
Please help me out in this.
This error means there is a new SecurityContents enum value of "Positions" that your client doesn't know about. You likely need to update your service reference.
I've also seen this if you Reuse types in referenced assemblies. Try unchecking this.

ejb jndi lookup throws ClassCastexception only when invoked from IBM Message Broker

When i try to make a remote ejb jndi look up, IBM message Broker throws ClassCastexception for the factory object.
But the same code works fine for a normal local java application and junit.Why this problem occurs when called only from IBM WMB
Context context = new InitialContext(ejbJndiProperties);
Object factoryObj = context.lookup("SampleBeanTAFJ/remote");
return (SampleBeanRemote) factoryObj;
This is often called by loading parts of the interface in a different classloader to the implementation classes.
I would use the env var:
IBM_JAVA_OPTIONS=-Dibm.cl.verbose=*
Then restart the broker, this will dump classloading trace to stdout / console.txt which might give you some clues.
What are the exact classes involved in the error and what jars are they stored in? Deployed to the EG or referenced via a SHARED-CLASSES? The exact details determine which classloaders should be in use here.

Error: failed due to the following error: 80040154 when i call Req() class

I use OTAClient.dll from HP for conencting with Quality Center.
My connection is correct:
TDConnection tdCon = new TDConnection();
tdCon.InitConnectionEx("http://....");
tdCon.Login("username", "userpass");
tdCon.Connect("****", "********");
But in this area i get error:
Req newReq = new Req();
I set platform target in x86 but didn't help me
Instead of COM object use the rest library. You could send xml documents with parameters for creating and updating requirements(Req) in QC. You can find documentation in QC.
You will use "post" method by HttpWebRequest for creating and updating, "get" method for getting session parameters.
In the rest library look to creating entity description. For maintaining connections you must save QCSessionId. Look to authentication description.
Good luck!

Resources