VS2010 は、CodeContract.Invariant が false であると私に言い続けます。これがどのように当てはまるのかわかりません
public class BankAccountIdentifierDefinitionVariation_CreateCommandArgs : ValidatedCommandArgs
{
    public string IdentifierCode {get; private set; }
    public string CountryCode {get; private set; }
    public Ems.Infrastructure.Validation.StringValidator Validator {get; private set; }
    private BankAccountIdentifierDefinitionVariation_CreateCommandArgs()
        : base() { }
    public BankAccountIdentifierDefinitionVariation_CreateCommandArgs(
        string identifierCode,
        string countryCode,
        Ems.Infrastructure.Validation.StringValidator validator)
    {
        Contract.Requires(!string.IsNullOrEmpty(identifierCode));
        Contract.Requires(!string.IsNullOrEmpty(countryCode));
        Contract.Ensures(!string.IsNullOrEmpty(this.IdentifierCode));
        Contract.Ensures(!string.IsNullOrEmpty(this.CountryCode));
        this.IdentifierCode = identifierCode;
        this.CountryCode = countryCode;
    }
    [ContractInvariantMethod]
    void ContractInvariants()
    {
        Contract.Invariant(!string.IsNullOrEmpty(IdentifierCode));
        Contract.Invariant(!string.IsNullOrEmpty(CountryCode));
    }
}
警告は、両方の不変条件が偽であるということです。これは明らかに当てはまりません。次の2つのバリエーションも試しました。
Contract.Ensures(!string.IsNullOrEmpty(this.IdentifierCode);
if (string.IsNullOrEmpty(identifierCode)) throw new ArgumentNullException...
this.IdentifierCode = identifierCode;
そしてまた
Contract.Ensures(!string.IsNullOrEmpty(this.IdentifierCode));
this.IdentifierCode = identifierCode;
if (string.IsNullOrEmpty(this.IdentifierCode)) throw new ArgumentNullException...
プライベートセッターを介してプロパティの値を変更できるため、不変式がfalseのように見えます(私は変更しませんが)。これに対処する方法はありますか?シリアル化しているため、プロパティはプロパティのままにする必要があります。