MSB4025: The project file could not be loaded. Data at the root level is invalid. Line 1, position 1

I'm running this file test.cs using the terminal but i keep getting the error MSB4025: The project file could not be loaded. Data at the root level is invalid. Line 1, position 1
using System;

namespace FavoriteNumber
{
class Program
{
static void Main(string[] args)
{
// Ask user for favorite number
int favNumber;
Console.Write("Enter your favorite number: ");

// Turn the answer into an int
favNumber = Convert.ToInt32(Console.ReadLine());
Console.WriteLine($"Your favorite number is {favNumber}!");
}
}
}
using System;

namespace FavoriteNumber
{
class Program
{
static void Main(string[] args)
{
// Ask user for favorite number
int favNumber;
Console.Write("Enter your favorite number: ");

// Turn the answer into an int
favNumber = Convert.ToInt32(Console.ReadLine());
Console.WriteLine($"Your favorite number is {favNumber}!");
}
}
}
5 Replies
Pobiega
Pobiega5mo ago
C# is project based, not file based. Do you have a .csproj file too?
AllianceCrusader
No
Pobiega
Pobiega5mo ago
Well, thats why then you should be creating projects only via dotnet new not manually creating empty files
AllianceCrusader
ok thanks
Pobiega
Pobiega5mo ago
so for this project, a dotnet new console -n FavoriteNumber or something like that (FavoriteNumber is your project name) sounds reasonable