title: Block Check-In on Policy Failure
body: <p>I've created the check-in policy <a href="https://msdn.microsoft.com/en-us/library/bb668980.aspx" rel="nofollow noreferrer">from this MSDN article</a> as an example (code is just copy / pasted).</p>
  
  <p>This works fine, it appears when I try and do a check-in, however it appears as an warning.  So I can ignore it by just pressing Check In again.  How can I change the code, as listed in the URL, so that it will return an Error not a warning.    I can't see any properties on PolicyFailure to do this.</p>
  
  <p>Essentially I want it to look like the error in this screenshot:
  <img src="https://i.stack.imgur.com/oHXIT.png" alt="enter image description here"></p>
  
  <p><sup><a href="http://blogs.msmvps.com/vstsblog/2014/05/13/turning-off-policy-overrides-in-tfs/" rel="nofollow noreferrer">Image Source</a></sup></p>
  
  <p><strong>EDIT:</strong> Here is the exact code that I'm using.  Now it is slightly modified from the original source, but not in any massive way I wouldn't have thought.  Unfortunately I can't post screenshots, but I'll try and describe everything I've done.</p>
  
  <p>So I have a DLL from the code below, I've added it into a folder at C:\TFS\CheckInComments.dll.  I added a registry key under Checkin Policies with the path to the DLL, the string value name is the same as my DLL (minus .dll).  In my project settings under source control I've added this Check-In Policy.</p>
  
  <p>It all seems to work fine, if I try and do a check-in it will display a warning saying "Please provide some comments about your check-in" which is what I expect, what I'd like is for it to stop the check-in if any policies are not met, however I would still like the user to be able to select Override if necessary.  At the moment, even though there is a warning, if I was to click the Check In button then it would successfully check-in the code.</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Windows.Forms;
  using Microsoft.TeamFoundation.VersionControl.Client;
  
  namespace CheckInComments
  {
      [Serializable]
      public class CheckInComments : PolicyBase
      {
          public override string Description
         {
              get
              { 
                  return "Remind users to add meaningful comments to their checkins";
  
              }
          }
  
          public override string InstallationInstructions
          { 
              get { return "To install this policy, read InstallInstructions.txt"; } 
          }
  
          public override string Type
          {
              get { return "Check for Comments Policy"; }
          }
  
  
          public override string TypeDescription
          {
              get
              {
                  return "This policy will prompt the user to decide whether or not they should be allowed to check in";
              }
          }
  
          public override bool Edit(IPolicyEditArgs args)
          {
  
              return true;
          }
  
  
          public override PolicyFailure[] Evaluate()
          {
              string proposedComment = PendingCheckin.PendingChanges.Comment;
              if (String.IsNullOrEmpty(proposedComment))
              {
                  PolicyFailure failure = new PolicyFailure("Please provide some comments about your check-in", this);
                  failure.Activate();
  
                  return new PolicyFailure[1]
                  {
                      failure
                  };
              }
              else
              {
                  return new PolicyFailure[0];
              }
          }
  
          public override void Activate(PolicyFailure failure)
          {
              MessageBox.Show("Please provide comments for your check-in.", "How to fix your policy failure");
          }
  
          public override void DisplayHelp(PolicyFailure failure)
          {
              MessageBox.Show("This policy helps you to remember to add comments to your check-ins", "Prompt Policy Help");
          }
      }
  }
  </code></pre>