Generation of Private Accessors (Publicize) and Code Generation for Visual Studio 2010

We are letting you know of a few things that are happening in Visual Studio 2010 in regards to generation of Private Accesors and Code Generation. 

What is Publicize in Visual Studio testing?

Publicize is the ability to take internal application programming interfaces (API) and create public counterpart API that you can call in your tests, which would in turn, call into the internal APIs of your product.  This comes in the form of a stand alone executable, or can be seen when using code generation to create test method stubs of internal or private APIs.

What is Code Generation in Visual Studio testing?

Code Generation allows users to create test stubs and generates a little code snippet inside that stub.  This feature can be used in conjunction with Publicize to create test method stubs from internal APIs.

What is happening in Visual Studio 2010?

We have stopped working on these features for Visual Studio 2010 and may remove them from the product in following releases.  This is due to the following reasons:

  1. Lack of resources and time: The focus for this release has been to improve the experience for manual testers, so the priority for the code generation and publicize features has been lowered.  There have also been other issues with the publicize functionality that we utilize that have not been addressed.

  2. New features by Language teams:  As the language teams have made modifications to their project types and languages, we have been unable to respond to the changes they have made and have not been able to work with the new features they have introduced.

What is available for me then?

For those who wish to continue testing internal APIs, you have three options:

  1. Use the Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject class to assist in accessing internal and private APIs in your code.  This is found in the Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll assembly.

  2. Create a reflection framework that would be able to reflect off your code to access internal or private APIs.

  3. If the code you are trying to access is internal, you may be able to access your APIs using the InternalsVisibleToAttribute so your test code can have access to the internal APIs.

However, there is not any good replacement for Code Generation for the new features added by the lanugage teams.  You may create the TestMethod stubs and then remove the internal code.  You only need to keep the stub itself.

Will it be added back in or fixed in future releases?

At the moment, there are no plans to do this.  It may change based on priority and focus. Feedback welcome about this content or other items you would like us to consider for future releases.


Bruce Taimana
Program Manager

Comments (10)

  1. says:

    Is this still the case now that the RC is out?  I see that the option is still availible when right clicking on a private member, however does not seem to be working.  If this functionality is not going to be availible than why keep the menu item for Create Private Accessor in VS2010 for the RC.



  2. Correct.  We have not removed it from VS2010.  However, we have not made steps to fix core issues in these features.  In future (post Visual Studio 2010) these may be removed.

  3. Michael says:

    This is extremely annoying.

    Earlier when working with NUnit I wrote my own helper to be able to test private methods.

    But the fact that this was already present combined with the "Create Unit Tests …" option made it an easy choice to start using MSTest.

    Now when working on a project I was replacing the data access logic with Entity Framework and suddenly I can't compile any more. I get: "Collection was modified; enumeration operation may not execute." when compiling the test project.

    I saved my tests and tried to recreate the test project but now I alwas get an error when calling my private methods:

    "Creation of the private accessor for 'Microsoft.VisualStudio.TestTools.TypesAndSymbols.Assembly' failed"

    Please fix this or supply a work-around so that we can once again use the  "Create Unit Tests …"  that saves us time in our daily work.

    Thanks / Michael

  4. Martynas says:

    just info- in final vs 2010 release there is both included – the bug and the feature to generate private accessors. I guess in microsoft only Scott Gufrie knows what is and why unit testing (sometimes it looks that testing at all) is needed. quite disappointing… also what i noticed, that release of vs 2010 crashes at least time per day, but that's possible to live with. sometimes disabling wpf font caching service helps…

  5. W Thomas says:

    This is apparently the root cause of a bug in VS2010 C# Unit Test generation.  I have a project with public interfaces (no private accessors) that uses covariant (<out T>) generic types. When VS2010 creates unit tests for this assembly, it apparently generates private accessors as part of its unit test wizard.  This causes the following type of error with every compile of either the original project or the unit test project:

    "Could not load type 'MultiTree.ITreeNode_Impl`1' from assembly 'MultiTree_Accessor, Version=, Culture=neutral, PublicKeyToken=null' because it declares a covariant or contravariant type parameter and is not an interface or delegate. MultiTree Unit Tests"

    Because every subsequent build gets this error, not only are these unit tests are totally useless, no other unit tests nor builds of the project under test can be successfully built.  See the post at…/0bad3473-787c-4a8d-9b11-6c345bde780c for further discussion.

    Again, this is nothing that "I" created, but code generated by Visual Studio 2010 when creating unit tests using the Unit Test wizard, from a project that otherwise builds and runs without error or problem.  Either Visual Studio should be fixed to stop generating code that uses (broken) private accessors, or the issues with private accessors should be fixed.  (Since auto-generating unit tests of code that uses co- and contravariance seems to require them, I vote for the latter.)

  6. Vladimir says:

    Why not generate private accessors on per type basis? Surely trying to wrap any type in an assembly can be extremely error prone, but the feature at all is (oops, was) very useful.

    Very disappointing!

  7. John says:

    Looking forward to good test coverage of my MVC3 controllers but removing tooling support  in VS2010 for testing private methods is now an impediment.  

    Why is this not treated as an important issue?  Surely testing is a major supposed benefit of ASP.NET MVC3?

  8. KG says:

    What about the BuildShadowTask problem?  I have been redirected to this page from…/buildshadowtask-nullreferenceexception, however, a clear workaround has not bee posted?


  9. saywhat says:

    improve the experience for manual testers? why not improve the experience for all people who want to test their code and just fix it.

Skip to main content