The code calls filesystem::remove_all even if the attempt to unload the dll fails.
In this case, filesystem::remove_all will throw an exception. If this exception is not caught then the application will terminate. Alternatively, you can call the non-throwing version -- remove_all
Also, the non-throwing version does not return 0 upon failure so the if statement needs revision if you decide to use it.