falahati / WindowsFirewallHelper

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

The system cannot find the file specified. (Exception from HRESULT: 0x80070002) #27

Closed zedle closed 5 years ago

zedle commented 5 years ago

Hello, been using this library for a while now with great success, but recently had a user get this error. We've tried a number of steps to resolve the issue to no avail, does anyone have any clues as to what might be wrong with his machine?

Trace:

System.IO.FileNotFoundException: The system cannot find the file specified. (Exception from HRESULT: 0x80070002)
--
at WindowsFirewallHelper.COMInterop.INetFwRules.Remove(String name)
at WindowsFirewallHelper.FirewallAPIv2.Firewall.RulesOnItemsModified(Object sender, ActiveCollectionChangedEventArgs`1 e)
at System.Collections.ObjectModel.Collection`1.Remove(T item)
falahati commented 5 years ago

This is interesting, first due to the fact that it happened on the Remove() and second because it happens on the marshaller level or via the native com object; and yet it is unexpected from this function to throw a file not found exception at least based on the MSDN page.

What is the environment of this client? What version of this library do you use and in what framework? This seems quite similar to the issue we had a while ago with the GetEnumerator() function under NetCore: https://github.com/dotnet/corefx/issues/26257

I wrote a completely new set of classes to handle this better in the alpha release of the v2. I personally recommend that you upgrade to the latest pre-release version and try again. It might need a little more testing tho and some changes here and there due to the different API it exposes, but it's essentially the same process at the end and therefore it should be easy to fix your code after the upgrade.

Meanwhile please provide more information about the environment and the solution you tried up to this point. Also, provide me with full exception message and inner exception info if available.

falahati commented 5 years ago

Also, it might be easier than this and simply means that the rule you are trying to delete doesn't exist or already deleted. Make sure that your code checks for that scenario or at least capture the exception. If multiple instances of this program are running it is quite possible to have a race condition in which one instance deletes a rule and the other later tries to do the same. This is more expected with V1 of this library since it does cache the rules and changes happening outside of it are not immediately visible. This isn't the case with v2 alpha pre-release since it removed all caching in favour of solving similar problems and being more responsive in general.

zedle commented 5 years ago

This only happened on one machine running Windows 10 with v1.6.3.40 of the library. I'm weary of using pre-release code in a production application truthfully.

falahati commented 5 years ago

You mentioned that you tried multiple steps to resolve this. What were the steps you tried? Does your application targets .NetFramework or .NetCore (.NetStandard)?

Also, I suggest moving to v2 at least in your development builds. Not only this makes it easier to upgrade to this version later (since I am not going to update V1 anymore; unless for big functionality breaking bugs), it also helps us find the bugs and problems in it faster and therefore release a proper version sooner.