Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
Mono organizations on
GitHub to continue tracking issues. Bugzilla will remain
available for reference in read-only mode. We will continue to work
on open Bugzilla bugs, copy them to the new locations
as needed for follow-up, and add the new items under Related
Our sincere thanks to everyone who has contributed on this bug
tracker over the years. Thanks also for your understanding as we
make these adjustments and improvements for the future.
Please create a new report on
Developer Community or GitHub with
your current version information, steps to reproduce, and relevant error
messages or log files if you are hitting an issue that looks similar to
this resolved bug and you do not yet see a matching new report.
System.Diagnostic.Contracts.Requires<T> have been implemented, but when called at runtime a 'not implemented' exception is thrown.
Visual Studio has Code Contracts configuration in Project Properties that allow selection of Runtime checking. If not selected the resulting project output will not contain code contracts. If the same project is compiled in MonoDevelop the output contains code that will throw a 'not implemented' exception when calling Contracts.Required<T>.
MonoDevelop always seems to produce code that contains Code Contracts but, when called, produce a 'not implemented' exception.
Is there any way that projects in MonoDevelop can be configured to provide Runtime checking in Contracts rather than the 'not implemented' exception, or, if not, can the compile filter out Code Contracts so that the code will run.
IIRC you need to instruct ccrewrite tool to re-write the assembly. Moving to MD for now to get things started.
MonoDevelop doesn't have support for invoking ccrewrite or editing the settings that affect it, and we have no ETA for adding this support.
If you need it sooner, you could use a custom postbuild task in your project, or contribute a patch to MonoDevelop to add this functionality in a VS-compatible way.
Did you find a workaround for this? Or is support for this planned anytime soon?
I'd really like to be able to do this as well. Any hint on how to approach resolving this would be much appreciated.
If Requires<T> were marked with [Conditional("CONTRACTS_FULL")], then it could appear (along with the non-generic forms) without forcing you to use ccrewrite, simply by NOT defining that compiler conditional. I submitted a bug and pull request for this 18 months ago, but it was rejected.
We have projects with code intended to be built in VS for Windows and in Xamarin for Mac. We use Contracts for documentation and runtime checking on Windows, and want to simply not use it when building for the Mac. Because the two Requires<T> methods are not marked with the conditional attribute (as they should be), they generate code when building on Xamarin, requiring ccrewrite, which doesn't run.
Our workaround was to bracket our Contract.Requires<Exc>() usages with #if __MonoCS__. We then use different project files (but the same source files) for Xamarin for the Mono/Mac projects, and we define __MonoCS__ within those project files. Unfortunately, this means keeping two project files up-to-date.
I'd really love to use Code Contracts w/ Xamarin as well and would retire https://github.com/ghuntley/conditions in a heart beat. Being able to check at compile time and define contracts on interface instead of individual concrete implementations is just so powerful, relaxing and makes maintenance so much easier.
Got a tip-off by John Galloway that as of a couple days ago CodeContracts has been released by Microsoft under the MIT license and is available at https://github.com/CodeContractsDotNet/CodeContracts . Hopefully that will aid Xamarin with implementing the missing tooling support.
I am also looking for this functionality so mac-based Xamarin Studio developers are still abiding by the same contracts the devs in Visual Studio do.
Closing for now, since Bugzilla isn't the place to track feature requests. Please vote for this on http://xamarin.uservoice.com if it's important to you.