When the following contract is violated:
Contract.Requires<CustomException>(arg1 != null, "arg1 cannot be null");
the message in CustomException.Message becomes: Precondition failed: arg1 != null arg1 cannot be null. In this situation, how can I prevent code contracts from adding "Precondition failed: arg1 != null" to CustomException.Message?
My assembly is using code contract's "standard contract requires" mode (usage 2 in section 5.1 of code contract's user manual) because I want to use contracts for argument validation on public methods in the release build, thus the reason I'm using Contract.Requires<T> (with the type parameter). In this situation I don't seem to have access to my "arg1 cannot be null" message by itself. I do not wish to try to remove "Precondition failed etc." using string manipulations.
I know that if I instead throw a ContractException (using the non-generic Contract.Requires) I can use reflection to get my message from ContractException.UserMessage. But I don't believe these contracts will work when using "standard contract requires" mode, and anyway I won't be able to globally catch these errors.