The number of generic arguments provided doesn't equal the arity of the generic type definition.

Topics: Troubleshooting
Jan 3, 2012 at 12:36 PM

This is a bizarre error (and the message gives me no clues as to what is causing the problem).

Everything was working fine and then suddenly I just get this error no matter what I do. The models in the relevant modules have no 1:n mappings so I don't know why NHibernate is trying to map anything. Any advice as to what could cause this would be urgently appreciated. It's affecting me in both Orchard 1.3 and 1.x.

Error as follows:

Server Error in '/' Application.

The number of generic arguments provided doesn't equal the arity of the generic type definition.
Parameter name: instantiation

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.ArgumentException: The number of generic arguments provided doesn't equal the arity of the generic type definition.
Parameter name: instantiation

Source Error: 

Line 21:             var persistenceModel = CreatePersistenceModel(parameters.RecordDescriptors);
Line 22: 
Line 23:             return Fluently.Configure()
Line 24:                 .Database(database)
Line 25:                 .Mappings(m => m.AutoMappings.Add(persistenceModel))


Source File: G:\Orchard\1.3\src\Orchard\Data\Providers\AbstractDataServicesProvider.cs    Line: 23 

Stack Trace: 

[ArgumentException: The number of generic arguments provided doesn't equal the arity of the generic type definition.
Parameter name: instantiation]
   System.RuntimeType.MakeGenericType(Type[] instantiation) +9486773
   FluentNHibernate.Automapping.AutoMapManyToMany.GetInverseProperty(PropertyInfo property) in E:\BitBucket\FluentGit\fluent-nhibernate\src\FluentNHibernate\Automapping\AutoMapManyToMany.cs:33
   FluentNHibernate.Automapping.AutoMapManyToMany.MapsProperty(PropertyInfo property) in E:\BitBucket\FluentGit\fluent-nhibernate\src\FluentNHibernate\Automapping\AutoMapManyToMany.cs:27
   FluentNHibernate.Automapping.AutoMapper.TryToMapProperty(ClassMappingBase mapping, PropertyInfo property, IList`1 mappedProperties) in E:\BitBucket\FluentGit\fluent-nhibernate\src\FluentNHibernate\Automapping\AutoMapper.cs:136
   FluentNHibernate.Automapping.AutoMapper.MapEverythingInClass(ClassMappingBase mapping, Type entityType, IList`1 mappedProperties) in E:\BitBucket\FluentGit\fluent-nhibernate\src\FluentNHibernate\Automapping\AutoMapper.cs:126
   FluentNHibernate.Automapping.AutoMapper.MergeMap(Type classType, ClassMappingBase mapping, IList`1 mappedProperties) in E:\BitBucket\FluentGit\fluent-nhibernate\src\FluentNHibernate\Automapping\AutoMapper.cs:54
   FluentNHibernate.Automapping.AutoMapper.Map(Type classType, List`1 types) in E:\BitBucket\FluentGit\fluent-nhibernate\src\FluentNHibernate\Automapping\AutoMapper.cs:158
   FluentNHibernate.Automapping.AutoPersistenceModel.AddMapping(Type type) in E:\BitBucket\FluentGit\fluent-nhibernate\src\FluentNHibernate\Automapping\AutoPersistenceModel.cs:137
   FluentNHibernate.Automapping.AutoPersistenceModel.CompileMappings() in E:\BitBucket\FluentGit\fluent-nhibernate\src\FluentNHibernate\Automapping\AutoPersistenceModel.cs:111
   FluentNHibernate.Cfg.AutoMappingsContainer.Apply(Configuration cfg) in E:\BitBucket\FluentGit\fluent-nhibernate\src\FluentNHibernate\Cfg\AutoMappingsContainer.cs:66
   FluentNHibernate.Cfg.MappingConfiguration.Apply(Configuration cfg) in E:\BitBucket\FluentGit\fluent-nhibernate\src\FluentNHibernate\Cfg\MappingConfiguration.cs:56
   FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration() in E:\BitBucket\FluentGit\fluent-nhibernate\src\FluentNHibernate\Cfg\FluentConfiguration.cs:110

[FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.

]
   FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration() in E:\BitBucket\FluentGit\fluent-nhibernate\src\FluentNHibernate\Cfg\FluentConfiguration.cs:119
   Orchard.Data.Providers.AbstractDataServicesProvider.BuildConfiguration(SessionFactoryParameters parameters) in G:\Orchard\1.3\src\Orchard\Data\Providers\AbstractDataServicesProvider.cs:23
   Orchard.Data.<>c__DisplayClass3.<BuildConfiguration>b__2() in G:\Orchard\1.3\src\Orchard\Data\SessionFactoryHolder.cs:94
   Orchard.Data.SessionConfigurationCache.GetConfiguration(Func`1 builder) in G:\Orchard\1.3\src\Orchard\Data\SessionConfigurationCache.cs:51
   Orchard.Data.SessionFactoryHolder.BuildConfiguration() in G:\Orchard\1.3\src\Orchard\Data\SessionFactoryHolder.cs:93
   Orchard.Data.SessionFactoryHolder.GetConfiguration() in G:\Orchard\1.3\src\Orchard\Data\SessionFactoryHolder.cs:71
   Orchard.Data.SessionFactoryHolder.BuildSessionFactory() in G:\Orchard\1.3\src\Orchard\Data\SessionFactoryHolder.cs:83
   Orchard.Data.SessionFactoryHolder.GetSessionFactory() in G:\Orchard\1.3\src\Orchard\Data\SessionFactoryHolder.cs:62
   Orchard.Data.SessionLocator.For(Type entityType) in G:\Orchard\1.3\src\Orchard\Data\SessionLocator.cs:29
   Orchard.Data.Repository`1.get_Session() in G:\Orchard\1.3\src\Orchard\Data\Repository.cs:26
   Orchard.Data.Repository`1.get_Table() in G:\Orchard\1.3\src\Orchard\Data\Repository.cs:30
   Orchard.Data.Repository`1.Fetch(Expression`1 predicate) in G:\Orchard\1.3\src\Orchard\Data\Repository.cs:126
   Orchard.Data.Repository`1.Get(Expression`1 predicate) in G:\Orchard\1.3\src\Orchard\Data\Repository.cs:91
   Orchard.Data.Repository`1.Orchard.Data.IRepository<T>.Get(Expression`1 predicate) in G:\Orchard\1.3\src\Orchard\Data\Repository.cs:60
   Orchard.Core.Settings.Descriptor.ShellDescriptorManager.GetDescriptorRecord() in G:\Orchard\1.3\src\Orchard.Web\Core\Settings\Descriptor\ShellDescriptorManager.cs:57
   Orchard.Core.Settings.Descriptor.ShellDescriptorManager.GetShellDescriptor() in G:\Orchard\1.3\src\Orchard.Web\Core\Settings\Descriptor\ShellDescriptorManager.cs:30
   Orchard.Environment.ShellBuilders.ShellContextFactory.CreateShellContext(ShellSettings settings) in G:\Orchard\1.3\src\Orchard\Environment\ShellBuilders\ShellContextFactory.cs:66
   Orchard.Environment.DefaultOrchardHost.CreateShellContext(ShellSettings settings) in G:\Orchard\1.3\src\Orchard\Environment\DefaultOrchardHost.cs:168
   Orchard.Environment.DefaultOrchardHost.CreateAndActivateShells() in G:\Orchard\1.3\src\Orchard\Environment\DefaultOrchardHost.cs:132
   Orchard.Environment.DefaultOrchardHost.BuildCurrent() in G:\Orchard\1.3\src\Orchard\Environment\DefaultOrchardHost.cs:103
   Orchard.Environment.DefaultOrchardHost.Orchard.Environment.IOrchardHost.Initialize() in G:\Orchard\1.3\src\Orchard\Environment\DefaultOrchardHost.cs:67
   Orchard.Web.MvcApplication.HostInitialization(HttpApplication application) in G:\Orchard\1.3\src\Orchard.Web\Global.asax.cs:48
   Orchard.WarmupStarter.<>c__DisplayClass3.<LaunchStartupThread>b__2(Object state) in G:\Orchard\1.3\src\Orchard.Startup\Starter.cs:89

[ApplicationException: Error during application initialization]
   Orchard.WarmupStarter.Starter`1.OnBeginRequest(HttpApplication application) in G:\Orchard\1.3\src\Orchard.Startup\Starter.cs:63
   Orchard.Web.MvcApplication.Application_BeginRequest() in G:\Orchard\1.3\src\Orchard.Web\Global.asax.cs:29

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
   System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner) +0
   System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner) +72
   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) +335
   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +28
   System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) +19
   System.Web.Util.ArglessEventHandlerProxy.Callback(Object sender, EventArgs e) +57
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +148
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75

My records:

    public class PaymentRecord {

        public PaymentRecord() {
        }

        public virtual long Id { get; set; }
        public virtual string Reference { get; set; }
        public virtual double Amount { get; set; }
        /// 
        /// Custom XML data relating to payment
        /// 
        [StringLengthMax]
        public virtual string PaymentData { get; set; }

        #region Auditing

        public virtual DateTime CreatedUtc { get; set; }
        public virtual DateTime? ConfirmedUtc { get; set; }

        /// 
        /// Name of gateway used to complete the payment
        /// 
        public virtual string GatewayName { get; set; }
        /// 
        /// Additional XML data from gateway
        /// 
        [StringLengthMax]
        public virtual string GatewayData { get; set; }

        #endregion

        public virtual bool Confirmed { get; set; }
    }

    public class PaymentSiteSettingsPartRecord :    ContentPartRecord {

        public PaymentSiteSettingsPartRecord() {
            DefaultCurrencyCode = "USD";
            DefaultCurrencyFormat = "$ {0:0.00}";
        }

        [StringLength(3)]
        public virtual string DefaultCurrencyCode { get; set; }
        [StringLength(255)]
        public virtual string DefaultCurrencyFormat { get; set; }

    }

Migrations:

    public class Migrations : DataMigrationImpl {

        public int Create() {
            SchemaBuilder.CreateTable("PaymentSiteSettingsPartRecord", table => table
                .ContentPartRecord()
                .Column<string>("DefaultCurrencyCode",col=>col.WithType(DbType.StringFixedLength).WithLength(3))
                .Column<string>("DefaultCurrencyFormat", col => col.WithLength(255))
                );
            SchemaBuilder.CreateTable("PaymentRecord", table => table
                .Column<long>("Id", col => col.Identity().PrimaryKey())
                .Column<String>("Reference", col => col.WithLength(255))
                .Column<double>("Amount", col => col.WithPrecision(16))
                .Column<string>("PaymentData", col => col.Unlimited())
                .Column<DateTime>("CreatedUtc")
                .Column<DateTime>("ConfirmedUtc")
                .Column<string>("GatewayName", col => col.WithLength(255))
                .Column<string>("GatewayData", col => col.Unlimited())
                .Column<bool>("Confirmed")
                );

            return 1;
        }
    }

What on earth is wrong here?

Jan 3, 2012 at 12:56 PM

Figured it out; I had a class in my Models folder that just happened to have an Id property, even tho it wasn't supposed to be DB-persisted, NHibernate was trying to map it anyway.