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'm using the latest version auf Autofac (6.3.0) (.net 6.0 on windows 10, console application)
Describe the Bug
When I add a middleware as described here https://autofac.readthedocs.io/en/latest/examples/log4net.html, I get the following exception:
System.InvalidOperationException: 'Cannot add service middleware in phase 'ResolveRequestStart' to a registration pipeline. Valid service middleware phases: [ResolveRequestStart, ScopeSelection, Decoration, Sharing, ServicePipelineEnd]'
Note: it seems no matter which phase I want to attach to, I always get the same exception.
Could you please tell me what I'm doing wrong.
Steps to Reproduce
Create a new ContainerBuilder, register a Module and within this module add the middleware, build the container, that's it.
I would expect that I can register my middleware and that this middleware will be executed by Autofac.
Exception with Stack Trace
at Autofac.Core.Resolving.Pipeline.ResolvePipelineBuilder.VerifyPhase(PipelinePhase middlewarePhase)
at Autofac.Core.Resolving.Pipeline.ResolvePipelineBuilder.AddStage(IResolveMiddleware stage, MiddlewareInsertionMode insertionLocation)
at Autofac.Core.Resolving.Pipeline.ResolvePipelineBuilder.Use(IResolveMiddleware stage, MiddlewareInsertionMode insertionMode)
at AutofacSample.AutofacCheckLifetimeMiddlewareConfigurationModule.<>c.<AttachToComponentRegistration>b__0_0(Object _, IResolvePipelineBuilder pipeline) in C:\Dev\Vie\Playground\Src\AutofacSolution\AutofacSample\AutofacCheckLifetimeMiddlewareConfigurationModule.cs:line 16
at Autofac.Core.Registration.ComponentRegistration.BuildResolvePipeline(IComponentRegistryServices registryServices)
at Autofac.Core.Registration.ComponentRegistryBuilder.Build()
at Autofac.ContainerBuilder.Build(ContainerBuildOptions options)
at AutofacSample.Program.InitAutofac() in C:\Dev\Vie\Playground\Src\AutofacSolution\AutofacSample\Program.cs:line 82
at AutofacSample.Program.Main() in C:\Dev\Vie\Playground\Src\AutofacSolution\AutofacSample\Program.cs:line 15
Dependency Versions
Autofac:
6.3.0, no other dependencies.
The text was updated successfully, but these errors were encountered:
Thanks for raising this; it appears there is a bug here in the error message you are shown. The wrong list of "valid service middleware phases" is being shown in the message.
Can you check, if you set the phase of the middleware to RegistrationPipelineStart, do you still get an exception?
Thanks for raising this; it appears there is a bug here in the error message you are shown. The wrong list of "valid service middleware phases" is being shown in the message.
Can you check, if you set the phase of the middleware to RegistrationPipelineStart, do you still get an exception?
You are right, changing the phase to RegistrationPipelineStart works fine, thank you very much.
So the exception is just a little bit misleading as you already posted out
Br
General
I'm using the latest version auf Autofac (6.3.0) (.net 6.0 on windows 10, console application)
Describe the Bug
When I add a middleware as described here https://autofac.readthedocs.io/en/latest/examples/log4net.html, I get the following exception:
System.InvalidOperationException: 'Cannot add service middleware in phase 'ResolveRequestStart' to a registration pipeline. Valid service middleware phases: [ResolveRequestStart, ScopeSelection, Decoration, Sharing, ServicePipelineEnd]'
Note: it seems no matter which phase I want to attach to, I always get the same exception.
Could you please tell me what I'm doing wrong.
Steps to Reproduce
Create a new ContainerBuilder, register a Module and within this module add the middleware, build the container, that's it.
Expected Behavior
I would expect that I can register my middleware and that this middleware will be executed by Autofac.
Exception with Stack Trace
Dependency Versions
Autofac:
6.3.0, no other dependencies.
The text was updated successfully, but these errors were encountered: