title: C# "Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))"
body: <p>I am building a firewall controller using c#.
  I am getting a :</p>
  
  <blockquote>
    <p>Catastrophic failure (Exception from HRESULT: 0x8000FFFF
    (E_UNEXPECTED))</p>
  </blockquote>
  
  <p>When I am trying to add firewall rules from a list. It seems to work out fine when I just create a rule and add it to the firewall directly.</p>
  
  <pre><code>public partial class Form1 : Form
  {
      private List&lt;INetFwRule2&gt; RuleList = new List&lt;INetFwRule2&gt;();
  
      private Type netFwPolicy2Type = Type.GetTypeFromProgID("HNetCfg.FwPolicy2");
      private INetFwPolicy2 fwPolicy2;
  
      public Form1()
      {
          InitializeComponent();
  
          fwPolicy2 = (INetFwPolicy2)Activator.CreateInstance(netFwPolicy2Type);
  
          // Adding all fireWall rules in a List
          foreach (INetFwRule2 rule in fwPolicy2.Rules)
          {
              RuleList.Add(rule);
          }
      }
  
      private void ApplyButton_Click(object sender, EventArgs e)
      {
          // Deleting all firewall rules
  
          foreach (INetFwRule2 rule in fwPolicy2.Rules)
          {
              fwPolicy2.Rules.Remove(rule.Name);
          }
  
          // Adding rules from the List to the windows firewall 
  
          INetFwRule2 newRule;
  
          for (int i=0; i &lt; RuleList.Count; i++)
          {
              newRule = RuleList[i];
  
              try
              {
                 fwPolicy2.Rules.Add(newRule);
              }
              catch (Exception r)
              {
                  Console.WriteLine("Error adding rule firewall");
              }
          }
      }
  }
  </code></pre>