Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Announcement: WcR2 .Net6 alpha version is ready. #224

Open
Kagamia opened this issue Jun 25, 2023 · 2 comments
Open

Announcement: WcR2 .Net6 alpha version is ready. #224

Kagamia opened this issue Jun 25, 2023 · 2 comments

Comments

@Kagamia
Copy link
Owner

Kagamia commented Jun 25, 2023

I'm trying to migrate wcR2 to .Net 6, but meet some blocking issue.

Here's the migration steps that I plan to take:

  1. migrate .csproj to sdk-style project file, so that we can enjoy the latest C# lang feature.
  2. add multi-target net462;net6.0-windows;netstandard2.0 and make it work. <- I'm blocking here.
  3. upgrade dependency package version.
  4. code style and performance optimization.

You know that wcR2 has strong dependence on Dotnetbar2. So far I can successfully build wcR2 when targeting net6.0, but can't open smoothly.

Here's the first error:

System.EntryPointNotFoundException: Unable to find an entry point named 'SetWindowTheme' in DLL 'user32'.
   at DevComponents.DotNetBar.Controls.ComboBoxEx.SetWindowTheme(IntPtr hWnd, String pszSubAppName, String pszSubIdList)
   at DevComponents.DotNetBar.Controls.ComboBoxEx.ᛤ(IntPtr ह)
   at DevComponents.DotNetBar.Controls.ComboBoxEx.OnHandleCreated(EventArgs e)
   at System.Windows.Forms.Control.WmCreate(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ComboBox.WndProc(Message& m)
   at DevComponents.DotNetBar.Controls.ComboBoxEx.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, WM msg, IntPtr wparam, IntPtr lparam)

It is really funny, by searching from msdn, we know that the SetWindowTheme function is declared in UxTheme.dll, not in user32. Also checked the disassemble code:

public class ComboBoxEx : ComboBox, ICommandSource
{
...
    [DllImport("user32", CharSet = CharSet.Unicode)]
    private static extern int SetWindowTheme(IntPtr hWnd, [MarshalAs(UnmanagedType.LPWStr)] string pszSubAppName, [MarshalAs(UnmanagedType.LPWStr)] string pszSubIdList);
    
    private void ᛤ(IntPtr ह)
    {
        bool flag = false;
        if (Environment.Version.Major > 5)
        {
            flag = true;
        }
        else if (Environment.Version.Major == 5 && Environment.Version.Minor >= 1)
        {
            flag = true;
        }
        if (flag)
        {
            SetWindowTheme(ह, " ", " ");
        }
    }
...
}

It checks the .net runtime version, if Environment.Version is equal to or greater than 5.1, then call SetWindowTheme on itself to reset themes.
This is also very confusing, I believe it should check Environment.OSVersion, because in .net Framework the version can't be greater than 5, so the function is never been called, and even no one was triggered the bug in the past 10 years.🤣

Finally I use Harmony to hook the function and replace with an empty function, now we can start wcR2-net6 version smoothly, only find the UI layout is a bit incorrect.
image

The second exception happens after loading base.wz and click any of the node:

System.TypeLoadException: Could not load type 'System.Windows.Forms.ContextMenu' from assembly 'System.Windows.Forms, Version=6.0.2.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
   at DevComponents.AdvTree.AdvTree.ټ(Node ٓ, MouseEventArgs ؿ, Point ٪)
   at DevComponents.AdvTree.AdvTree.OnMouseDown(MouseEventArgs e)
   at System.Windows.Forms.Control.WmMouseDown(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, WM msg, IntPtr wparam, IntPtr lparam)
   at Interop.User32.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.Interop.Mso.IMsoComponentManager.FPushMessageLoop(UIntPtr dwComponentID, msoloop uReason, Void* pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(msoloop reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(msoloop reason, ApplicationContext context)
   at System.Windows.Forms.Application.Run(Form mainForm)
   at WzComparerR2.Program.StartMainForm() in F:\Coding\visual studio 2012\Working Projects\WzComparerR2\WzComparerR2\Program.cs:line 44
   at WzComparerR2.Program.Main() in F:\Coding\visual studio 2012\Working Projects\WzComparerR2\WzComparerR2\Program.cs:line 25

Dotnetbar2 is .Net FX 2.0 compatible, so it still checks System.Windows.Forms.ContextMenu type in its inner logic, but the class has already deprecated and removed from netcore codebase. see dotnet/winforms#2157

The class is not widely used, but the referenced function is very very long, I've no confidence that the decompiled code could work well. Also ContextMenu is used as property in some type, I can't remove them at runtime.

image

Now I'm stopping here and posting this thread. 😿

@Kagamia
Copy link
Owner Author

Kagamia commented Jun 25, 2023

It is not completely waste of time, I also meet the GraphicsControl memory leak bug (#196), still don't know the root cause but I'm trying to fix it.

Kagamia added a commit that referenced this issue Oct 8, 2023
@Kagamia
Copy link
Owner Author

Kagamia commented Oct 8, 2023

Net6 alpha version released.

Here are some known issues:

  1. Dotnetbar does not fully support .net core, I inject some function before starting, this may cause program unstable.
  2. Default font changed, and may cause some UI layout to be incorrect. <- won't fix, we're planing to remake entire UI window with new framework.
  3. Threading related functions are all deprecated, so long running jobs like Patcher and Comparer can't interrupt, will refactor to Task based functions to support these operation.
  4. ListViewItems are all highlighted even they're not selected, this is just a visual issue, never mind.
  5. TBD

@Kagamia Kagamia changed the title .Net6 migration blocking Announcement: WcR2 .Net6 alpha version is ready. Oct 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant