私の Global.asax には以下のコードが含まれています。
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), new ContextConfiguration() { ScaffoldAllTables = true }); です。
完全なスタック トレース:
[ArgumentException: アイテムは既に追加されています。辞書のキー: 'APP.SQLAppModel.sEntities' 追加されるキー: 'APP.SQLAppModel.sEntities'] System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add) +9352427 System.Collections.Hashtable.Add(オブジェクト キー、オブジェクト値) +11 System.Web.DynamicData.MetaModelManager.AddModel(タイプ contextType、MetaModel モデル) +96 System.Web.DynamicData.MetaModel.RegisterContext(DataModelProvider dataModelProvider、ContextConfiguration 構成) +727 System.Web.DynamicData. MetaModel.RegisterContext(Func`1 contextFactory、ContextConfiguration 構成) +390 System.Web.DynamicData.MetaModel.RegisterContext(Type contextType、ContextConfiguration 構成) +88 SAMI.Global.RegisterRoutes(RouteCollection ルート) in C:\Anand\SAMI\SAMI \SAMI\Global.asax.cs:
これを修正する方法を教えてください。問題の特定に苦労しています。