0

I'm trying to learn Python.NET module, but at the very beginning I face some problems.

I'm trying to execute this simple code:

import clr

clr.AddReference("System")
clr.AddReference("System.Drawing")
clr.AddReference("System.Windows.Forms")

import System
import System.Drawing
import System.Windows.Forms

class FormLogin(System.Windows.Forms.Form):
    def __init__(self):
        pass

def main():
    System.Windows.Forms.Application.Run(FormLogin())

if __name__ == "__main__":
    main()

Unfortunately, this exception is raised:

Traceback (most recent call last):
  File "C:\Users\MyUser\Desktop\Test\APP.py", line 21, in <module>
    main()
  File "C:\Users\MyUser\Desktop\Test\APP.py", line 18, in main
    System.Windows.Forms.Application.Run(FormLogin())

System.NullReferenceException: Object reference not set to an instance of an object.
   at System.Windows.Forms.Form.get_IsMdiChild()
   at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)

Does anyone know how to fix this?

Itay Dvash
  • 40
  • 9
  • Does this answer your question? [What is a NullReferenceException, and how do I fix it?](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – burnsi Feb 18 '23 at 12:55
  • Unfortunately, no @burnsi – Itay Dvash May 07 '23 at 20:21

0 Answers0