1

I have an issue as described here. Let me explain the details.

I have a table which is used for two different dll's with different edmx files. And I have an executable which uses these two dlls. When I call one of them, it throws the exception specified in the above(Schema specified is not valid, multiple types with the name...)

Can someone describe me what causes this error in this case?

Edit: Detailed explanation is below:

  1. Below code is in ABC.dll:

ABC.dll -> EntModel.edmx -> EntModel.Context.cs

namespace MyNamespaceABC
{
    using System;
    using System.Data.Entity;
    using System.Data.Entity.Infrastructure;

    public partial class AbcEntities : DbContext
    {
        public AbcEntities()
            : base("name=AbcEntities")
        {
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            throw new UnintentionalCodeFirstException();
        }

        public DbSet<MyTable> MyTables { get; set; }
    }
}
  1. Below code is in XYZ.dll:

XYZ.dll -> EntModel.edmx -> EntModel.Context.cs

namespace MyNamespaceXYZ
{
    using System;
    using System.Data.Entity;
    using System.Data.Entity.Infrastructure;

    public partial class XyzEntities : DbContext
    {
        public XyzEntities()
            : base("name=XyzEntities")
        {
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            throw new UnintentionalCodeFirstException();
        }

        public DbSet<MyTable> MyTables { get; set; }
    }
}

And these dlls are used by an executable called Main.exe. When I test these dlls on their tester projects, they work like a charm. Then, when I call it from Main.exe, both of the dlls throw this exception when I try to retrieve data.

Schema specified is not valid. Errors:

Multiple types with the name 'MyTable' exist in the EdmItemCollection in different namespaces. Convention based mapping requires unique names without regard to namespace in the EdmItemCollection.

7
  • The exception message explains itself: multiple types with the name... Did you inspect the source code of the dll? Commented Oct 26, 2017 at 12:15
  • Of course. When I debug and run the dll it doesn't throw the exception. Exception occures when I call it from an executable which uses same table with a different dll. Both of the dlls working fine on their teste projects. I mean, the issue is about calling them in the same exe. Commented Oct 26, 2017 at 12:32
  • Both dll's contain public entity classes with different names. But, both of these classes contains same table having the same name. This may cause the issue(I don't know why), but I am looking for a persistent resolution. Commented Oct 26, 2017 at 13:06
  • @GertArnold I updated the question and tried to give more details. I hope it helps. Commented Oct 27, 2017 at 7:13
  • That doesn't match with your comment Both dll's contain public entity classes with different names. Commented Oct 27, 2017 at 7:40

1 Answer 1

1

To resolve this issue, I renamed the entity name in the edmx diagram and the error is gone.

To sum up, it is forbidden to use same entity name for different projects. Using one and only structure for accessing database will resolve the issue permanently for the main project.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.