Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework Duplicate type name within an assembly (6.1.0)

I am not sure what is going on but I keep getting the following exception when doing a query. "Duplicate type name within an assembly." I have not been able to find a solution on the web. I had resolved the issue by removing entity framework from all the projects in the solutions and re-installing using nugget. Then all of the sudden the exception is back. I have verified my table schema over and over and find nothing wrong with.

This is the query causing the exception.

    var BaseQuery = from Users in db.Users
            join UserInstalls in db.UserTenantInstalls on Users.ID equals UserInstalls.UserID
            join Installs in db.TenantInstalls on UserInstalls.TenantInstallID equals Installs.ID
            where
                Users.Username == Username
                && Users.Password == Password
                && Installs.Name == Install
            select Users;

    var Query = BaseQuery.Include("UserTenantInstalls.TenantInstall");

    return Query.FirstOrDefault();

As I mentioned previously the same query was working before. The data has not changed and the code has not changed.

like image 745
CodeMilian Avatar asked Apr 21 '14 00:04

CodeMilian


4 Answers

As a work around, this only happens if you are single-stepping using the debugger. If you place your break point a few lines further down inside your source, the error will not show up.

I haven't uninstalled, and this at least allows me to continue working.

like image 119
Chad Lehman Avatar answered Oct 22 '22 23:10

Chad Lehman


This is a new issue with EF 6.1.0, and the EF team is aware of the problem:

https://entityframework.codeplex.com/workitem/2228

like image 33
yohohoho Avatar answered Oct 23 '22 00:10

yohohoho


Faced the same in my WCF webservice recently. Just clean your solution and rebuild it. This should fix the issue.

like image 12
Sandy Avatar answered Oct 23 '22 01:10

Sandy


None of the above seem to work for me however in the link specified earlier i did fin this, which worked for me. This was submitted by 'bunomonteiro'

To Fix "Duplicate type name within an assembly"

I had similar issue. I checked all my models/classes and I have not used duplicate names for types. I deleted the assemblies and regenerated the the model and context object from the database and still had the same issue.

A trace yielded in Visual Studio "Children could not be evaluated". The SOLUTION is to add .ToList(); or ToArray(); or ToDictionary() etc, to your query. etc.

eg. var query = context.TableName.Where(x => x.name =="CodeRealm").ToList();

PingBack - http://entityframework.codeplex.com/workitem/1898

bunomonteiro wrote Jul 18 at 3:37 AM

like image 4
Steady Avatar answered Oct 22 '22 23:10

Steady