ledcomp
ledcomp

Reputation: 53

ASP + EF loading assembly problem

I have a big problem. When I'm running asp SOMETIMES the application is craching with the following error message:

Schema specified is not valid. Errors: The types in the assembly 'Data.EF, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' cannot be loaded because the assembly contains the EdmSchemaAttribute, and the closure of types is being loaded by name. Loading by both name and attribute is not allowed.

Stack Trace:

[MetadataException: Schema specified is not valid. Errors: The types in the assembly 'Data.EF, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' cannot be loaded because the assembly contains the EdmSchemaAttribute, and the closure of types is being loaded by name. Loading by both name and attribute is not allowed.]
System.Data.Metadata.Edm.ObjectItemCollection.LoadAssemblyFromCache(ObjectItemCollection objectItemCollection, Assembly assembly, Boolean loadReferencedAssemblies, EdmItemCollection edmItemCollection, Action1 logLoadMessage) +480
System.Data.Metadata.Edm.ObjectItemCollection.ExplicitLoadFromAssembly(Assembly assembly, EdmItemCollection edmItemCollection, Action
1 logLoadMessage) +53
System.Data.Metadata.Edm.MetadataWorkspace.ExplicitLoadFromAssembly(Assembly assembly, ObjectItemCollection collection, Action1 logLoadMessage) +93 System.Data.Metadata.Edm.MetadataWorkspace.LoadFromAssembly(Assembly assembly, Action1 logLoadMessage) +130 System.Web.UI.WebControls.EntityDataSourceView.ConstructContext() +585 System.Web.UI.WebControls.EntityDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +76
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +21 System.Web.UI.WebControls.DataBoundControl.PerformSelect() +143 Telerik.Web.UI.GridTableView.PerformSelect() +38 System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +74 Telerik.Web.UI.GridTableView.DataBind() +363 Telerik.Web.UI.RadGrid.DataBind() +173 System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +66 System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +75 System.Web.UI.Control.EnsureChildControls() +102 Telerik.Web.UI.GridBaseDataList.get_Controls() +33 Telerik.Web.UI.RadAjaxControl.PopulatePlainPanels(Control parent, List`1 list, Control root) +119 Telerik.Web.UI.RadAjaxControl.OnPagePreRender(Object sender, EventArgs e) +1802
System.EventHandler.Invoke(Object sender, EventArgs e) +0
System.Web.UI.Control.OnPreRender(EventArgs e) +8864486
System.Web.UI.Control.PreRenderRecursiveInternal() +103 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2496

I also added LoadFromAssembly before every context call and still the same problem.

context.MetadataWorkspace.LoadFromAssembly(context.GetType().Assembly);

Enviroment: VS 2010, .NET 4.0, C#, EF

Could please somebody help me, to fix this issue?

Thanks in advance,

Best regards.

Upvotes: 2

Views: 4483

Answers (4)

user2703177
user2703177

Reputation: 41

I was getting the same error for days. I using was a mixture of EntityDataSource objects and other data access such as ObjectDataSource in the same page. Replaced the EntityDataSource objects with ObjectDataSource. Problem went away!

Upvotes: 0

crimbo
crimbo

Reputation: 11201

I was seeing the same error message, using EF 5.0 and WCF Data Services 5.2.0. This was a data service using a DbContext-derived class.

The fix for me was to separate code-first EF code from model-first EF code. By moving the code-first code into a separate assembly, the error message went away and things are working. The only way I was able to figure out to try this, is that the [EdmSchema] attribute exists on the code generated from our EDMX; but it doesn't exist on our model (code-first) code.

Hope that helps someone...

Upvotes: 0

Simon Dugré
Simon Dugré

Reputation: 18916

It's an old post but I've ran throught this problem twice this week and it seems to, in my case at least, to be related about the fact that I opened a VPN (for a complete other task with no link to this entity projet) and then, this error happened.

I've tried to close my VPN... then close my projet and re-open, completly close my VS without any success. But, restarting my computer make it works back.

Hope this helps if someone get this in same circonstences.

Upvotes: 0

Riko
Riko

Reputation: 113

I was receiving the same error on pages where there was a mixture of EntityDataSource objects and other data access such as ObjectDataSource and/or imperative code.

I took the advice of the MSDN article referenced in the other answer to your question. I.e. to use context.MetadataWorkspace.LoadFromAssembly(...). I actually didn't know how to get a reference to the context instance used by EntityDataSource, and I figured I should DRY it up anyway, so I created a partial class eg:

    public partial class YourTypeNameEntities
{
    partial void OnContextCreated()
    {
        this.MetadataWorkspace.LoadFromAssembly(typeof(Full.Namespace.Of.YourTypeNameEntities).Assembly);

    }

It still didn't work, but I noticed fairly quickly that when calling DataBind() on a control bound to an EntityDataSource that my OnContextCreated() implementation was not firing!

That was a different issue to which I found a solution... replace the ConnectionString and DefaultContainerName attributes in the EntityDataSource declaration with ContextTypeName. For example:

    <asp:EntityDataSource ID="CountrySource" runat="server" 
ContextTypeName="Full.Namespace.Of.YourTypeNameEntities" EntitySetName="Country" 
OrderBy="it.Name" Where="it.Active==true">

That made sure my OnContextCreated implementation would fire and POOF, the "Loading by both name and attribute is not allowed" problem went away!

Upvotes: 3

Related Questions