C
C#11mo ago
Amir

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
Pobiega11mo ago
C# is project based, not file based. Do you have a .csproj file too?
Amir
AmirOP11mo ago
No
Pobiega
Pobiega11mo ago
Well, thats why then you should be creating projects only via dotnet new not manually creating empty files
Amir
AmirOP11mo ago
ok thanks
Pobiega
Pobiega11mo ago
so for this project, a dotnet new console -n FavoriteNumber or something like that (FavoriteNumber is your project name) sounds reasonable
Want results from more Discord servers?
Add your server