serenity-is / Serenity

Business Apps Made Simple with Asp.Net Core MVC / TypeScript
https://serenity.is
MIT License
2.6k stars 802 forks source link

Error after generating code with sergen #2190

Closed gfo2007 closed 7 years ago

gfo2007 commented 7 years ago

Hello Volkan, I generated code with sergen on a table in the database called content_cat

After rebuilding the solution the project throws the error when running it:

System.Reflection.TargetInvocationException occurred HResult=0x80131604 Message=Exception has been thrown by the target of an invocation. Source=mscorlib StackTrace: at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) at System.Activator.CreateInstance(Type type, Boolean nonPublic) at System.Activator.CreateInstance(Type type) at Serenity.Data.RowRegistry.Initialize() at Serenity.Data.RowRegistry.EnsureRegistry() at Serenity.Data.RowRegistry.d__8.MoveNext() at Serenity.Localization.EntityLocalTexts.Initialize(String languageID, ILocalTextRegistry registry) at Serenity.Web.CommonInitialization.InitializeLocalTexts() at Serenity.Web.CommonInitialization.Run() at ppa.SiteInitialization.ApplicationStart() in J:\Visual Studio Projects\ppa\ppa\ppa.Web\App_Start\SiteInitialization.cs:line 37 at ppa.Global.Application_Start(Object sender, EventArgs e) in J:\Visual Studio Projects\ppa\ppa\ppa.Web\Global.asax.cs:line 26

Inner Exception 1: TypeInitializationException: The type initializer for 'ppa.MasterData.Entities.ContentCatRow' threw an exception.

Inner Exception 2: InvalidProgramException: Tablename in row type ContentCatRow can't be overridden by attribute!

PLEASE HELP

abelal83 commented 7 years ago

can you paste the code for ContentCatRow. From inner exception 2 it looks like you have a conflict of some sort.

gfo2007 commented 7 years ago

Hello Abelal, Below is the code

namespace ppa.MasterData.Entities { using Serenity; using Serenity.ComponentModel; using Serenity.Data; using Serenity.Data.Mapping; using System; using System.ComponentModel; using System.IO;

[ConnectionKey("Default"), TableName("[ppa2013sql].[content_cat]"), DisplayName("Content Cat"), InstanceName("Content Cat"), TwoLevelCached]
[ReadPermission("Administration:General")]
[ModifyPermission("Administration:General")]
public sealed class ContentCatRow : Row, IIdRow, INameRow
{
    [DisplayName("Id"), Column("cat_id"), Identity]
    public Int32? Id
    {
        get { return Fields.Id[this]; }
        set { Fields.Id[this] = value; }
    }

    [DisplayName("Name"), Column("cat_name"), Size(50), QuickSearch]
    public String Name
    {
        get { return Fields.Name[this]; }
        set { Fields.Name[this] = value; }
    }

    IIdField IIdRow.IdField
    {
        get { return Fields.Id; }
    }

    StringField INameRow.NameField
    {
        get { return Fields.Name; }
    }

    public static readonly RowFields Fields = new RowFields().Init();

    public ContentCatRow()
        : base(Fields)
    {
    }

    public class RowFields : RowFieldsBase
    {
        public Int32Field Id;
        public StringField Name;

        public RowFields()
            : base("cat_")
        {
            LocalTextPrefix = "MasterData.ContentCat";
        }
    }
}

}

abelal83 commented 7 years ago

just compared with one of mine, why do you have "cat_" within your :base ?

        public RowFields()
            : base("cat_")

try simply as

        public RowFields()
            : base()
gfo2007 commented 7 years ago

It was automatically generated by sergen. Thanks so much for your help. I am really grateful