Wednesday, May 14, 2014

Could not load type System.Data.Entity.DynamicProxies

Server Error in '/' Application.

Could not load type 'System.Data.Entity.DynamicProxies.Employees_31D5D8E22BDA1BDE7633258E0B872E10BE53EA325E44C778D3924FDEDFBCE14F' from assembly 'EntityFrameworkDynamicProxies-CTS, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.

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.TypeLoadException: Could not load type 'System.Data.Entity.DynamicProxies.Employees_31D5D8E22BDA1BDE7633258E0B872E10BE53EA325E44C778D3924FDEDFBCE14F' from assembly 'EntityFrameworkDynamicProxies-CTS, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.



Solution:

In your entity datasource, set the value EnableFlattening="False"

Example:

<asp:EntityDataSource ID="EntityDataSource1" runat="server"  ConnectionString="name=XXXXXEntities" DefaultContainerName="XXXXXEntities" EnableFlattening="False" EntitySetName="Employees" Include="Nationalities,Locations" EntityTypeFilter="Employees" OrderBy="it.[EmployeeID]">

</asp:EntityDataSource>