The type or namespace name 'Fakes' does not exist in the namespace 'System' (are you missing an assembly reference?)

Pham Minh Tu 1 Reputation point
2020-11-30T09:36:53.093+00:00

Hi,

I got this issue when porting the Unit Test Project from .NET Framework to .NET core 3.1.
I do not understand what caused the issue.

43569-image.png

Could you please solve it if have any?
I used VS Studio 2019, v16.8.2

Developer technologies | Visual Studio | Testing
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Tianyu Sun-MSFT 34,691 Reputation points Microsoft External Staff
    2020-12-01T07:18:21.96+00:00

    Hi @Pham Minh Tu ,

    Thank you for taking time to post this issue in Microsoft Q&A forum.

    It seems that there are something wrong with the assemblies(Fakes), maybe the versions, or some related files that generated before, under .NET Framework, but are not supported in .NET Core 3.1.

    I suggest you try to remove the Fakes, the FakesAssemblies, the bin and obj folders in your project folder, then try to re-add the projects reference in VS (right-click the Dependencies > Add Project Reference… > Uncheck the project checkbox > OK > Do the same operations but this time check the project checkbox > OK).

    After that re-add the Fakes Assembly(right-click the project under Dependencies , Projects > Add Fakes Assembly) and rebuild then rerun your project. Please remember to make a backup of your solution and then delete the folders.

    In short, make a backup of your solution > delete Fakes, FakesAssemblies, bin and obj folders > re-add the project reference > re-add the Fakes Assembly > rebuild your unit test project > run the test.

    Hope this helps.

    Sincerely,
    Tianyu

    • If the answer is helpful, please click "Accept Answer" and upvote it.
      Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
    0 comments No comments

  2. Pham Minh Tu 1 Reputation point
    2020-12-01T07:46:54.557+00:00

    Hi @Tianyu Sun-MSFT ,
    Thank you for your response.

    I will try it.

    But I have other concern that I got the issue from fake of System library
    System.Fake....
    44031-image.png
    And I solved the following ways.
    43969-image.png

    43954-image.png
    If I am wrong, please give me a solution.
    Thank you.


  3. Johannes 1 Reputation point
    2021-04-28T06:25:42.82+00:00

    Hello,

    i have the same problem with Xunit under .NET 5. I'm not able to use shims there.

    I added a new Xunit project for .NET 5, i went to Frameworks / Microsoft.NETCore.App, right click on System and "Add Fakes Assembly". VS added some packages and created a fakes folder.

    ![91917-image.png]2

    When i try to use shims for DateTime i got the message:
    The type or namespace name 'Fakes' does not exist in the namespace 'System' (are you missing an assembly reference?)

    91966-image.png

    91918-image.png

    Is it possible to use MS Fakes in XUnit under .NET 5 or .NET Core 3.1?

    Sincerely
    Johannes


Your answer

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