System.Windows.Forms.OpenFileDialog(C#)中的System.TypeLoadException

问题描述:

我在运行我的Windows窗体程序时遇到了问题。System.Windows.Forms.OpenFileDialog(C#)中的System.TypeLoadException

在程序中,我有一个按钮,每次单击时调用OpenFileDialog的ShowDialog()。

public partial class MyProgram : Form 
{ 
    private Button myButton; 
    private OpenFileDialog openFD; 
    private string filePath; 
    public MyProgram() 
    { 
    InitializeComponent(); 
    myButton = new Button(); 
    openFD = new OpenFileDialog(); 
    filePath = string.Empty; 
    myButton.Text = "Browse"; 
    myButton.Click += new EventHandler(ShowOpenDialog); 
    } 
    private ShowOpenDialog(object sender, EventArgs e) 
    { 
    if(openFD.ShowDialog() == DialogResult.OK) // Here 
    { 
     filePath = openFD.FileName; 
    } 
    } 
}

但是当我运行该程序,每次我点击“浏览”(为myButton)按钮,我得到了一个“MyProgram遇到问题,需要关闭。我们很抱歉给您带来不便。”错误。当我点击“这个错误报告包含什么数据?”错误签名包含

EventType : clr20r3  P1 : myprogram.exe  P2 : 1.0.0.0  P3 : 4a49b0bf 
P4 : system.windows.forms  P5 : 2.0.0.0  P6 : 4889dee7  P7 : 188f  
P8 : 32  P9 : system.typeloadexception

任何想法?

根据MSDN,TypeLoadException是指未能从程序集加载类型。

我相信你没有安装合适的WinForms版本。你试图使用什么版本的.NET和WinForms?

但是,最基本的解决方案可能是重新安装.NET框架。

+0

但是在运行使用OpenFileDialog的其他.NET应用程序时,我没有任何问题。我安装了.NET Framework 1.1,2.0 SP2,3.0 SP2和3.5 SP1。使用Microsoft Visual C#2008 Express Edition作为IDE。如何获取WinForms版本? – 2009-06-30 07:12:16