question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PrivateObject and PrivateType are not available for a project targeting netcorapp2.0

See original GitHub issue

Description

Currently the classes located at Microsoft.VisualStudio.QualityTools.UnitTestFramework.PrivateObject and Microsoft.VisualStudio.QualityTools.UnitTestFramework.PrivateType are only available in the /src/TestFramework/Extension.Desktop/ project, this made sense in the past because the other project types did not support the System.Reflection classes necessary to implement those two classes.

However, as of netcoreapp2.0 those projects projects have access to all the needed classes in System.Reflection. A new Extension.CoreApp project should be built, or the existing Extension.Desktop project should be moved to the new VS15 style of projects so that <targetframeworks>netcoreapp2.0;net45</targetframeworks> could be set.

Steps to reproduce

  • Create a new test project targeting netcoreapp2.0
  • Try to use the class PrivateObject

Expected behavior

PrivateObject is found and is useable

Actual behavior

PrivateObject is not available for projects referencing the assembly that was generated from Extensions.Core

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:40
  • Comments:22 (1 by maintainers)

github_iconTop GitHub Comments

36reactions
skalinetscommented, Dec 17, 2019

Personally I am glad that this hasn’t been added to .NET Core / Standard. Testing of private stuff is an anti-pattern and should be avoided. However, if you absolutely cannot live without it (are doing migration of legacy stuff into .NET Core / Standard etc.), you could implement is yourself: https://gist.github.com/skalinets/1c4e5dbb4e86bd72bf491675901de5ad

34reactions
nohwndcommented, Jan 30, 2020

We discussed this internally and decided that we don’t want to introduce this pattern back into the framework.

In the attached zip file there is a single .cs that can be dropped into your test project, or a shared class library and is netstandard 2.0 compatible. The source code is a copy of this implementation.

PrivateObjectPrivateType.zip

Read more comments on GitHub >

github_iconTop Results From Across the Web

The type or namespace name 'PrivateObject' could not be ...
PrivateObject and PrivateType are not available for projects targeting netcoreapp2.0. There is a GitHub issue here: GitHub Issue 366.
Read more >
Private Accessor for .NET Core Assemblies - Factory Blog
GitHub issue “PrivateObject and PrivateType are not available for a project targeting netcorapp2.0 #366” · GitHub Source of PrivateObject ...
Read more >
PrivateObjectExtensions 1.4.0
PrivateObjectExtensions provides extension methods of PrivateObject and PrivateType for unit test projects. This allows you to.
Read more >
PrivateObject Class (Microsoft.VisualStudio.TestTools. ...
Initializes a new instance of the PrivateObject class that wraps the specified type. Properties. RealType. Gets the type of underlying object. Target.
Read more >
Untitled
728 dyer street c# - Pass parameters to PrivateObject method - Stack ... and PrivateType are not available for a project targeting netcorapp2.0...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found