public static void ValidateFault(NativeActivityContext context, OperationDescription targetOperation, string overridingAction, Type faultType) { bool faultTypeExistOnContract = false; for (int index = 0; index < targetOperation.Faults.Count; index++) { FaultDescription targetFault = targetOperation.Faults[index]; if (targetFault.DetailType == faultType) { string name = NamingHelper.TypeName(faultType) + TypeLoader.FaultSuffix; string action = overridingAction ?? NamingHelper.GetMessageAction(targetOperation, false) + name; if (targetFault.Action != action) { Constraint.AddValidationError(context, new ValidationError(SR2.PropertyMismatch(action, "Fault Action", targetFault.Action, targetOperation.Name, targetOperation.DeclaringContract.Name))); } if (targetFault.Name != NamingHelper.XmlName(name)) { Constraint.AddValidationError(context, new ValidationError(SR2.PropertyMismatch(NamingHelper.XmlName(name), "Fault Name", targetFault.Name, targetOperation.Name, targetOperation.DeclaringContract.Name))); } if (targetFault.Namespace != targetOperation.DeclaringContract.Namespace) { Constraint.AddValidationError(context, new ValidationError(SR2.PropertyMismatch(targetOperation.DeclaringContract.Namespace, "Fault Namespace", targetFault.Namespace, targetOperation.Name, targetOperation.DeclaringContract.Name))); } if (targetFault.HasProtectionLevel) { Constraint.AddValidationError(context, new ValidationError(SR2.ProtectionLevelNotSupported(targetOperation.Name, targetOperation.DeclaringContract.Name))); } // TypeLoader guarantees that fault types are unique in the Faults collection. faultTypeExistOnContract = true; break; } } // It is OK to have fewer fault types than defined on the contract. // But we do not allow workflow to define more fault types than specified on the contract. if (!faultTypeExistOnContract) { Constraint.AddValidationError(context, new ValidationError(SR2.FaultTypeMismatch(faultType.FullName, targetOperation.Name, targetOperation.DeclaringContract.Name))); } }