Search code examples
c#-4.0entity-framework-6.net-framework-version

Entity Framework 6: Schema specified is not valid


I have 4 following projects in my solution. All the projects use target framework version 4.0.

  • 1. Durabuilt.CantorERP.Entities > Class library project > Used ADO.NET Entity Data Model to expose tables and views in SQL Database named CantorERP
  • 2. Durabuilt.Duranet2.Entities > Class library project > Used ADO.NET Entity Data Model to expose tables in SQL Database named DuranetTest
  • 3. Durabuilt.Duranet2.BL > Class library project > Contains business logic and references both of the above Entities projects for CRUD operations. All logic including CRUD resides in this project.
  • 4. Durabuilt.Duranet2.UI > It is a website which is the UI and references Durabuilt.Duranet2.BL project.

SQL Server version is 2005. Both the Databases CantorERP and DuranetTest reside on a database server. I connect to the database server from my development machine.

Everything works fine on my development machine. When I deploy the UI project to our hosting server (Windows 2003 SP2 running IIS6 .net version 4.0). There are following three pages (~/RAF/Common/NoChargeSearch.aspx, ~/RAF/Common/RAFSearch.aspx, ~RAF/Sales/CreateNoCharge.aspx) in my UI project that give me error mentioned below.

Server Error in '/' Application.
Schema specified is not valid. Errors: 
Duranet2Model.csdl(2,9) : warning 0005: Could not find schema information for the attribute 'Namespace'.
Duranet2Model.csdl(2,35) : warning 0005: Could not find schema information for the attribute 'Alias'.
Duranet2Model.csdl(2,48) : error 0005: The 'http://schemas.microsoft.com/ado/2009/02/edm/annotation:UseStrongSpatialTypes' attribute is not declared.
Duranet2Model.csdl(2,2) : error 0010: The element Schema in namespace http://schemas.microsoft.com/ado/2009/11/edm was unexpected for the root element. The expected Schema in one of the following namespaces: http://schemas.microsoft.com/ado/2006/04/edm, http://schemas.microsoft.com/ado/2007/05/edm, http://schemas.microsoft.com/ado/2008/09/edm.

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.Data.MetadataException: Schema specified is not valid. Errors: 
Duranet2Model.csdl(2,9) : warning 0005: Could not find schema information for the attribute 'Namespace'.
Duranet2Model.csdl(2,35) : warning 0005: Could not find schema information for the attribute 'Alias'.
Duranet2Model.csdl(2,48) : error 0005: The 'http://schemas.microsoft.com/ado/2009/02/edm/annotation:UseStrongSpatialTypes' attribute is not declared.
Duranet2Model.csdl(2,2) : error 0010: The element Schema in namespace http://schemas.microsoft.com/ado/2009/11/edm was unexpected for the root element. The expected Schema in one of the following namespaces: http://schemas.microsoft.com/ado/2006/04/edm, http://schemas.microsoft.com/ado/2007/05/edm, http://schemas.microsoft.com/ado/2008/09/edm.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 


[MetadataException: Schema specified is not valid. Errors: 
Duranet2Model.csdl(2,9) : warning 0005: Could not find schema information for the attribute 'Namespace'.
Duranet2Model.csdl(2,35) : warning 0005: Could not find schema information for the attribute 'Alias'.
Duranet2Model.csdl(2,48) : error 0005: The 'http://schemas.microsoft.com/ado/2009/02/edm/annotation:UseStrongSpatialTypes' attribute is not declared.
Duranet2Model.csdl(2,2) : error 0010: The element Schema in namespace http://schemas.microsoft.com/ado/2009/11/edm was unexpected for the root element. The expected Schema in one of the following namespaces: http://schemas.microsoft.com/ado/2006/04/edm, http://schemas.microsoft.com/ado/2007/05/edm, http://schemas.microsoft.com/ado/2008/09/edm.]
   System.Data.Metadata.Edm.EdmItemCollection.LoadItems(IEnumerable`1 xmlReaders, IEnumerable`1 sourceFilePaths, SchemaDataModelOption dataModelOption, DbProviderManifest providerManifest, ItemCollection itemCollection, Boolean throwOnError) +8617673
   System.Data.Metadata.Edm.EdmItemCollection.Init(IEnumerable`1 xmlReaders, IEnumerable`1 filePaths, Boolean throwOnError) +139
   System.Data.Metadata.Edm.EdmItemCollection..ctor(IEnumerable`1 xmlReaders, IEnumerable`1 filePaths) +158
   System.Data.Metadata.Edm.EdmMetadataEntry.LoadEdmItemCollection(MetadataArtifactLoader loader) +90
   System.Data.Metadata.Edm.EdmItemCollectionLoader.LoadItemCollection(EdmMetadataEntry entry) +12
   System.Data.Metadata.Edm.MetadataCache.LoadItemCollection(IItemCollectionLoader`1 itemCollectionLoader, T entry) +149
   System.Data.Metadata.Edm.MetadataCache.GetOrCreateEdmItemCollection(String cacheKey, MetadataArtifactLoader loader, Object& entryToken) +141
   System.Data.EntityClient.EntityConnection.LoadEdmItemCollection(MetadataWorkspace workspace, MetadataArtifactLoader artifactLoader) +103
   System.Data.EntityClient.EntityConnection.GetMetadataWorkspace(Boolean initializeAllCollections) +369
   System.Data.Objects.ObjectContext.RetrieveMetadataWorkspaceFromConnection() +29
   System.Data.Objects.ObjectContext..ctor(EntityConnection connection, Boolean isConnectionConstructor) +205
   System.Data.Objects.ObjectContext..ctor(String connectionString) +23
   System.Web.UI.WebControls.EntityDataSourceView.ConstructContext() +467
   System.Web.UI.WebControls.EntityDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +76
   System.Web.UI.WebControls.ListControl.OnDataBinding(EventArgs e) +97
   System.Web.UI.WebControls.ListControl.PerformSelect() +34
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +74
   System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +66
   System.Web.UI.WebControls.ListControl.OnPreRender(EventArgs e) +29
   System.Web.UI.Control.PreRenderRecursiveInternal() +103
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2496

All other pages in the project work fine including the ones in same directories e.g. ~/RAF/Common/NoCharge.aspx, ~/RAF/Common/RAF.aspx, ~RAF/Sales/CreateRAF.aspx. Interestingly ~/RAF/Common/RAFSearch.aspx uses a method called GetTopNRafs() inside a class called RAFSearch.cs to display data on page load and it does not work. Another page ~/RAF/Sales/raf_pending_requests.aspx uses GetRafsByStatus() method inside same class RAFSearch.cs to display data on page load and it works. Both methods get the data from DuranetTest DB using Durabuilt.Duranet2.Entities project and return List<RAF>.

I have made sure that both my Entities project and UI project have same version of EntityFramework (version 6.1.3).

I've tried removing and recreating the .edmx files in both Durabuilt.CantorERP.Entities and Durabuilt.Duranet2.Entities projects. I've tried deleting all tables and views from edmx and used option of "update model from Database" and re-added tables and views. I've also deleted and recreated both Durabuilt.CantorERP.Entities and Durabuilt.Duranet2.Entities projects. Not sure if I'm missing any critical information. Please let me know if additional info is needed and I can add the info as requested.

I've read various articles with similar issues and upgrading the server to .net version 4.5 has seemed to solve the issue. But I currently do not have that option to upgrade .net version nor can I install SP3 on the server as it is running some other applications that would break. Kindly let me know what can be done to fix this error. Appreciate your help.

Connection strings as requested:

<connectionStrings>
   <add name="CANTORERPConnectionString" connectionString="Data Source=CANTORSERVER;Initial Catalog=CANTORERP;Integrated Security=False; User Id=XXXXXX; password=XXXXXX" providerName="System.Data.SqlClient" />
   <add name="CantorERPEntities" connectionString="metadata=res://*/CantorERPModel.csdl|res://*/CantorERPModel.ssdl|res://*/CantorERPModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=CANTORSERVER;initial catalog=CANTORERP;persist security info=True;user id=XXXXXX;password=XXXXXX;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
   <add name="DURANET2Entities" connectionString="metadata=res://*/Duranet2Model.csdl|res://*/Duranet2Model.ssdl|res://*/Duranet2Model.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=CANTORSERVER;initial catalog=DURANETTEST;persist security info=True;user id=XXXXXX;password=XXXXXX;multipleactiveresultsets=True;application name=EntityFramework&quot;" providerName="System.Data.EntityClient" />
</connectionStrings>

I use CANTORERPConnectionString to run direct SQL queries against the DB. And both CantorERPEntities and DURANET2Entities are connection strings used by the Entities projects.


Solution

  • Ok so here is what solved it for me. Posting this as it could help others who might run into same error.

    The three pages (where this error was coming on page load) had drop down controls. Each of these drop down controls was bound to a database table using Entity data source like so:

    <asp:DropDownList ID="ddlStatus" runat="server" DataSourceID="EDS_Status" DataTextField="Status" DataValueField="Id"></asp:DropDownList>
    <asp:EntityDataSource runat="server" ID="EDS_Status" DefaultContainerName="DURANET2Entities" ConnectionString="name=DURANET2Entities" EnableFlattening="False" EntitySetName="RAFStatuses" Select="it.[Id], it.[Status]"></asp:EntityDataSource>
    

    This is what was causing the error in my case. Somehow on page load when control was binding, this error got generated. This worked on the dev environment, but would cause the error on server (Windows 2003 SP2, IIS6, .NET Framework 4.0) and that is why it was hard to troubleshoot.

    Just by changing the data source to SQL Data source, the problem was solved. Like so:

    asp:DropDownList ID="ddlStatus" runat="server" DataSourceID="SqlDataSource1" DataTextField="Status" DataValueField="Id"></asp:DropDownList>
    <asp:SqlDataSource runat="server" ID="SqlDataSource1" ConnectionString='<%$ ConnectionStrings:DURANETConnectionString %>' SelectCommand="SELECT [Id], [Status] FROM [RAFStatuses] ORDER BY [Id]"></asp:SqlDataSource>
    

    Let me know if anybody would need additional details.