Having a problem with adding an xUnit Test Project for .Net 5.0, error described below, please help.

Alina Nakhamchik 21 Reputation points
2021-12-05T00:28:41.537+00:00

Hi, I'm sorry if this isn't an appropriate place for this question.
I am trying to add an xUnit test project to my solution (framework .Net 5.0). Once I add the project as described in numerous tutorials I am getting the following error resulting in the following message "the type or namespace name "Fact", "FactAttribute" could not be found, are you missing a using statement. "

Here is the error:

Error occurred while restoring NuGet packages: An error occurred while retrieving package metadata for 'Microsoft.CSharp.4.0.1' from source 'C:\Program Files\dotnet\sdk\NuGetFallbackFolder'.

If I do a dotnet restore in the CLI I get the following:
C:\Program Files\dotnet\sdk\5.0.403\NuGet.targets(131,5): error : An error occurred while retrieving package metadata for 'Microsoft.CSharp.4.0.1' from source 'C:\Program Files\dotnet\sdk\NuGetFallbackFolder'. [C:\Users\ia\source\repos\AlgoExpert3\AlgoExpert3.sln]
C:\Program Files\dotnet\sdk\5.0.403\NuGet.targets(131,5): error : '.', hexadecimal value 0x00, is an invalid character. Line 1, position 1. [C:\Users\ia\source\repos\AlgoExpert3\AlgoExpert3.sln]

Note: When the project gets added a using statement is also created: using Xunit

Here is the .csproj:
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>

<IsPackable>false</IsPackable>

</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

</Project>

The project is completely empty, I haven't written any code anywhere. This is just step 1. Any help would be greatly appreciated!

Developer technologies ASP.NET ASP.NET Core
Developer technologies C#
{count} votes

1 answer

Sort by: Most helpful
  1. Alina Nakhamchik 21 Reputation points
    2021-12-08T02:06:09.283+00:00

    Hi Dillion! Thank you for responding -- I am not using the Microsoft.Csharp.4.01, and I'd tried to clear the cache before :( I tried it again and restarted visual studio, same result. It's clearly stuck somewhere... I don't think it's clearing the NuGet cache.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.