I'm using

VS2013 MVC5, SimpleInjector 2.4.1 MvcSiteMapProvider.MVC5.DI.SimpleInjector.Modules 4.4.10

and I'm getting the following error when calling 'Verify' on the container

Additional information: The configuration is invalid. Creating the instance for type IAttributeAssemblyProvider failed. The registered delegate for type IAttributeAssemblyProvider threw an exception. The constructor of the type AttributeAssemblyProvider contains the parameter of type IEnumerable<String> with name 'includeAssemblies' that is not registered. Please ensure IEnumerable<String> is registered in the container, or change the constructor of AttributeAssemblyProvider.

The array it is referencing is :

string[] includeAssembliesForScan = new string[] { "MyProject" };

and this is what seems to be the culprit :

        container.RegisterSingle<ReflectionSiteMapNodeProvider>(() => 
            container.GetInstance<ReflectionSiteMapNodeProviderFactory>()
            .Create(includeAssembliesForScan));

The signature for the create method is :

public MvcSiteMapProvider.Builder.ReflectionSiteMapNodeProvider Create(System.Collections.Generic.IEnumerable<string> includeAssemblies)
    Member of MvcSiteMapProvider.Builder.ReflectionSiteMapNodeProviderFactory

I think the IAttributeAssemblyProvider is being registered as per below

// Single implementations of interface with matching name (minus the "I").
            CommonConventions.RegisterDefaultConventions(
                (interfaceType, implementationType) => container.RegisterSingle(interfaceType, implementationType),
                new Assembly[] { siteMapProviderAssembly },
                allAssemblies,
                excludeTypes,
                string.Empty);

since :

  public class AttributeAssemblyProvider  : IAttributeAssemblyProvider

and the ctor is :

public AttributeAssemblyProvider(
            IEnumerable<string> includeAssemblies,
            IEnumerable<string> excludeAssemblies)
        {...}

Thanks in advance for any help

stack trace is :

at SimpleInjector.InstanceProducer.VerifyExpressionBuilding() at SimpleInjector.Container.VerifyIfAllExpressionsCanBeBuilt(InstanceProducer[] producersToVerify) at SimpleInjector.Container.VerifyIfAllExpressionsCanBeBuilt() at SimpleInjector.Container.Verify() at MyProject.App_Start.SimpleInjectorInitializer.Intialise() in \App_Start\SimpleInjectorInitializer.cs:line 54 at MyProject.MvcApplication.Application_Start() in \Global.asax.cs:line 16

有帮助吗?

解决方案

The latest versions of the external DI config files don't automatically update when you upgrade if you have changed them. Be sure you have merged in the latest versions of CommonConventions.cs and MvcSiteMapProviderContainerInitializer.cs from the master branch (this is to be done manually, but it helps a lot if you use a diff tool to quickly see the changes). You can also view the releases list to see the various points where updates were done to the DI configuration with direct links to the diff on GitHub.

The latest version of CommonConventions.RegisterDefaultConventions excludes auto-registration of any types that have a string parameter in the constructor (which AttributeAssemblyProvider does), so be sure you have merged the latest changes of that file into your project.

Of course, if all else fails you can add typeof(AttributeAssemblyProvider) to the excludeTypes array and it will no longer be auto-registered. It is not supposed to be because it has a factory class that instantiates it named AttributeAssemblyProviderFactory.

Also, if you are not using MvcSiteMapNodeAttribute to register nodes, it is not necessary to have it in your configuration at all. Removing it will make your SiteMap load a little faster.

To remove it, change this...

container.RegisterSingle<ReflectionSiteMapNodeProvider>(() => container.GetInstance<ReflectionSiteMapNodeProviderFactory>()
    .Create(includeAssembliesForScan));

// Register the sitemap builders
container.RegisterSingle<ISiteMapBuilder>(() => container.GetInstance<SiteMapBuilderFactory>()
    .Create(new CompositeSiteMapNodeProvider(container.GetInstance<XmlSiteMapNodeProvider>(), container.GetInstance<ReflectionSiteMapNodeProvider>())));

To this...

// Register the sitemap builders
container.RegisterSingle<ISiteMapBuilder>(() => container.GetInstance<SiteMapBuilderFactory>()
    .Create(container.GetInstance<XmlSiteMapNodeProvider>()));

This is exactly what the "MvcSiteMapProvider_ScanAssembliesForSiteMapNodes" web.config setting does when set to "false" when you are using the internal DI container.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top