Reputation: 1290
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.
Upvotes: 44
Views: 25922
Reputation: 1
Had same issue that has taken hours yesterday to get rid of. Using EF 6.1.0, error on executing linq to entities query similar as above. My solution was to stop IIS Express, clean solution , uninstall EF from all projects in solution, close VS2012, delete all packages folders/files within solution, then restart VS2012, add EF 6.1.0 where needed, compile, error disappeared.
Upvotes: 0
Reputation: 537
I too was facing similar sort of issue, I fixed it by converting the result set to List i.e
var registers = registerRepository.All.ToList().Where(a=>a.AreaLatitude.Equals(0));
Converting the result ToList solved the issue to iterate it further.
and solved the issue.
Upvotes: 0
Reputation: 11687
Faced the same in my WCF webservice
recently. Just clean your solution and rebuild it. This should fix the issue.
Upvotes: 12
Reputation: 361
This seems to be fixed in 6.1.3.
Here's how I come to this conclusion:
I reliably reproduced this problem in a previous version (probably 6.1.2). Rebuilding my solution did not fix it. The stepping through with breakpoints before and after did reproduce the problem, while having breakpoints only after the point of the exception did not cause an exception, as stated here in other answers. [Summary: I seem to have the same problem as everyone else with the older version of EF.]
Given the exact same breakpoints and with no re-boot or anything like that, I just installed the update to Entity Framework. This did fix the issue, where I could step freely with breakpoints before and after the "problem code" with no exception being thrown anymore.
Since the issue is kind of random and temperamental to the conditions, it's hard to say definitively that the update to EF specifically addresses the issue, but so far so good.
Upvotes: 2
Reputation: 41
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
Upvotes: 4
Reputation: 1036
Must be correcting "select Users;" segment of code :
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;
Correction code :
select new { ID=Users.ID, F1= Users.forExampleField1,
F2= UserInstalls.forExampleFild1,
F3= Installs.forExampleFild1 ,
F4= Installs.forExampleFild2 };
The reason:
Foreign key fields in the class are present and "Linq" are not able to remove them which there was the following error:
Duplicate type name within an assembly
(Of course this problem Fault "entity framework" !)
I am a full explanation on this matter, But unfortunately my English is not very good and it is really hard for me to explain specialization, because I understand that many people do not understand what I mean. I apologize for this.
Upvotes: 0
Reputation: 1
With EF 6.1, I run into the same problem.
In my case, my model has a self-reference table. So I found it might be caused by the following two reasons.
Upvotes: 0
Reputation: 952
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.
Upvotes: 67
Reputation: 361
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
Upvotes: 19