Chadderbox
Chadderbox

Reputation: 65

Data at the root level is invalid even when not using xml file

I am trying to run this code:

using System;

public class Program
{
    public static int Main()
    {
        int i; 
        int basee;
        for (basee = 2;; basee += 1) {
            for (i = 2; i < basee; i++) {
                    if ((basee % i) == 0)
                    break;
            }
        if (i == basee)
            Console.WriteLine(basee);
        }
        return 0;
    }
}

However, when I try to compile this code with dotnet build prime.cs, it results in the error Data at the root level is invalid. Line 1, position 1..

From a google search, this error comes up when an XML file is invalid, but I am not doing anything with an xml file here.

Does anyone have the solution for this? Am I running the wrong command in cmd? I have tried csc but I get an error that it is not installed, when I have both dotnet core and framework installed between my two pcs.

Upvotes: 0

Views: 366

Answers (1)

KevinLamb
KevinLamb

Reputation: 634

If you haven't, you can create a project first using the command dotnet new. Below creates a new console application in .NET Core. The -n parameter specifies the name of your project.

dotnet new console -n Prime

With your new project you can start developing a console application. Once you're done creating your app, you can run it while in the project directory:

dotnet run

and build your project using the build command:

dotnet build 

Upvotes: 2

Related Questions