0

I use Code Contracts in my code, my app runs fine on the emulator. When I deploy it on a device, it fails/crashes whenever Contract statement is executed.

 public static HTTPRequest CreateGetRequest(string url,
                                        bool shouldUseCustomTimeout)
        {
            // preconditions
            Contract.Requires<ArgumentException>(!string.IsNullOrWhiteSpace(url));

            return new HTTPRequest(url,
                                    System.Net.Http.HttpMethod.Get,
                                    shouldUseCustomTimeout);
        }

Is the code contract supported on actual device? Should I install a separate extension?

ssk
  • 9,045
  • 26
  • 96
  • 169
  • 1
    a quick search led me to http://stackoverflow.com/questions/16972781/code-contracts-not-working-in-windows-phone-8-unit-test – Lee Gary Jun 13 '13 at 01:25
  • @LeeGary - that's actually subtly different. This question is about whether this works on a device. – Paul Annetts Jun 13 '13 at 10:24
  • @LeeGary I have already installed Code Contracts for .Net and vs2012 extension. My unit tests work, but when I deploy my app on a device, it fails/crashes when it executes Contract statements. – ssk Jun 13 '13 at 15:45
  • You'll need to provide some error information here. What stacktrace does it crash with? Did you enable runtime contracts, or just static analytics? etc. – Claus Jørgensen Jun 13 '13 at 19:08
  • @ClausJørgensen There was no stack trace available, the control goes to unknown location when the app executes contract statements. I set up the project similar to this: http://blog.stephencleary.com/2011/01/simple-and-easy-code-contracts.html – ssk Jun 14 '13 at 02:19

2 Answers2

0

Is the code contract supported on actual device?

Yes.

Claus Jørgensen
  • 25,882
  • 9
  • 87
  • 150
0

I got it working by following the steps on this blog: http://blog.stephencleary.com/2011/01/simple-and-easy-code-contracts.html

It turns out that I had to enable for the library projects too. I was setting code contracts only for the test app.

ssk
  • 9,045
  • 26
  • 96
  • 169