LinqPad 9 winforms: class already exists
i am using lp since net48 days where i consumed some of my winforms assemblies without problems.
however in version 9 i get above error. the assembly i use is a net9-assembly which i have assigned in MyExtensionsHeNaRaMessageBox.Info("hallo");
creates the exception with this stacktrace
at System.Windows.Forms.NativeWindow.WindowClass.RegisterClass()
at System.Windows.Forms.NativeWindow.WindowClass.Create(String className, WNDCLASS_STYLES classStyle)
at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
at System.Windows.Forms.Control.CreateHandle()
at System.Windows.Forms.Application.ThreadContext.get_MarshallingControl()
at System.Windows.Forms.WindowsFormsSynchronizationContext..ctor()
at LINQPad.UI.RuntimeUIServices.CreateSynchronizationContext()
at LINQPad.Util.CreateSynchronizationContext(Boolean reportActivity)
Answers
-
I've tried creating a WinForms project with a method to show a dialog, referenced it from My Extensions, and can call without error. I've also tried running it from a worker thread, again without error.
Can you provide a full repro, please?
-
hmmm. thank you. here is a simple winforms project https://dropbox.com/scl/fi/askp0zlg2rymyupjmaypj/WinFormsLib.7z?rlkey=5a9b25v8w6qt54ay0wwn83m7o&dl=0
in MyExtensions i wrap it like this
public static void ShowSimpleForm() => WinFormsLib.Class1.ShowForm();- then i compile and simply call it viaMyExtensions.ShowSimpleForm()from a new script. the form shows - the exceptions comes after the button on the form is clicked -
I still can't reproduce this. Is there anything unusual about your setup or environment? Can you double-check you don't also experience this error in LINQPad 8?
-
aaah, i am deeply sorry. instead of Linqpad 9 i was refering to Linqpad 8 all the time. our company plans the upgrade next month
-
so the title is confusing - it is all about Linqpad 8 - however the problem still exists. we are using .net9.
-
@JoeAlbahari could you help me/us? (we have a 10-team license and plan to upgrade ...
)
thank you -
Can you please report:
- Whether you can reproduce the problem on another machine
- Whether the problem also occurs when you target .NET 8
- Whether the problem also occurs when you run the script directly from My Extensions (or a separate script, without using My Extensions)
- Whether the problem also occurs with LINQPad 9 (you can test it with the free edition)
-
thank you, without my MyExtensions (and the usage of my net9 assemblies) the sample project works in net9. so it must be my winforms-assemblies. no issues on the linqpad side (though the assemblies/forms load fine with my c# applications)
-
there are forms within the winforms-assembly that have resources (images) that cause the problem - however it is no issue when consuming them from a c#-net9-application.
it ends in a BadImageFormatException - The type serialized in the .resources file was not the same type that the .resources file said it contained. Expected 'System.Drawing.Bitmap' but read 'System.Drawing.Bitmap'.
