Error when using Windows Form Events with Python in Dynamo for Revit 2024

Hi,
I have created a couple of scripts where I use a Python node to display a Windows Form for a better user experience.

This has worked fine for Revit 2023 and earlier. However, when trying to run these scripts in Revit 2024, I get an error message saying:
System.Reflection.Emit.TypeBuilder not found.” See the attached picture.

Through a lot of testing, I found out that it is different events like .Click etc., that cause the error.
I have made a simple example with a form and a clickable label. See the code below.

If I remove the line:

self.label.Click += self.label_clicked,

the form is displayed as expected.
I tried to change .Click to other events but got the same error.

I also tried to change from a Windows Form to a WPF Form but got the same error for events then as well.

I guess this has something to do with the upgrade from .NET 4.8 in previous Dynamo versions to 6.0 in Dynamo for Revit 2024, but I am not skilled enough to figure out what the problem is and how to solve it.

Is there anyone here who knows how to solve this?


Code example:


import clr

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

from System.Windows.Forms import Form, Label
from System.Drawing import Point


class SimpleForm(Form):
    def __init__(self):
        self.label = Label()
        self.label.Text = "Label is not clicked"
        self.label.Location = Point(50, 50)
        self.label.Click += self.label_clicked # Click Event that cause error
        self.Controls.Add(self.label)

    def label_clicked(self, sender, args):
        self.label.Text = "Label is clicked"

form = SimpleForm()
form.Show()
1 Like

Hi,

for info, the issue has been reported

2 Likes

Thank you @c.poupin for pointing that out !

Then i have to wait for the bugg to be solved.

Hi, do we have an update on this bug? My dyn script work in Revit 2023 but fails in 2024.

Thank you

@egdivad

the Dynamo team is starting to work on the integration of PythonNet 3 (which should solve several problems, including this one)

I can suggest you to use C# or IronPython3 in the meantime

2 Likes