tags:

views:

285

answers:

1

Hello there,

I'm having problem when running my Windows Forms program.

In the program, I have a button that calls OpenFileDialog's ShowDialog() everytime it clicked.

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

But when I run the program, everytime I clicked the "Browse" (myButton) button, I got a "MyProgram has encountered a problem and needs to close. We are sorry for the inconvenience." error. When I clicked on the "What data does this error report contain?" link, the Error signature contains

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

Any idea?

A: 

According to MSDN, a TypeLoadException refers to a failure to load a type from an assembly.

I believe that you don't have a suitable version of WinForms installed. What version of .NET and WinForms are you trying to use?

The most basic solution, however, would likely be to reinstall the .NET framework.

MiffTheFox
But I have no problem when running other .NET applications that uses OpenFileDialog. I have .NET Framework 1.1, 2.0 SP2, 3.0 SP2, and 3.5 SP1 installed. with Microsoft Visual C# 2008 Express Edition as the IDE. How to get WinForms version?
djzmo
Additional information: I selected .NET Framework 2.0 as the Target Framework in the Project Properties
djzmo
@djzmo To get your Winforms version, go to the Solution Explorer, expand the References item, right-click System.Windows.Forms and click "Properties". Although, the code worked when I ran it on my machine, so it's likely a DLL hell problem on your end.
MiffTheFox