Compilation error on Windows " The namespace <proj name> already contains a definition for 'Main'"

How to solve the Compilation error on Windows - The namespace already contains a definition for 'Main'?

In Windows project compatibilities, during project compilation, this error may occur:

Unexpected error has occurred during the library compilation process: The assembly compilation returned the following errors: (1,xxx): error CS0101: The namespace 'project name' already contains a definition for 'Main'

Root Cause: UiPath implements the same behavior as Microsoft does in working with Visual Studio.

  • A file (and the containing class) in the root folder of the project will receive, by default, the namespace name of the containing project (see file Main.cs and the class Main, of the namespace MyClassLibrary).
  • A file (and the containing class) in a folder of the project will receive, by default, the namespace name of the containing project concatenated by dot with the name of the folder (see file Sequence.cs and the class Sequence, of the namespace MyClassLibrary.Main).
  • Using this combination of names (same name used for a file in the root folder and a directory of the project) will generate also in Microsoft environment the same error: The namespace 'MyClassLibrary' already contains a definition for 'Main'.


Resolution:

In Windows projects where compilation error such as "The namespace already contains a definition for 'Main'" is thrown, take into account the below rules:

  1. Do not name any xaml file in the project as Init.xaml
  2. A XAML file placed in the root folder of a project cannot have the same name as a subfolder which contains other XAML files. If that is the case, rename the XAML file
  3. It is not possible to run Windows projects that invoke workflows containing files or folders named Main. Invoke other files or rename the invoked file, if possible.



    1 Like