title: migration from asp.core 2.2 to 3.1. Autofac.Core.DependencyResolutionException
body: <p>I am doing a migration and have encountered an exception. Autofac can resolve my service from an instance of a service provider, but cannot get it in my controller at the time of the request.</p>
  
  <p><strong>Exception:</strong> Castle.DynamicProxy.ProxyGe
    nerationException: This is a DynamicProxy2 error: Target type for the proxy implements Castle.DynamicProxy.IP
    roxyTargetAccessor which is a DynamicProxy infrastructure interface and you should never implement it yoursel
    f. Are you trying to proxy an existing proxy?</p>
  
  <p>My AutoregistrableModule looks like that:</p>
  
  <pre><code>public class AutoregisterableModule : Autofac.Module
  {
      private readonly string _nameFilter;
  
      /// &lt;summary&gt;
      /// Default ctor
      /// &lt;/summary&gt;
      /// &lt;param name="nameFilter"&gt;Load will only search assemblies with names that contains filter&lt;/param&gt;
      public AutoregisterableModule(string nameFilter)
      {
          _nameFilter = nameFilter;
      }
  
      /// &lt;summary&gt;
      /// Register's dependencies
      /// &lt;/summary&gt;
      protected override void Load(ContainerBuilder builder)
      {
          var assemblies = new List&lt;Assembly&gt;();
          var dependencies = DependencyContext.Default.RuntimeLibraries.Where(x =&gt; x.Name.Contains(_nameFilter));
          foreach (var library in dependencies)
          {
              var assembly = Assembly.Load(new AssemblyName(library.Name));
              assemblies.Add(assembly);
          }
  
          builder.Register(c =&gt; new LogInterceptor()).InstancePerLifetimeScope();
  
          var isProd = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Production";
  
          var containerBuilder = builder.RegisterAssemblyTypes(assemblies.ToArray())
              .Where(TypesToRegisterFilter)
              .PreserveExistingDefaults()
              .AsImplementedInterfaces();
  
          if (!isProd)
          {
              containerBuilder.EnableInterfaceInterceptors();
          }
  
          base.Load(builder);
      }
  
      private static bool TypesToRegisterFilter(Type type)
      {
          return !type.IsSubclassOf(typeof(SwaggerConfigureOptions)) &amp;&amp; !typeof(BackgroundService).IsAssignableFrom(type);
      }
  }
  </code></pre>
  
  <p>If I remove that row all works well(except of my LoggerInterceptor :D) </p>
  
  <pre><code>containerBuilder.EnableInterfaceInterceptors();
  </code></pre>
  
  <p>My service looks like</p>
  
  <pre><code> [Intercept(typeof(LogInterceptor))]
  public class CategoriesService : ICategoriesService
  {
       // some code here 
  }
  </code></pre>
  
  <p>I tried to fix it by downgranding Autofac.Extensions.DependencyInjection package from 6.0.0 to 5.0.1 as were suggested <a href="https://stackoverflow.com/questions/60067943/unable-to-hook-up-interceptor-on-classes-interfaces-in-asp-net-core-3-1-applicat">there</a> but it didn't help.</p>
  
  <p>You can find full Stacktrace there <a href="https://pastebin.com/YCAhLQv0" rel="nofollow noreferrer">https://pastebin.com/YCAhLQv0</a> .</p>
  
  <p><strong>So the question is how can I fix the exception and keep my interceptor working?</strong></p>