dotnet / winforms

Windows Forms is a .NET UI framework for building Windows desktop applications.
MIT License
4.41k stars 984 forks source link

[dotnet-sdk-9.0.100-preview.4.24223.3] When launch Analogy.LogViewer, it shows error “The type initializer for 'FormIconHelper' threw an exception”. #11261

Closed Junjun-zhao closed 6 months ago

Junjun-zhao commented 6 months ago

.NET version

.NET SDK:
 Version:             9.0.100-preview.4.24223.3
 Commit:            a86b2fed47
 Workload version:  9.0.100-manifests.fb4db8ea
 MSBuild version:   17.11.0-preview-24218-01+195e9289b

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19045
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\9.0.100-preview.4.24223.3\

.NET workloads installed:
 [aspire]
   Installation Source: VS 17.10.34707.107
   Manifest Version:    9.0.0-preview.4.24210.26/9.0.100-preview.1
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\9.0.100-preview.1\microsoft.net.sdk.aspire\9.0.0-preview.4.24210.26\WorkloadManifest.json
   Install Type:              Msi

Host:
  Version:      9.0.0-preview.4.24218.7
  Architecture: x64
  Commit:       b0118bebe3

.NET SDKs installed:
9.0.100-preview.4.24223.3 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 9.0.0-preview.4.24218.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 9.0.0-preview.4.24218.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 9.0.0-preview.4.24218.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Did it work in .NET Framework?

Yes

Did it work in any of the earlier releases of .NET Core or .NET 5+?

Yes

Verify Scenarios:

  1. Windows10 21h2 x64 + dotnet-sdk-9.0.100-preview.4.24223.3: Fail
  2. Windows10 21h2 x64 + dotnet-sdk-9.0.100-preview.4.24221.1: Fail
  3. Windows10 21h2 x64 + dotnet-sdk-9.0.100-preview.4.24216.1: Fail
  4. Windows10 21h2 x64 + dotnet-sdk-9.0.100-preview.3.24204.13: Fail
  5. Windows10 21h2 x64 + dotnet-sdk-8.0.204-win-x64: Pass

Issue description

When we run Analogy.exe with dotnet-sdk-9.0.100-preview.4.24223.3, it will pop up window with error:System.TypeInitializationException: 'The type initializer for 'FormIconHelper' threw an exception.'.

Application Name: Analogy.LogViewer OS: Windows 10 21H2 CPU: X64 .NET Build Number: dotnet-sdk-9.0.100-preview.4.24223.3 App Source Location, demo checking at https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2045273

Github Link: https://github.com/Analogy-LogViewer/Analogy.LogViewer

Steps to reproduce

Minimal Repro steps (Demo attached WinFormDemo.zip) The machine has dotnet-sdk-9.0.100-preview.4.24223.3 installed.

  1. Create a new .NET 8.0 Winforms App.
  2. Add Project Reference: DevExpress.Utils.v23.2.dll and DevExpress.XtraBars.v23.2.dll.
  3. Add the following code in From1.cs:
    using DevExpress.XtraBars.Ribbon;
    namespace WinFormDemo
    {
    public partial class Form1 : RibbonForm
    {
        public Form1()
        {
            InitializeComponent();
        }
    }
    }
  4. Build the app and change the runtime to .NET 9.0:
    "frameworks": [
      {
        "name": "Microsoft.NETCore.App",
        "version": "9.0.0-preview.4.24218.7"
      },
      {
        "name": "Microsoft.WindowsDesktop.App",
        "version": "9.0.0-preview.4.24218.3"
      }
    ]
  5. Run the app.

Expected Result: Run successfully. Actual Result: Show error: System.TypeInitializationException: 'The type initializer for 'FormIconHelper' threw an exception.'

Finding: There is an app issue (DevExpress version23.1) we filed before for .NET 9 Preview1 and Preview2: [[dotnet-sdk-9.0.100-alpha.1.24070.3] AnalogyLogViewer launch failed with error: "System.AccessViolationException: Attempted to read or write protected memory..." · Issue #10719 · dotnet/winforms (github.com)](https://github.com/dotnet/winforms/issues/10719) And even we upgrade DevExpress to version 23.2 (latest version), this issue still exists in .NET 9 Preview 1 and Preview 2. But start from .NET 9 Preview 3, previous error was gone, and we get 'The type initializer for 'FormIconHelper' threw an exception.' exception now.

@dotnet-actwx-bot @dotnet/compat

Olina-Zhang commented 6 months ago

We can repro this issue in .Net 9.0(form designer cannot be loaded successfully), not .Net 8.0, here is the call stack --- it seems to be a DevExpress product issue.

System.TypeInitializationException
  HResult=0x80131534
  Message=The type initializer for 'FormIconHelper' threw an exception.
  Source=DevExpress.Utils.v23.2
  StackTrace:
   at DevExpress.XtraEditors.FormIconOptions.FormIconHelper..ctor(Form form)
   at DevExpress.XtraEditors.FormIconOptions.Initialize()
   at DevExpress.XtraEditors.FormIconOptions..ctor(IFormIconOptionsOwner owner, Boolean initIconImmediately)
   at DevExpress.XtraEditors.FormIconOptions..ctor(IFormIconOptionsOwner owner)
   at DevExpress.XtraEditors.XtraForm.CreateIconOptions()
   at DevExpress.XtraEditors.XtraForm..ctor()
   at DevExpress.XtraBars.Ribbon.RibbonForm..ctor()
   at WinFormsApp11.Form1..ctor() in C:\Users\xxx\source\repos\WinFormsApp11\WinFormsApp11\Form1.cs:line 6
   at WinFormsApp11.Program.Main() in C:\Users\xxx\source\repos\WinFormsApp11\WinFormsApp11\Program.cs:line 14

Inner Exception 1:
NullReferenceException: Object reference not set to an instance of an object.
merriemcgaw commented 6 months ago

Unfortunately, this looks to be an issue with private reflection on internal types, and we can't promise that this internal surface doesn't change.

Junjun-zhao commented 6 months ago

@merriemcgaw @JeremyKuhne Thank you for helping investigate this issue. Any updates regarding it? Could you please let us know if this issue is a blocker for .NET 9 Preview 4?

elachlan commented 6 months ago

@Junjun-zhao was Devexpress 24.1 tested? I've raised a Devexpress support issue at: https://supportcenter.devexpress.com/ticket/details/t1231900/exception-in-formiconhelper-net9-preview

Junjun-zhao commented 6 months ago

@Junjun-zhao was Devexpress 24.1 tested? I've raised a Devexpress support issue at: https://supportcenter.devexpress.com/ticket/details/t1231900/exception-in-formiconhelper-net9-preview

Thank you for sharing the link . So this is also Devexpress issue , right ? No. We tried to download the latest trial version from the official site , the version is still V23.2 .

elachlan commented 6 months ago

@Junjun-zhao apparently it has been fixed in v23.2.6

Junjun-zhao commented 6 months ago

Thank you very much @elachlan Verified this issue with the latest build 9.0.100-preview.4.24257.5, it has been fixed with Devexpress v23.2.6 . Hence closing it.