Entity Framework Duplicate type name within an assembly (6.1.0)

23,821

Solution 1

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.

Solution 2

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

Solution 3

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

Solution 4

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

Solution 5

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.

Share:
23,821

Related videos on Youtube

CodeMilian
Author by

CodeMilian

Updated on July 09, 2022

Comments

  • CodeMilian
    CodeMilian almost 2 years

    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.

    • CodeMilian
      CodeMilian about 10 years
      I was able to solve this again by repeating the steps I mentioned. This is starting to get really annoying. I hope someone can shed some light as to what is going on.
    • Chris Piechotta
      Chris Piechotta about 10 years
      This might seem like an odd question, but did you seed your database, or maybe changed the way you seeded it ? I had the exact same issue as you describe. In my case I newed an object and added it to a DbSet, newed a second object of the same type and added it the same way. After changing this to newing both objects before adding either one resolved the problem.
    • Lukas K
      Lukas K over 9 years
      I had a same problem and for me it worked after I Cleaned and Rebuilt solution. Really strange.
  • robasta
    robasta almost 10 years
    As a lazy dude's workaround, I installed version 6.0.0 and this issue is gooone. run this command in the nuget console: "install-package EntityFramework -version 6.0.0"
  • gspatel
    gspatel almost 10 years
    As unintuitive as it is...this actually was the problem.
  • Chris Owens
    Chris Owens almost 10 years
    +1 I don't know how or why, but this actually works. Just to clarify for anyone else who comes across this, the first breakpoint had to be after the exception was normally thrown. Pausing anywhere before it and then skipping to a line after stil seems to break it.
  • iphone007
    iphone007 almost 10 years
    Wow, this works for me too! You've saved me countless hours of debugging! Now I can go home for dinner. Thanks!!!
  • Termato
    Termato over 9 years
    Thank you for the link. In it I found my solution. Adding .ToList() at the end fixed my issue.
  • JsAndDotNet
    JsAndDotNet about 8 years
    For me it was clean (delete bin folders), restart Visual Studio and rebuild. Simple clean and rebuild didn't fix it. Thanks for the tip though. +1.
  • Toolkit
    Toolkit almost 7 years
    The correct sequence is clean, rebuild, restart 5 times, do yoga, go camping, pray to Bill Gates, sacrifice a goat
  • Toolkit
    Toolkit almost 7 years
    but seriously, after all dancing around the fire, i still have this error
  • Sandy
    Sandy over 6 years
    @Toolkit Then maybe you did wrong Yoga asanas, went camping at wrong place and weight of goat was not as expected. It is your mistake:D
  • Toolkit
    Toolkit over 6 years
    no i just set the breakpoint after the shitline and that solved it
  • Sandy
    Sandy over 6 years
    Hmm..So you want to iterate your LINQ query to get rid of error? Its costly and will not be recommended. Queries return Enumerable and Queryable for a reason and adding ToList, ToArray and ToDictionary is just I cannot digest.
  • Savage
    Savage over 5 years
    Solved with a combination of rebuild and moving debug point past the problem line. Rebuilding alone will get the code working in non-debug, but it re-occurs when you debug.
  • Savage
    Savage almost 4 years
    I also had to close IIS Express and relaunch