Click here to Skip to main content
15,867,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,


In the following code, I am getting the following errors;

1. Error CS0234 The type or namespace name 'Form1' does not exist in the namespace 'PdfSloutions' (are you missing an assembly reference?)

2. System.ArgumentNullException: 'Property MainForm cannot be set to Nothing.
Parameter name: MainForm'

Please help.

What I have tried:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Diagnostics;
using System.Windows.Forms;
using System.Linq;
using System.Xml.Linq;

namespace PdfSloutions
{
	namespace My
	{

		internal partial class MyApplication : Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase
		{

			[global::System.Diagnostics.DebuggerStepThroughAttribute()]
			public MyApplication() : base(Microsoft.VisualBasic.ApplicationServices.AuthenticationMode.Windows)
			{
				this.IsSingleInstance = false;
				this.EnableVisualStyles = true;
				this.SaveMySettingsOnExit = true;
				this.ShutdownStyle = Microsoft.VisualBasic.ApplicationServices.ShutdownMode.AfterMainFormCloses;
			}

			[global::System.Diagnostics.DebuggerStepThroughAttribute()]
			protected override void OnCreateMainForm()
			{
                this.MainForm = global::PdfSloutions.Form1.DefaultInstance;
			}

			private static MyApplication MyApp;
			internal static MyApplication Application
			{
				get
				{
					return MyApp;
				}
			}

			[STAThread]
			static void Main(string[] args)
			{
				System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);
				MyApp = new MyApplication();
				MyApp.Run(args);
			}

		}
	}

}
Posted
Updated 3-May-18 22:06pm
Comments
Richard MacCutchan 4-May-18 4:01am    
You have an extra namespace statement at the beginning of your code which, presumably, does not match your Form1 definition module.
Primo Chalice 4-May-18 4:09am    
I removed that, still I am getting the error
Maciej Los 4-May-18 4:21am    

You do not explicitly call Main method. That is the default entry point for your application which framework will call.

The errors you have mentioned tell that there nothing called PdfSloutions.Form1. Either there is nothing called Form1 in that namespace or if it is, it not public.
 
Share this answer
 
Comments
Primo Chalice 4-May-18 4:09am    
I am getting an error there so what can be done?
dan!sh 4-May-18 4:11am    
I just told what you can check. Does that form exist in PdfSolutions?
Quote:
How do I call the main function in C#?

Short answer: You don't, never.
'main' is a special function, it is the starting point of your program and you can't call it in your code.
 
Share this answer
 
Comments
Primo Chalice 4-May-18 4:08am    
But then I am getting an error. What should I do?
Patrice T 4-May-18 4:10am    
what error ?
Primo Chalice 4-May-18 4:37am    
System.ArgumentNullException: 'Property MainForm cannot be set to Nothing.
Parameter name: MainForm'
Patrice T 4-May-18 4:45am    
'MainForm' and function 'main' are two things totally different.
In this case, the question title is completely wrong and misleading.
Primo Chalice 4-May-18 5:01am    
I am sorry, I will post a new question for the solution then :).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900