1

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.

Aleksandar Matic
  • 789
  • 1
  • 9
  • 21
  • 1
    What are you doing in some of those events? Specifically, LocationChanged and VisibleChanged. – LarsTech Dec 20 '16 at 16:38
  • There was no code executed in those events, I added dummy code there just to try to stop the debugger there. Events that do have code are ItemClicked, ItemDoubleClicked, DragDrop and DragEnter, and none of those are triggered when the control is displayed, right? – Aleksandar Matic Dec 20 '16 at 16:43
  • you could comment out all code in all events just to be sure, – GuidoG Dec 20 '16 at 16:58
  • Maybe the drive is too big? Try setting a different location since in your construction you have it set for the `c:\` path. – LarsTech Dec 20 '16 at 17:03
  • @GuidoG I will try that now, but keep in mind that it threw the same exception even when I used that control in a newly added project in that solution without any events or anything. It worked only in a different solution. – Aleksandar Matic Dec 20 '16 at 17:05
  • @LarsTech Nope, it's not that. Just tried it. In a different solution created just to check if the control works, it shows "C:\" without any issues. – Aleksandar Matic Dec 20 '16 at 17:10
  • It looks like the error comes from `GetTypeDescriptionForFile`, so that would point to some kind of file it doesn't like. – LarsTech Dec 20 '16 at 17:22
  • @LarsTech I tried pointing to an empty folder and a folder containing only one SQL script, but I get the same error. News is it's now working if called in a new project within the same solution. Hm... – Aleksandar Matic Dec 20 '16 at 17:28

1 Answers1

0

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.

Aleksandar Matic
  • 789
  • 1
  • 9
  • 21