Windows Forms - VbPowerPack v1 FileViewer throwing an unexpected exception

73 Views Asked by At

I need to maintain an old legacy Windows Forms application. I just got the source code, no documentation or anything. I'm building the application using Visual Studio 2015 running on a 64-bit Windows 8.1 and using .NET Framework 4.5. Everything works fine except for one thing, a VbPowerPack (version 1.0.1644.16184, tottaly outdated) control named FileViewer is used to display contents of a folder and it just keeps throwing an exception for the first time that pane is set to be visible

System.OverflowException: Arithmetic operation resulted in an overflow.
   at System.IntPtr.ToInt32()
   at VbPowerPack.ShellFolder.GetTypeDescriptionForFile(String in_path) in C:\Documents and Settings\Ken\My Documents\Visual Studio Projects\VbPowerPack Source\VbPowerPack\ShellFolder.vb:line 264
   at VbPowerPack.FileViewer.populateControl() in C:\Documents and Settings\Ken\My Documents\Visual Studio Projects\VbPowerPack Source\VbPowerPack\FileViewer.vb:line 992
   at VbPowerPack.FileViewer.CreateHandle() in C:\Documents and Settings\Ken\My Documents\Visual Studio Projects\VbPowerPack Source\VbPowerPack\FileViewer.vb:line 866
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
   at System.Windows.Forms.TabPage.set_Visible(Boolean value)
   at System.Windows.Forms.TabControl.UpdateTabSelection(Boolean updateFocus)
   at System.Windows.Forms.TabControl.OnSelectedIndexChanged(EventArgs e)
   at System.Windows.Forms.TabControl.WmSelChange()
   at System.Windows.Forms.TabControl.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

(Please note that I'm not Ken mentioned in the exception, the DLL must have been compiled on his computer, and I get the same exception, just without the Ken part, if I use another instance of the same DLL found on the internet)

Exception screenshot

after that, if click "Continue" in the "Unhandled Exception Window" and I click on another tab and then try this one again it shows the control without an exception being thrown again but none of the folder content is there.

I tried adding that same control an a new form in a newly created empty Windows Forms project inside this solution and it behaves the same. But when I create a new empty solution with a new Windows Forms project and use only the FileViewer control it works fine. Also it kind of works in the problematic solution when I open the form in design view (not running the application), it shows me the folder content. I tried debugging but the exception is thrown before it triggers any of the events like "VisibleChanged". I also tried commenting out any other code that could affect this but no luck. Here is how the control is initialized

public partial class DocumentsForm
{
    private VbPowerPack.FileViewer fileViewer;
    ...

    private void InitializeComponent()
    {
        this.fileViewer = new VbPowerPack.FileViewer();
        ...
        this.fileViewer.AllowDrop = true;
        this.fileViewer.ContextMenu = this.contextMenuFiles;
        this.fileViewer.Dock = System.Windows.Forms.DockStyle.Fill;
        this.fileViewer.HideSelection = false;
        this.fileViewer.Location = new System.Drawing.Point(0, 34);
        this.fileViewer.Margin = new System.Windows.Forms.Padding(2, 3, 2, 3);
        this.fileViewer.Name = "fileViewer";
        this.fileViewer.Path = "c:\\";
        this.fileViewer.Size = new System.Drawing.Size(842, 482);
        this.fileViewer.Sorting = System.Windows.Forms.SortOrder.Ascending;
        this.fileViewer.TabIndex = 0;
        this.fileViewer.UseCompatibleStateImageBehavior = false;
        this.fileViewer.ItemClicked += new VbPowerPack.FileViewer.ItemClickedEventHandler(this.fileViewer_ItemClicked);
        this.fileViewer.ItemDoubleClicked += new VbPowerPack.FileViewer.ItemDoubleClickedEventHandler(this.fileViewer_ItemDoubleClicked);
        this.fileViewer.LocationChanged += new System.EventHandler(this.fileViewer_LocationChanged);
        this.fileViewer.VisibleChanged += new System.EventHandler(this.fileViewer_VisibleChanged);
        this.fileViewer.DragDrop += new System.Windows.Forms.DragEventHandler(this.fileViewer_DragDrop);
        this.fileViewer.DragEnter += new System.Windows.Forms.DragEventHandler(this.fileViewer_DragEnter);
        ...
        this.Controls.Add(this.fileViewer);
        ...
    }
}

Struggling for a few days now. Any help and suggestions are welcome.

1

There are 1 best solutions below

0
On BEST ANSWER

Found it! The problem was that VbPowerPack v1 controls needed to be used in a 32-bit application, yeah they are that old. My computer is 64-bit and Visual Studio set the platform target to "Any CPU" by default, which meant 64-bit in my case. The explanation for how it worked in newly added projects is that those Win Forms projects were built with platform target set to "Any CPU" but had "Prefer 32-bit" ticked (checked) by default.

Why didn't I try to run it as x86 before? Well... Running it in 32-bit pulled some other issues with it, but after resolving them the FileViewer control works. Thanks @LarsTech and @GuidoG for trying to help.