How can I solve this problem by using Code contracts:
private string SomeMethod(string code)
{
var msg = "Invalid blabal " + code;
Contract.Ensures(!string.IsNullOrEmpty(Contract.Result<string>()), msg);
}
Error:
User message to contract call can only be string literal, or a static field, or static property that is at least internally visible.
EDIT: I saw this information as you use contracts with similar use case
All of the contract methods have overloads that take a string in addition to the boolean condition:
The user-supplied string will be displayed whenever the contract is violated at runtime.
It must be a compile-time constant.
So It must be: