Questions tagged [microsoft-contracts]
22 questions
52
votes
7 answers
ReSharper - Possible Null Assignment when using Microsoft.Contracts
Is there any way to indicate to ReSharper that a null reference won't occur because of Design-by-Contract Requires checking? For example, the following code will raise the warning (Possible 'null' assignment to entity marked with 'NotNull'…

Hans Van Slooten
- 2,257
- 2
- 19
- 18
43
votes
4 answers
How mature is the Microsoft Code Contracts framework?
Microsoft has recently put a release of their Code Contracts framework on DevLabs with a commercial license. We're interested on using them in our project (mostly C#, some C++/CLI) to gradually replace all the custom validation code, but I'm keen to…

Greg Beech
- 133,383
- 43
- 204
- 250
38
votes
4 answers
.NET 4.0 code contracts - How will they affect unit testing?
For example this article introduces them.
What is the benefit?
Static analysis seems cool but at the same time it would prevent the ability to pass null as a parameter in unit test. (if you followed the example in the article that is)
While on the…

Finglas
- 15,518
- 10
- 56
- 89
32
votes
1 answer
C#: Code Contracts vs. normal parameter validation
consider the following two pieces of code:
public static Time Parse(string value)
{
string regXExpres =
"^([0-9]|[0-1][0-9]|2[0-3]):([0-9]|[0-5][0-9])$|^24:(0|00)$";
Contract.Requires(value != null);
…

steveee
- 321
- 3
- 8
7
votes
2 answers
Can Microsoft Code Contracts be used with an ASP.NET Website?
I'm currently using Microsoft Code Contracts in an ASP.NET MVC application without any issues but I can not seem to get it quite running in a basic ASP.NET Web site. I'm not entirely sure it was made to work with this type of project (although it…

jamesmillerio
- 3,154
- 4
- 27
- 32
7
votes
5 answers
Bug in iterators with code contracts?
The following code fails on the pre condition. Is this a bug in code contracts?
static class Program
{
static void Main()
{
foreach (var s in Test(3))
{
Console.WriteLine(s);
}
}
static…

pn.
- 852
- 1
- 8
- 9
5
votes
1 answer
.NET code contracts: can it get more basic than this?
I was just messing around to answer someone's question here on Stack Overflow, when I noticed a static verification warning from inside my Visual Studio (2008):
string[] source = { "1", "A", "B" };
var sourceObjects = Array.ConvertAll(source, c =>…

Thorarin
- 47,289
- 11
- 75
- 111
4
votes
2 answers
What tooling do you use to do Design by Contract?
I used to use Microsoft CodeContracts for three weeks and now half of my code is just contracts. I have dozens of unproved places, I cannot use runtime-check because IL rewrite prevents coverage tool to show something and compile time is less then…

Mike Chaliy
- 25,801
- 18
- 67
- 105
4
votes
5 answers
Why am I getting malformed contract, in by C# code?
Visual Studio shows an error when I write this contract below.
Error 20 Malformed contract section in method '....get_Page'
Is the problem with the if block?
public int? Page
{
get
{
int? result = Contract.Result();
if (result…

Victor Rodrigues
- 11,353
- 23
- 75
- 107
3
votes
1 answer
Outlook contacts change their ID when you move them to another folder
I have a problem with the Microsoft Graph Rest API. I have written a progam that should read the contacts from Outlook and later match them again and again. For this I use the ID from the contacts record. My program reads over all folders and gets…

Tibor
- 33
- 2
3
votes
1 answer
Code Contracts with new MVC 3 ViewBag
public class HomeController : Controller
{
public ActionResult Index()
{
// Warning 19 CodeContracts: Possibly calling a method on a null reference 'Website.Controllers.HomeController.o__SiteContainer0.<>p__Site2.Target'…

Dave Jellison
- 924
- 13
- 22
2
votes
2 answers
What does it take to prove this Contract.Requires?
I have an application that runs through the rounds in a tournament, and I am getting a contract warning on this simplified code structure:
public static void LoadState(IList

John Gietzen
- 48,783
- 32
- 145
- 190
1
vote
1 answer
Could not load file or assembly 'Facebook.Web.Contracts' or one of its dependencies
Just downloaded the facebook c# sdk. Haven't written any code just added my references to the dll's and ran the project, as I already had some other code I was working on. Then I got this error above. I've definitely added that dll as well as the…
user583824
1
vote
2 answers
How do I indicate that a method never returns a null using code contracts?
How do I indicate that a method never returns a null? Currently this is my code.
Line 19 gets an Ensures not proven message, even though CreateFunction assumes that the result is not nothing.
1 Public Function CreateFunction(Of…

Jonathan Allen
- 68,373
- 70
- 259
- 447
1
vote
2 answers
Microsoft.Contracts namespace
For what it is necessary Microsoft.Contracts namespace in asp.net?
I mean, in what cases I could write using Microsoft.Contracts;?

x2.
- 9,554
- 6
- 41
- 62