MediatR
MediatR copied to clipboard
AmbigousMatchException
I have the following responses and request handlers in two different assemblies.
AssemblyA
EmployeeDetails
GetEmployeeQueryHandler: IRequestHandler<EmployeeDetalils>
AssemblyB
EmployeeDetails
GetEmployeeQueryHandler: IRequestHandler<EmployeeDetalils>
When I try to register dependencies, it gives an exception "System.Reflection.AmbiguousMatchException" when AddMediatR is called. Given below is the stack trace. My models and handlers are in different namespaces even though they have the same name. Can you please help me with this?
at System.RuntimeType.GetInterface(String fullname, Boolean ignoreCase)
at System.Type.GetInterface(String name)
at MediatR.Registration.ServiceRegistrar.IsMatchingWithInterface(Type handlerType, Type handlerInterface)
at MediatR.Registration.ServiceRegistrar.<>c__DisplayClass1_0.<ConnectImplementationsToTypesClosing>b__3(Type m)
at System.Collections.Generic.List1.RemoveAll(Predicate
1 match)
at MediatR.Registration.ServiceRegistrar.ConnectImplementationsToTypesClosing(Type openRequestInterface, IServiceCollection services, IEnumerable1 assembliesToScan, Boolean addIfAlreadyExists) at MediatR.Registration.ServiceRegistrar.AddMediatRClasses(IServiceCollection services, IEnumerable
1 assembliesToScan)
at MediatR.ServiceCollectionExtensions.AddMediatR(IServiceCollection services, IEnumerable1 assemblies, Action
1 configuration)
at MediatR.ServiceCollectionExtensions.AddMediatR(IServiceCollection services, Assembly[] assemblies)
at MedAlert.Clinics.App.Server.Startup.ConfigureServices(IServiceCollection services) in Startup.cs:line 63
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.InvokeCore(Object instance, IServiceCollection services)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass9_0.<Invoke>g__Startup|0(IServiceCollection serviceCollection)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.Invoke(Object instance, IServiceCollection services)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass8_0.<Build>b__0(IServiceCollection services)
at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.UseStartup(Type startupType, HostBuilderContext context, IServiceCollection services, Object instance)
at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass13_0.<UseStartup>b__0(HostBuilderContext context, IServiceCollection services)
at Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider()
at Microsoft.Extensions.Hosting.HostBuilder.Build()
at MedAlert.Clinics.App.Server.Program.Main(String[] args) in D:\MainProject\ClinicsApis\Clinics.App\MedAlert.Clinics.App.Server\Program.cs:line 18
Curious if this is not supported. I anticipate coding myself into this very scenario.
@zachrybaker, did u find any solution for this?
@simirajsp To be honest I have not hit this issue in practice. In fact at this point I would say that if you did you probably have a design issue. Conceptually, why would you need two different assemblies to provide that functionalities' implementation? Perhaps what you need, actually, is a single assembly to implement, with two other assemblies that reference the said assembly to expose it in two different manners.