+-
错误:应用程序错误是System.Windows.Application和System.Windows.Forms.Application之间的引用
我正在Visual Studio 2013中运行它.

对于Application.Current.Shutdown我得到:

“应用程序”是“ System.Windows.Application”和“ System.Windows.Forms.Application”之间的歧义引用.

我尝试使用SystemInformation = System.Windows.Forms.SystemInformation;建议将System.Windows.Forms用作一个站点,但出现错误:

找不到行OpenFileDialog的类型或名称空间名称“ OpenFileDialog”(您是否缺少using指令或程序集引用?)dlg = new OpenFileDialog();

我该如何修复它才能使用OpenFileDialog?我希望显示一个打开文件对话框.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using PTDGUI.View;  

private void mnuExit_Click(object sender, RoutedEventArgs e)
{
    Application.Current.Shutdown();
}

private void button1_Click(object sender, EventArgs e)
{
    OpenFileDialog dlg = new OpenFileDialog();
    dlg.ShowDialog();

    if (dlg.ShowDialog() == DialogResult.OK)
    {
       string fileName;
       fileName = dlg.FileName;
       MessageBox.Show(fileName);
    }
}
最佳答案
尝试这样做以避免Application类的歧义.

private void mnuExit_Click(object sender, RoutedEventArgs e)
{
    System.Windows.Application.Current.Shutdown();
}

更新资料

这种歧义的原因是名称空间System.Windows.Forms和System.Windows都包含类Application的定义.因此,此时C#编译器会混淆要引用的Application的哪个实现.

如果您没有从System.Windows.Forms引用任何类,则可以将其从using列表中删除.

点击查看更多相关文章

转载注明原文:错误:应用程序错误是System.Windows.Application和System.Windows.Forms.Application之间的引用 - 乐贴网