falahati / WindowsFirewallHelper

A class library to manage the Windows Firewall as well as adding your program to the Windows Firewall Exception list.
MIT License
274 stars 72 forks source link

Exception thrown: 'System.NotSupportedException' in WindowsFirewallHelper.dll #59

Open ctechid opened 1 year ago

ctechid commented 1 year ago

I get a warning like this in the immediate window when FirewallManager.Instance.Rules.SingleOrDefault is executed.

I use VS2022 with C# Desktop with Framework 7.0. The program works fine but a warning appears like that. Can it be ignored?

Thanks.

Exception thrown: 'System.Runtime.InteropServices.COMException' in System.Private.CoreLib.dll Exception thrown: 'System.Runtime.InteropServices.COMException' in WindowsFirewallHelper.dll Exception thrown: 'System.NotSupportedException' in WindowsFirewallHelper.dll Exception thrown: 'System.Runtime.InteropServices.COMException' in System.Private.CoreLib.dll Exception thrown: 'System.Runtime.InteropServices.COMException' in WindowsFirewallHelper.dll Exception thrown: 'System.NotSupportedException' in WindowsFirewallHelper.dll

                var wcfHttpRuleInName = String.Format("DiscountCard - WcfHttpRuleIn: Port {0} - Protocol {1}", Settings.Default.ServiceHttpPort, FirewallProtocol.Any);
                var wcfHttpRuleAction = FirewallAction.Allow;
                var wcfHttpRulePort = (ushort)Settings.Default.ServiceHttpPort;
                var wcfHttpRuleProtocol = FirewallProtocol.Any;
                //
                var isWcfHttpRuleInNameFounded = FirewallManager.Instance.Rules.SingleOrDefault(r => r.Name.Equals(wcfHttpRuleInName));
                if (isWcfHttpRuleInNameFounded == null)
                {
                    var ruleIn = FirewallManager.Instance.CreatePortRule(
                        wcfHttpRuleInName,
                        wcfHttpRuleAction,
                        wcfHttpRulePort,
                        wcfHttpRuleProtocol
                    );
                    ruleIn.Direction = FirewallDirection.Inbound;
                    FirewallManager.Instance.Rules.Add(ruleIn);
                }

image

falahati commented 1 year ago

Do you have break on exception active?