Rick Strahl's Web Log

Wind, waves, code and everything in between...
ASP.NET • C# • HTML5 • JavaScript • AngularJs
Contact   •   Articles   •   Products   •   Support   •   Search
Ad-free experience sponsored by:
ASPOSE - the market leader of .NET and Java APIs for file formats – natively work with DOCX, XLSX, PPT, PDF, images and more

Blend Path interfering with C# Project Builds


:P
On this page:

Yesterday I ran into a nasty bug in Visual Studio that caused a compiler error in a Web project. It appears that Visual Studio looks in a completely unrelated path and pulls in an assembly that overrides the project assembly reference. Specifically it’s related to accessing a Type from JSON.NET directly in code, but this might manifest with other types that exist in the external path as well.

Here’s what the error looks like in my project at build time:

JsonNetError

Notice here I’m referencing an explicit type from JSON.NET – the Formatting Enum – and the compiler is complaining:

The type 'Newtonsoft.Json.Formatting' exists in both 'c:\projects2010\MyDailyDosha\packages\Newtonsoft.Json.6.0.7\lib\net45\Newtonsoft.Json.dll' and 'c:\Program Files (x86)\Microsoft Visual Studio 12.0\Blend\Newtonsoft.Json.dll'    C:\projects2010\MyDailyDosha\MyDailyDosha\Code\Controllers\QuizController.cs

So what the hell is the compiler doing pulling in references from the Blend directory when there’s an explicit reference in the project to the DLL?

Apparently this has been a problem for a while – there’s a connect issue for this problem:

Looks like a bug in Visual Studio 2013 that has been ongoing for a long time without a real resolution.

Rename the Path or DLL!

My guess is the problem is a bad path somewhere in the CSharp compiler’s command line. So a quick solution to this problem is to simply rename the directory or the offending DLL (Newtonsoft.Json.dll).

Since I don’t use Blend or WPF  this isn’t a problem but if you do, make sure you write a note somewhere so that you can remember to rename the folder back when you do need it.

Renaming the folder works for me and I can also still open Visual Studio. Not sure what happens when I open a WPF project that requires Blend, but not likely to happen for me anyway…

It remains a mystery how a Web project would be referencing the Blend folder. I checked the Visual Studio Command Line and it doesn’t have a path reference to this folder.

It’s a bit surprising that this issue has been around for so long and not been fixed. This is kind of a show stopper IF you happen to reference a library that’s in that particular folder.

Posted in C#  .NET  

The Voices of Reason


 

West Wind  © Rick Strahl, West Wind Technologies, 2005 - 2019