question

PhamMinhTu-5578 avatar image
0 Votes"
PhamMinhTu-5578 asked TianyuSun-MSFT commented

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

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

vs-testing
image.png (15.9 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

TianyuSun-MSFT avatar image
0 Votes"
TianyuSun-MSFT answered

Hi @PhamMinhTu-5578 ,

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

PhamMinhTu-5578 avatar image
0 Votes"
PhamMinhTu-5578 answered TianyuSun-MSFT edited

Hi @TianyuSun-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.



image.png (7.8 KiB)
image.png (14.5 KiB)
image.png (16.7 KiB)
image.png (7.8 KiB)
image.png (14.5 KiB)
image.png (10.7 KiB)
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @PhamMinhTu-5578 , thank you for your feedback. Although I don’t know the detailed error message that got from the codes you shared(System.Fakes…), and I am not sure if you mean you clicked the Add Fakes Assembly in the second part, I think it’s the correct way. You can refer to this document: Choose between stub and shim types and this document: Get started with shims.

0 Votes 0 ·

The first document(part) points this: “But external assemblies such as System.dll typically are not provided with separate interface definitions, so you must use shims instead”, and the second document(part) points to add fakes assembly. So, if you use shim and maybe some external assemblies, it is needed to add fakes assembly. Also, generally, this will not cause error like “The type or namespace name Fakes does not exist…”

0 Votes 0 ·
Johannes-0709 avatar image
0 Votes"
Johannes-0709 answered TianyuSun-MSFT commented

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



[2]: /answers/storage/attachments/91944-image.png


image.png (29.9 KiB)
image.png (13.7 KiB)
image.png (25.8 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello Johannes, actually, you need to Add Fakes Assembly for System.Runtime, instead of for System. Have a nice day :)

0 Votes 0 ·