【问题标题】:Windows Forms - VbPowerPack v1 FileViewer throwing an unexpected exceptionWindows 窗体 - VbPowerPack v1 FileViewer 引发意外异常
【发布时间】:2016-12-20 16:34:56
【问题描述】:

我需要维护一个旧的旧版 Windows 窗体应用程序。我只是得到源代码,没有文档或任何东西。 我正在使用在 64 位 Windows 8.1 上运行并使用 .NET Framework 4.5 的 Visual Studio 2015 构建应用程序。一切正常,除了一件事,一个名为 FileViewer 的 VbPowerPack(版本 1.0.1644.16184,完全过时)控件用于显示文件夹的内容,它只是在第一次将该窗格设置为可见时抛出异常

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)

(请注意,我不是在异常中提到的 Ken,DLL 一定是在他的计算机上编译的,如果我使用找到的同一个 DLL 的另一个实例,我会得到相同的异常,只是没有 Ken 部分网上)

之后,如果单击“未处理的异常窗口”中的“继续”,然后单击另一个选项卡,然后再次尝试此选项,它会显示控件而不会再次引发异常,但文件夹内容不存在。

我尝试在此解决方案内新创建的空 Windows 窗体项目中添加相同的控件和新窗体,它的行为相同。但是,当我使用新的 Windows 窗体项目创建一个新的空解决方案并仅使用 FileViewer 控件时,它可以正常工作。当我在设计视图中打开表单(不运行应用程序)时,它也适用于有问题的解决方案,它向我显示文件夹内容。 我尝试调试,但在触发任何事件(如“VisibleChanged”)之前引发了异常。我还尝试注释掉任何其他可能影响这一点但没有运气的代码。下面是控件的初始化方式

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);
        ...
    }
}

现在挣扎了几天。欢迎任何帮助和建议。

【问题讨论】:

  • 你在这些活动中做了什么?具体来说,LocationChanged 和 VisibleChanged。
  • 在这些事件中没有执行任何代码,我在那里添加了虚拟代码只是为了尝试在那里停止调试器。有代码的事件是ItemClicked、ItemDoubleClicked、DragDrop和DragEnter,这些都不是在控件显示时触发的,对吧?
  • 你可以注释掉所有事件中的所有代码,以确保,
  • 可能是驱动器太大了?尝试设置一个不同的位置,因为在你的构造中你已经为 `c:` 路径设置了它。
  • @GuidoG 我现在会尝试,但请记住,即使我在该解决方案中新添加的项目中使用该控件而没有任何事件或任何东西,它也会引发相同的异常。它只适用于不同的解决方案。

标签: c# .net winforms vb-power-pack


【解决方案1】:

找到了!问题是 VbPowerPack v1 控件需要在 32 位应用程序中使用,是的,它们太旧了。我的计算机是 64 位的,Visual Studio 默认将平台目标设置为“任何 CPU”,在我的情况下这意味着 64 位。它在新添加的项目中如何工作的解释是,这些 Win Forms 项目是在平台目标设置为“任何 CPU”的情况下构建的,但默认勾选(选中)“首选 32 位”。

为什么我以前不尝试将它作为 x86 运行?嗯...以 32 位运行它会带来一些其他问题,但在解决这些问题后,FileViewer 控件可以正常工作。感谢@LarsTech 和@GuidoG 提供帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-19
    • 1970-01-01
    • 2016-09-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多