0

A have a large web service solution (written in C# targetting .NET 3.5) which is comprised of 16 individual projects (many class libraries, a few web applications and setup projects). It is developed in visual studio 2010.

I was recently experimenting with Microsoft.CodeContracts, and after evaluating it decided that it was not suitable for my needs. I removed all of the code that referenced it, and removed the assembly references from all of the projects that referenced it.

However my web service has now started to randomly return this error message:

"Could not load file or assembly 'Microsoft.Contracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=736440c9b414ea16' or one of its dependencies. The system cannot find the file specified."

How/Why can it still be trying to load that assembly when I have removed all the code & references to it?

On investigating further, I am still finding that Microsoft.Contracts.dll is showing up in the /bin/ folder of my web application, even though no projects reference it. It is also listed as a "detected dependency" in my setup project - but I am 100% certain NONE OF MY PROJECTS ARE USING IT!

This is driving me absolutely nuts - there is obviously something lurking around thats holding the reference. How can I remove all traces of Microsoft.CodeContracts from my solution?

ohmantics
  • 1,799
  • 14
  • 16
MattDavey
  • 8,897
  • 3
  • 31
  • 54

1 Answers1

3

There are numerous XML elements within CSharp project files that start with CodeContracts.

Remove them if you feel you need to do so.

There will be as many sections as you have configurations {Release, Debug} x {Any CPU, Mixed Platforms} = 4. Do this for each *.csproj file in your solution.

Keep in mind that CodeContracts conditionally generate/weave code, so you app might behave differently.

GregC
  • 7,737
  • 2
  • 53
  • 67
  • 1
    If you'd like a UI route, have a look at each project's properties. There is a CodeContracts tab (usually on bottom left). In it, there is an option to build, not build, or not selected. Choose not selected. – GregC Apr 13 '11 at 12:35
  • 1
    Thanks for your answer Greg. I edited the various .csproj files and removed the (many) references to CodeContracts. There were 23 individual elements in each property group - messy! The most interesting one was this: %28none%29. – MattDavey Apr 14 '11 at 08:16