[FlexChart] Invalid Cast Exception

Posted by: jak on 2 May 2024, 7:15 am EST

  • Posted 2 May 2024, 7:15 am EST

    Hi,

    For testing I have a simple form with a FlexChart. I receive the following unhandled exception.

    System.InvalidCastException: Specified cast is not valid.
      at C1.Util.DX.HResult.ThrowException () [0x0000b] in <6c47f93b00ff472aa889e8dbffd89277>:0 
      at C1.Util.DX.HResult.CheckError () [0x00009] in <6c47f93b00ff472aa889e8dbffd89277>:0 
      at C1.Util.DX.DXGI.SwapChain.GetBuffer (System.Int32 buffer, System.Guid riid) [0x0002b] in <6c47f93b00ff472aa889e8dbffd89277>:0 
      at #5ln.#4ln.#Vbg (System.IntPtr #frd) [0x00191] in <f1fad3d92ac849f9b32d5b05d62b4269>:0 
      at #5ln.#4ln.#3ln (System.Object #ci, System.EventArgs #di) [0x00019] in <f1fad3d92ac849f9b32d5b05d62b4269>:0 
      at System.Windows.Forms.Control.OnHandleCreated (System.EventArgs e) [0x00277] in <f8ddac92d8e04f8abe177f57ba0387df>:0 
      at System.Windows.Forms.Control.WmCreate (System.Windows.Forms.Message& m) [0x0002c] in <f8ddac92d8e04f8abe177f57ba0387df>:0 
      at System.Windows.Forms.Control.WndProc (System.Windows.Forms.Message& m) [0x004ce] in <f8ddac92d8e04f8abe177f57ba0387df>:0 
      at System.Windows.Forms.Control+ControlNativeWindow.OnMessage (System.Windows.Forms.Message& m) [0x00001] in <f8ddac92d8e04f8abe177f57ba0387df>:0 
      at System.Windows.Forms.Control+ControlNativeWindow.WndProc (System.Windows.Forms.Message& m) [0x000b3] in <f8ddac92d8e04f8abe177f57ba0387df>:0 
      at System.Windows.Forms.NativeWindow.Callback (System.Windows.Forms.Message& m) [0x00025] in <f8ddac92d8e04f8abe177f57ba0387df>:0

    I am guessing that the #5ln, #4ln and #Vbg are the parameters being passed to the C1.Util.DX.DXGI.SwapChain.GetBuffer() function. I am also guessing that the C1…GetBuffer() is then calling the windows .GetBuffer() function.

    I think the windows .GetBuffer() is throwing up the exception.

    What is flexChart trying to do when it causes the exception?

    Is there a way to debug/show the value of the parameters?

    Thank you,

  • Posted 2 May 2024, 7:37 pm EST

    Hi,

    We created a sample project using the latest version (4.8.20233.643) of FlexChart, and unfortunately, we could not reproduce the error on our end. The sample project is attached for your reference.

    If you have a different implementation or specific data that is causing the issue, please share a stripped-down version of your project or update the attached project, so we can investigate further on this and assist you as best as possible.

    Attachment: FlexChartDemo.zip

    Thanks, and Kind Regards,

    Kartik

  • Posted 21 May 2024, 9:56 am EST - Updated 22 May 2024, 3:41 am EST

    Kartik,

    I have been given the task to explore if the C1 controls will run in wine on Linux. My host computer is running Ubuntu 22.04 LTS (jammy-jelly), the latest stable version of wine (9.0) and wine-mono. All of the C1 controls that we use run except FlexChart.

    I receive the following Unhandled Exception when running the provided FlexChartDemo example.

    ************** Exception Text **************
    System.InvalidCastException: Specified cast is not valid.
      at C1.Util.DX.HResult.a () [0x0000b] in <d961e0fb3f28459999877003373f0ebb>:0 
      at C1.Util.DX.HResult.CheckError () [0x00009] in <d961e0fb3f28459999877003373f0ebb>:0 
      at C1.Util.DX.DXGI.SwapChain.GetBuffer (System.Int32 buffer, System.Guid riid) [0x0002b] in <d961e0fb3f28459999877003373f0ebb>:0 
      at bpa.a (System.IntPtr A_0) [0x0017c] in <5299db0be2504182b1e081f851d40fca>:0 
      at bpa.a (System.Object A_0, System.EventArgs A_1) [0x00019] in <5299db0be2504182b1e081f851d40fca>:0 
      at System.Windows.Forms.Control.OnHandleCreated (System.EventArgs e) [0x00277] in <ef3dd1b1af11490e89408e0d9c28d1f0>:0

    I have narrowed the problem down to something inside the C1.FlexChart.4.8.dll

    Here are the steps to reproduce the exception.

    • start with fresh install of Ubuntu 22.04 LTS

    installing wine

    sudo dpkg --add-architecture i386
    • add repository
    sudo mkdir -pm755 /etc/apt/keyrings
    sudo wget -O /etc/apt/keyrings/winehq-archive.key https://dl.winehq.org/wine-builds/winehq.key
    sudo wget -NP /etc/apt/sources.list.d/ https://dl.winehq.org/wine-builds/ubuntu/dists/jammy/winehq-jammy.sources
    • install wine - stable branch - at the time of this message, the latest wine stable version was 9.0
    sudo apt-get update
    sudo apt install --install-recommends winehq-stable
    • create a 32-bit wine prefix script
    mkdir ~/bin
    cat > ~/bin/wine32_prefix << "EOF"
    # this creates a 32-bit wine prefix
    export WINEPREFIX=~/.wine32
    export WINEARCH=win32
    EOF
    chmod +x ~/bin/wine32_prefix
    • run the script to setup the wine environment
    source ~/bin/wine32_prefix

    run your first wine program

    # winecfg is installed as part of --install-recommends
    winecfg
    • Wine Mono Installer dialog will be displayed

      click [Install]
    • wine Configuration dialog will be displayed

      choose Windows Version: Windows 7

      click OK to exit winecfg
    • you have created a new hidden directory ‘~/.wine32’ located in your home directory. To list the hidden directory type ‘ls -a’
    cd
    ls -a
    • you are done with installing and setting up wine

    run the FlexChartDemo.exe

    • create a flextemp folder on the Ubuntu computer
    mkdir ~/flextemp
    • build the demo on your windows computer and copy to the flextemp directory -OR- unzip the attached FlexChart.zip into the flextemp folder
    • set the wine prefix environment - this is required once each time you open a new terminal window
    source ~/bin/wine32_prefix
    • run the FlexChartDemo.exe in wine
    cd ~/flextemp
    wine FlexChartDemo.exe

    The exception dialog is displayed - click on [Details] to see the exception text.

    • Note: if you click on [continue] then the FlexChart is displayed and the chart acts normal.

    I attached the executable I built from the provided code.

    Please advise if you can duplicate the problem.

    Sincerly,

    MesciusFlexChartDemoBuilt.zip

  • Posted 21 May 2024, 9:14 pm EST

    Hi,

    Thanks a lot for sharing all the details. We are setting up an environment similar to yours for testing the behavior you mentioned, and will get back to you with the updates as soon as possible.

    We appreciate your patience.

    Best Regards,

    Kartik

  • Posted 22 May 2024, 5:39 am EST

    Kartik,

    First thank you so much making an attempt to setup the environment to see my problem.

    I have edited the above post’s syntax to make the instructions easier to follow. Let me know if you have trouble with any of the steps and I will try to give more detail about what the step is doing.

    When you are ready, wine-mono has some optional command lines to help with debugging

    # these command lines may provide you with more clues
    WINE_MONO_TRACE=E:System.InvalidCastException wine FlexChartDemo.exe
    WINE_MONO_TRACE=M:C1.Util.DX.DXGI.SwapChain:GetBuffer wine FlexChartDemo.exe
    WINE_MONO_TRACE=M:C1.Util.DX.HResult:CheckError wine FlexChartDemo.exe
    WINE_MONO_TRACE=M:C1.Util.DX.HResult:a wine FlexChartDemo.exe
    # you can combine them
    WINE_MONO_TRACE=M:C1.Util.DX.DXGI.SwapChain:GetBuffer,M:C1.Util.DX.HResult:CheckError,M:C1.Util.DX.HResult:a wine FlexChartDemo.exe

    Thank you,

  • Posted 22 May 2024, 10:49 pm EST

    Hi,

    Thanks a lot for providing the detailed steps. These steps helped us a lot in reproducing the behavior you mentioned :-).

    We have shared all the observations with the development team to get their insights on your use-case and will let you know the updates as soon as possible.

    [Internal Tracking Id: C1WIN-32189]

    Kind Regards,

    Kartik

  • Posted 24 May 2024, 4:17 am EST

    Kartik,

    I look forward to what the development team reports. Here is a snippet from Form1.Designer.cs

    private C1.Win.Chart.FlexChart flexChart1;

    The Unhandled Exception occurs when the form is instantiated. I think there is a property of the form that is not set correctly which causes an exception to be thrown when flexChart1 is instantiated. I have tried wrapping the code with try()/catch(), but the exception is being thrown inside the FlexChart code before my try/catch can catch it. I am guessing that the incorrect property could be part of windows (wine) such as Localization, Culture… If that is the problem, then what I would like to know is what property is FlexChart1 complaining about.

    Other than C1 throwing an exception, is there a setting in C1 to provide more verbose information about what the control is complaining about?

    Typically, how long before we hear back from the development team?

    Thank you,

  • Posted 26 May 2024, 7:27 pm EST

    Hi,

    Thank you for sharing your observation. We have already shared it with the development team while escalating this case.

    The developers quickly researched the issue and believe they can add a fix for this issue in the 2024v1 hotfix 1 release. Afterwards, the FlexChart should work with Wine in the Default RenderMode, but the DirectX mode will not be supported (RenderModes).

    Best Regards,

    Kartik

  • Posted 28 May 2024, 3:20 am EST

    Kartik,

    Thank you for the RenderMode link.

    I am excited to hear that the development team believe they can add a fix. If it would be helpful, I am willing to beta test the fix and give feedback.

    Thank you,

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels