Visual Studio Error CS0433: The type exists in both... (Unity-Accord.net)

10,275

Solution 1

So I had this problem today. Seems I had two versions of the DLL I fixed this by removing both from project

Solution > References -- check for the files with similar names and remove them. then re-add the correct version.

Clash solved.

Solution 2

It's possible this is related to: Where does error CS0433 “Type 'X' already exists in both A.dll and B.dll ” come from?

In summary:
This can sometimes happen when Visual Studio fails to correctly clear out cached state as part of rebuilding. I have noticed it occurring more frequently with recent updates of VS2019.

Try the following steps and see if it helps:

  1. Delete all bin/obj directories for your solution using File Explorer
  2. Close VisualStudio and restart PC (this seems odd and unnecessary, but have found it can help)
  3. Reopen VisualStudio and do a full rebuild

It is also possible, although much more unlikely, that you genuinely have two references to the same package / dll with different hint paths. One retrieving a signed version, and one not (although if this is an external package it seems unlikely you'd have an unsigned version available). If the above steps don't work, check your project file for duplicate references.

Share:
10,275
Ensking
Author by

Ensking

Updated on June 05, 2022

Comments

  • Ensking
    Ensking almost 2 years

    I'm receiving this error messange:

    The type NormalDistribution exists in both Accord.Statistics, Version=3.8.2.0, Culture=neutral, PublicKeyToken=fa1a88e29555ccf7 and Accord.Statistics, Version=3.8.2.0, Culture=neutral, PublicKeyToken=null

    How can I solve this?

    • Christopher
      Christopher almost 4 years
      Apparently you have the reference twice: Once iwth a proper PublicKeyToken, and once with a PublicKeyToken that is null.
    • Ensking
      Ensking almost 4 years
      Yes, but do you know how can i fix this?
    • Christopher
      Christopher almost 4 years
      I have no idea how to fix it. Usually name and PublicKey are used to prune duplicates, but for some reason one of them does not have the proper key? How can a .dll not have the PublicKeyToken? Much less a dll from the same provider?
  • Ensking
    Ensking almost 4 years
    I tried use the VisualStudio CleanSolution tool but the problem persist. Any other idea to solve the problem? Where can i verify if i have two references?
  • Ross Gurbutt
    Ross Gurbutt almost 4 years
    CleanSolution sometimes doesn't get rid of everything it should if something is holding onto files in bin/obj directories that shouldn't be. Try manually the deleting the folders in FileExplorer as suggested above (will edit for clarity)
  • Ensking
    Ensking almost 4 years
    I found the bin and obj folders and deleted all but this isn't working. There's a way to tell the VisualStudio which one it should use?
  • Ross Gurbutt
    Ross Gurbutt almost 4 years
    It seems unlikely that you have a genuine issue with duplicate references with different public key tokens and more likely that it is a VS build issue, but if you share the relevant references section of your project file then that may help to confirm/disprove this. Using an external tool like Grep or Notepad++ to do a search of all the csproj files in your solution for the phrase "Accord.Statistics" may also be useful, just to check how and where it is referenced.
  • Ensking
    Ensking over 3 years
    I did it, I just deleted the files whit the same name and at some point Unity worked