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'. -
I'm totally confused now. The file that you attached doesn't include images. Also, you indicated that the error message was "class already exists". But now, you're saying that it's throwing a BadImageFormatException.
Is this a different problem that you're reporting? Are you able to provide something that allows me to reproduce the actual problem?
-
Sorry, the issue appears more complex than previously thought, also depending on the Cpu-Version of Linqpad:
prerequisites:Assembly 1, AnyCpu, depending on DevExpress (3rd party) libraries and System.Drawing hosting 2 methods:
- method1 (MessageBox-wrapper), no image involved
- method2 containing an image
Assembly 2, AnyCpu, no external dependencies
- method 1, simple form, no image involved
myextensions is totally empty (the issues are re-producable in standalone lp-scripts)
- machine: Parallels-VM on iMac, ARM-Based
execution:
LP X64
- Assembly1.method1: initial error of 'class already exists '
- Assembly2.method1: no issues
- Assembly1.method2: 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'.
LP ARM64
- Assembly1.method1, requires extra reference to System.Drawing: BadImageFormatException (Could not load file or assembly 'System.Windows.Forms, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. Format of the executable (.exe) or library (.dll) is invalid., Could not load file or assembly '%localappdata%\Temp\LINQPad8_bdwfrzag\shadow-1\System.Windows.Forms.dll'.)
- Assembly2.method1: no issues
since Assembly2.method1 has no issue in whatever setup, the problems must be on my side. however the methods of Assembly1 are perfectly callable from out net9-csproj-programs and were under LP 5.0 (net48 based).
thank you for your patience - LP is such an invalueable tool for prototyping and customer service/reporting - that's why i call for suggestions/help. the move to netcore was necessary for the product to stay alive. -
Because I don't have your DevExpress libraries, I can't reproduce this, so it's hard to offer suggestions. One clue is that your project appears to have an explicit dependency on System.Drawing. This might be unnecessary and could be adding to or creating the problem. The System.Drawing types are distributed between .NET Core and .NET Core Desktop runtime assemblies. If it's a Windows Forms project with
<UseWindowsForms>true</UseWindowsForms>, the compiler should bring in all required dependencies automatically, using the correct target (X64 or ARM64).If it's possible to create a simple repro that doesn't rely on third-party components, I'm happy to take another look at it.
-
thank you Joe, i will look into the System.Drawing issue. In case i have further issues i come back with another ticket.
great product!
