Search code examples
c#messagebox

MessageBox.Show Error, can not convert from string to 'System.Windows.Forms.IWin32Window


I am developing a desktop application in Visual Studio 2012 and Sql Server 2012. It has been running well until now. Now, following error is being displayed in each line of the code where I have used MessageBox.Show("String"); function.

cannot convert from 'string' to 'System.Windows.Forms.IWin32Window'

I don't remember whether I deleted any necessary libraries or not. As I think, all necessary libraries are included in the project like System.Windows.Form etc.... Please help me to figure out my error... a sample line of code with error is

 MessageBox.Show("Enter Product Name");

Solution

  • It seems as though you have a conflicting class named MessageBox, with a Show() method.

    You should change the name of your own user-defined MessageBox class so that it doesn't conflict. If that's not possible for some reason, you can use a using directive to define an alias to ensure against the conflict.