question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Castle.MicroKernel.CircularDependencyException when resolving MvcRouteHandler

See original GitHub issue

Hello! I got a question. Abp.Boilerplate, v 3.9.0 Why am i getting Castle.MicroKernel.CircularDependencyException on

app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "defaultWithArea",
                    template: "{area}/{controller=Home}/{action=Index}/{id?}");

                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });

with breaking on exceptions turned on? How do i get rid of it? As far as I understood, the exception is thrown when resolving MvcRouteHandler. Full exception message is

Dependency cycle has been detected when trying to resolve component 'Microsoft.AspNetCore.Razor.Language.RazorProjectEngine_143cff80-96bf-4aa2-80fc-af7373a01ca6'.
The resolution tree that resulted in the cycle is the following:
Component 'Microsoft.AspNetCore.Razor.Language.RazorProjectEngine_143cff80-96bf-4aa2-80fc-af7373a01ca6' resolved as dependency of
	component 'Microsoft.AspNetCore.Razor.Language.RazorEngine_e513da7d-e020-4ea6-925d-e4c5c69c3bee' resolved as dependency of
	component 'Microsoft.AspNetCore.Mvc.Razor.Internal.LazyMetadataReferenceFeature_5cbf1bf2-21ea-4c01-9186-70edda5f81ff' resolved as dependency of
	component 'Microsoft.AspNetCore.Razor.Language.RazorProjectEngine_143cff80-96bf-4aa2-80fc-af7373a01ca6' resolved as dependency of
	component 'Microsoft.AspNetCore.Mvc.Razor.Compilation.IViewCompilerProvider_08cd7c5c-c9cf-4a5e-a5aa-12aec9f1961b' resolved as dependency of
	component 'Microsoft.AspNetCore.Mvc.Razor.IRazorPageFactoryProvider_c1da251e-97e1-41d8-adc2-9d9ea0d9242c' resolved as dependency of
	component 'Microsoft.AspNetCore.Mvc.Razor.IRazorViewEngine_4bdad906-7788-4ff0-8bc0-4af945e4a625' resolved as dependency of
	component 'Microsoft.Extensions.Options.IConfigureOptions`1[[Microsoft.AspNetCore.Mvc.MvcViewOptions, Microsoft.AspNetCore.Mvc.ViewFeatures, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]]_ad494af2-5ab1-43d8-944f-8d612001e90b' resolved as dependency of
	component 'Microsoft.Extensions.Options.IOptionsFactory`1_ebc4dd86-b18c-422a-8986-a406cad4eb42' resolved as dependency of
	component 'Microsoft.Extensions.Options.IOptionsFactory`1_ebc4dd86-b18c-422a-8986-a406cad4eb42' resolved as dependency of
	component 'Microsoft.Extensions.Options.IOptions`1_d8f88dbb-e8a9-4196-abf8-9b7398343629' resolved as dependency of
	component 'Microsoft.Extensions.Options.IOptions`1_d8f88dbb-e8a9-4196-abf8-9b7398343629' resolved as dependency of
	component 'Microsoft.AspNetCore.Mvc.ApplicationModels.IPageApplicationModelProvider_47b77ab4-c4c0-4b1f-b306-1dd46aa082be' resolved as dependency of
	component 'Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.IPageLoader_930a8b19-9481-41d1-b412-9ba32a232960' resolved as dependency of
	component 'Microsoft.AspNetCore.Mvc.Abstractions.IActionInvokerProvider_8784d307-44bc-4edb-8a61-f3127ad49b79' resolved as dependency of
	component 'Microsoft.AspNetCore.Mvc.Infrastructure.IActionInvokerFactory_4961e9f6-9ade-4a98-9e3e-4de3f80bac3c' resolved as dependency of
	component 'Microsoft.AspNetCore.Mvc.Internal.MvcRouteHandler_d7531031-381e-4ff3-b56c-3568a38854a3' which is the root component being resolved.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:27 (13 by maintainers)

github_iconTop GitHub Comments

3reactions
hikalkancommented, Jul 5, 2018

Try this:

  1. Create AbpPropertiesDependenciesModelInspector class as shown below:
using Castle.Core;
using Castle.MicroKernel.ModelBuilder.Inspectors;
using Castle.MicroKernel.SubSystems.Conversion;

namespace Abp.Dependency
{
    public class AbpPropertiesDependenciesModelInspector : PropertiesDependenciesModelInspector
    {
        public AbpPropertiesDependenciesModelInspector(IConversionManager converter) 
            : base(converter)
        {
        }

        protected override void InspectProperties(ComponentModel model)
        {
            if (model.Implementation.FullName != null && 
                model.Implementation.FullName.StartsWith("Microsoft"))
            {
                return;
            }

            base.InspectProperties(model);
        }
    }
}
  1. Go to your Startup.cs, add following code in the services.AddAbp... options:
var propInjector = options.IocManager.IocContainer.Kernel.ComponentModelBuilder
    .Contributors
    .OfType<PropertiesDependenciesModelInspector>()
    .Single();

options.IocManager.IocContainer.Kernel.ComponentModelBuilder.RemoveContributor(propInjector);
options.IocManager.IocContainer.Kernel.ComponentModelBuilder.AddContributor(new AbpPropertiesDependenciesModelInspector(new DefaultConversionManager()));

See my commit for exact code: https://github.com/aspnetboilerplate/aspnetboilerplate/commit/1270e6766905994b69e1e2b8fe2d40ffeacb817d

If this works properly, we may include it into the framework. I know that Microsoft team ignores property injection, so the property injection shouldn’t work for Microsoft types.

0reactions
LeoZhwcommented, Jun 12, 2019

It works well. Thanks. 感谢大佬。 https://github.com/aspnetboilerplate/aspnetboilerplate/issues/3569#issuecomment-402738621

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

Castle.MicroKernel.CircularDependencyException #5614
Castle.MicroKernel.CircularDependencyException #5614 ... Dependency cycle has been detected when trying to resolve component 'Microsoft.
Read more >
Erroneous Circular Dependency exception - resolving ...
I am using a factory to resolve components in Castle Windsor (with arguments) and it works fine normally. However, the (transient) instance ...
Read more >
Problem with Castle Windsor resolution in ASP.NET Core
Castle Windsor allows us to decorate a property with a DoNotWire attribute that instructs the resolver to ignore this property.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found