You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a test that asserts that an extension method correctly registers all required dependencies such that clients should have everything fully registered. On dotnet8 this throws an exception. I've included a cut-down example.
publicclassExampleOfFailingTest{[Fact]publicvoidServiceProviderShouldResolveTheInterface(){IServiceCollectionsubject=new ServiceCollection();// Create a mocked interfaceMock<ITestInterface<TestClass>>mockInterface=new();// add it to the service collection
subject.TryAddSingleton(typeof(ITestInterface<TestClass>), mockInterface.Object.GetType());// build the service providerServiceProviderserviceProvider= subject.BuildServiceProvider();// now get an instance of the service
Assert.NotNull(serviceProvider.GetService<ITestInterface<TestClass>>());}}publicclassTestClass{}publicinterfaceITestInterface<inT>whereT:class{
Task DoSomeWork(Trequest);}
Expected Behavior
Should also pass on dotnet8
Exception with Stack Trace
System.InvalidOperationException
Unable to resolve service for type 'Castle.DynamicProxy.IInterceptor[]' while attempting to activate 'Castle.Proxies.ITestInterface`1Proxy'.
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateArgumentCallSites(ServiceIdentifier serviceIdentifier, Type implementationType, CallSiteChain callSiteChain, ParameterInfo[] parameters, Boolean throwIfCallSiteNotFound)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateConstructorCallSite(ResultCache lifetime, ServiceIdentifier serviceIdentifier, Type implementationType, CallSiteChain callSiteChain)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact(ServiceDescriptor descriptor, ServiceIdentifier serviceIdentifier, CallSiteChain callSiteChain, Int32 slot)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact(ServiceIdentifier serviceIdentifier, CallSiteChain callSiteChain)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateCallSite(ServiceIdentifier serviceIdentifier, CallSiteChain callSiteChain)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.GetCallSite(ServiceIdentifier serviceIdentifier, CallSiteChain callSiteChain)
at Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateServiceAccessor(ServiceIdentifier serviceIdentifier)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(ServiceIdentifier serviceIdentifier, ServiceProviderEngineScope serviceProviderEngineScope)
at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetService[T](IServiceProvider provider)
at MoqTest.ExampleOfFailingTest.ServiceProviderShouldResolveTheInterface() in E:\temp\src\moq\MoqTest\MoqTest\Class1.cs:line 26
at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
Version Info
Moq - 4.20.70
The text was updated successfully, but these errors were encountered:
If you want the service collection to return your previously constructed mock from its GetService, you need to register the function to retrieve it, not the mock type which the container doesn't know how to instantiate:
Describe the Bug
I have a test that asserts that an extension method correctly registers all required dependencies such that clients should have everything fully registered. On dotnet8 this throws an exception. I've included a cut-down example.
Steps to Reproduce
Execute the code below - net6 works - net8 fails
Expected Behavior
Should also pass on dotnet8
Exception with Stack Trace
Version Info
Moq - 4.20.70
The text was updated successfully, but these errors were encountered: