I just found out that the custom framework ( https://github.com/viperneo/winforms-modernui ) is not working as intended. Everything works fine with the regular Windows Forms, no exception is thrown. But for some reason when using the framework, the exception is thrown if a form is not disposed before the application quits. Hopefully someone may read this when considering using this framework.
Thanks to Hans Passant for the hint regarding the custom framework!