首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >异常“项目已被添加。”在MetaModel.Register中

异常“项目已被添加。”在MetaModel.Register中
EN

Stack Overflow用户
提问于 2011-10-21 23:09:29
回答 1查看 975关注 0票数 2

我的Global.asax包含以下代码:

代码语言:javascript
复制
public class Global : System.Web.HttpApplication
    {
        private MetaModel _s_Model = new AdvancedMetaModel();
        public MetaModel s_Model
        {
            get
            {
                return _s_Model;
            }
        }

        private MetaModel _a_Model = new AdvancedMetaModel();
        public MetaModel a_Model
        {
            get
            {
                return _a_Model;
            }
        }

        public void RegisterRoutes(RouteCollection routes)
        {
            Dictionary<Helper.ModelName, MetaModel> registeredRoutes = new Dictionary<Helper.ModelName, MetaModel>();

            if (SQLAppModel.ModelQuery.GetUserType() == Utility.Helper.UserType.ApplicationAdmin
                || SQLAppModel.ModelQuery.GetUserType() == Utility.Helper.UserType.SystemAdmin)
            {
                _a_Model.RegisterContext(typeof(SQLAppModel.aEntities), new ContextConfiguration() { ScaffoldAllTables = true });

                /** Full Permission **/
                routes.Add(new DynamicDataRoute("{table}/ListDetails.aspx")
                {
                    Action = PageAction.List,
                    ViewName = "ListDetails",
                    Model = a_Model
                });

                routes.Add(new DynamicDataRoute("{table}/ListDetails.aspx")
                {
                    Action = PageAction.Details,
                    ViewName = "ListDetails",
                    Model = a_Model
                });

                registeredRoutes.Add(Helper.ModelName.Administration, a_Model);
            }

            string supportedEnvironments = System.Configuration.ConfigurationManager.AppSettings[Helper.SupportedEnvironmentsAppSettingsKey].ToString();

            foreach (string supportedEnvironment in supportedEnvironments.Split(','))
            {

                foreach (var supportedSystem in SQLAppModel.ModelQuery.GetSupportedSystems(supportedEnvironment, true))
                {
                    if (supportedEnvironment.ToUpper() == "ORACLE")
                    {
                        if (supportedSystem.Name.ToUpper() == "ADS")
                        {
                            _s_model.RegisterContext(typeof(OracleAppModel.sEntities), new ContextConfiguration()
                            {
                                ScaffoldAllTables = true
                            });

                            routes.Add(new DynamicDataRoute("{table}/ReadOnlyListDetails.aspx")
                            {
                                Action = PageAction.List,
                                ViewName = "ReadOnlyListDetails",
                                Model = s_model
                            });

                            routes.Add(new DynamicDataRoute("{table}/ReadOnlyListDetails.aspx")
                            {
                                Action = PageAction.Details,
                                ViewName = "ReadOnlyListDetails",
                                Model = s_model
                            });
                            registeredRoutes.Add(Helper.ModelName.ADS, s_model);
                        }
                    }
                }

            HttpContext.Current.Session[Helper.RegisteredRouteListSessionKey] = registeredRoutes;
        }

        void Application_Start(object sender, EventArgs e)
        {

        }

        void Session_Start(object sender, EventArgs e)
        {
            SQLAppModel.ModelQuery.GetApplicationUser();
            RegisterRoutes(RouteTable.Routes);
        }
    }

当我第一次使用ASP.NET开发web服务器调试我的应用程序时,该应用程序运行良好,并给出了预期的结果。

但当我停止调试并再次启动它时,它给出了以下异常:

已添加项目。字典中的键:要添加的'APP.SQLAppModel.sEntities‘键:'APP.SQLAppModel.sEntities’

抛出此异常的行是_a_Model.RegisterContext(typeof(SQLAppModel.aEntities),ContextConfiguration() { ScaffoldAllTables = true });

完成堆栈跟踪:

ArgumentException:已添加项。字典中的键:正在添加的‘System.Web.DynamicData.MetaModel.RegisterContext(DataModelProvider’键:'APP.SQLAppModel.sEntities‘System.Collections.Hashtable.Insert(对象键,对象n值,布尔加法) +9352427 System.Collections.Hashtable.Add(对象键,对象值) +11 System.Web.DynamicData.MetaModelManager.AddModel(Type contextType,MetaModel型号) +96 System.Web.DynamicData.MetaModel.RegisterContext(Func`1 dataModelProvider,ContextConfiguration配置)+727value contextFactory,ContextConfiguration配置) +390 System.Web.DynamicData.MetaModel.RegisterContext(Type contextFactory,ContextConfiguration contextType,ContextConfiguration配置) +8955827 System.Web.SessionState.SessionStateModule.CompleteAcquireState() +148 System.Web.SessionState.SessionStateModule.BeginAcquireState(Object源,EventArgs e,AsyncCallback cb,C:\Anand\SAMI\Global.asax.cs:137 SAMI.Global.Session_Start(对象发送者,EventArgs e)中的C:\Anand\SAMI\Global.asax.cs:137路由(EventArgs路由),对象步长) +561 System.Web.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +96 System.Web.HttpApplication.ExecuteStep(IExecutionStep extraData,布尔值& completedSynchronously) +184

请让我知道如何解决这个问题。我很难发现问题所在。

EN

回答 1

Stack Overflow用户

发布于 2011-10-22 00:44:14

问题是您从Session_Start调用RegisterRoutes,因此它可能会被多次调用。您需要从Application_Start调用它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7851440

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档