Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The type <type> exists in both 'A' and 'B'

Now I know there are a number of these questions already up here, but after flipping through them, I haven't found one that solves my specific problem.

I have an ASP.NET MVC 4.5 project. I used NuGet and added Newtonsoft.Json to the project. As soon as I used it in my code (to do some serialization in camel-case), my project no longer builds correctly with the following error:

The type 'Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver' exists in both 'C:..\Microsoft Visual Studio 12.0\Blend\Newtonsoft.Json.dll" and 'C:..\Visual Studio 2013\Projects\myProject\packages\Newtonsoft.Json.6.0.1\lib\net45\Newtonsoft.Json.dll'

Unfortunately, it's the same file down to the public key on each so I can't use the dependency assembly reference in Web.config (as suggested elsewhere). I would prefer to use the dll retrieved via NuGet so upgrades to new versions are easier.

Additionally, neither one is in the Temporary Internet folder, so I can't simply delete that and have it work either.

How can I go about specifying the specific assembly file I want to use so I can build the project correctly? Thanks!

like image 703
Whit Waldo Avatar asked Feb 15 '14 00:02

Whit Waldo


1 Answers

Xaniff, open your project file manually and look for Newtonsoft. You will more than likely find an item group with a reference to a version that is not matching your nuget package.. In my case I found this:

<ItemGroup>
    <Reference Include="Newtonsoft.Json">
        <HintPath>..\packages\Newtonsoft.Json.5.0.6\lib\net45\Newtonsoft.Json.dll</HintPath>
    </Reference>
</ItemGroup>

I deleted this item group, closed the project file, reloaded, and all was well.

like image 63
Khepri Avatar answered Nov 13 '22 15:11

Khepri