TypeInitializationException: The type initializer for 'System.Data.Entity.ModelConfiguration.Utilities.TypeExtensions' threw an exception

Jun 13, 2013 at 5:06 AM
Hi,
When i run jqGrid and ASP.NET MVC – Form Editing with TinyMCE and file upload project i go the following exception

I also must mention that i install VS2012,but i open project with VS2010.
Server Error in '/' Application.

An item with the same key has already been added.

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: An item with the same key has already been added.

Source Error: 


Line 12:     {
Line 13:         #region Fields
Line 14:         private NorthwindContext _context = new NorthwindContext();
Line 15:         #endregion
Line 16: 

Source File: D:\Projects\z_Samples\ASP.NETMVC\jqGrid in ASP.NET MVC – Editing, TinyMCE, Upload\jqGrid and ASP.NET MVC – Form Editing with TinyMCE and file upload\Northwind.Repositories.Entity\EmployeesRepository.cs    Line: 14 

Stack Trace: 


[ArgumentException: An item with the same key has already been added.]
   System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) +52
   System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) +350
   System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value) +10
   System.Data.Entity.ModelConfiguration.Utilities.TypeExtensions..cctor() +215

[TypeInitializationException: The type initializer for 'System.Data.Entity.ModelConfiguration.Utilities.TypeExtensions' threw an exception.]
   System.Data.Entity.ModelConfiguration.Utilities.TypeExtensions.IsValidStructuralType(Type type) +0
   System.Data.Entity.Internal.DbSetDiscoveryService.GetSets() +742
   System.Data.Entity.Internal.DbSetDiscoveryService.InitializeSets() +49
   System.Data.Entity.DbContext.DiscoverAndInitializeSets() +61
   System.Data.Entity.DbContext.InitializeLazyInternalContext(IInternalConnection internalConnection, DbModel model) +84
   System.Data.Entity.DbContext..ctor() +113
   Northwind.Repositories.Entity.NorthwindContext..ctor() +42
   Northwind.Repositories.Entity.EmployeesRepository..ctor() in D:\Projects\z_Samples\ASP.NETMVC\jqGrid in ASP.NET MVC – Editing, TinyMCE, Upload\jqGrid and ASP.NET MVC – Form Editing with TinyMCE and file upload\Northwind.Repositories.Entity\EmployeesRepository.cs:14
   jqGrid.DungDepTrai.Controllers.HomeController..ctor() in D:\Projects\z_Samples\ASP.NETMVC\jqGrid in ASP.NET MVC – Editing, TinyMCE, Upload\jqGrid and ASP.NET MVC – Form Editing with TinyMCE and file upload\jqGrid.DungDepTrai\Controllers\HomeController.cs:23
Coordinator
Jun 14, 2013 at 8:18 PM
Hi,

The project is a little bit outdated and may not work with current version of Entity Framework. I will look into this over weekend.

Regards,
Tomasz Pęczek
Jun 15, 2013 at 3:53 AM
Thanks TPeczek,
I have updated EntityFramework.dll to 5.0 in project "Northwind.Repositories.Entity" and also in class NorthwindContext.cs change ModelBuilder to DbModelBuilder
and add System.Data.Entity reference to project "Northwind.Repositories.Entity" and project runs successfully.