The type or namespace name 'PrivateObject' could not be found












2















I am using Visual Studio 2017 and I was trying to create a unit test of a private method in C# (code below):



[TestClass]
public class CalculatorTests
{
[TestMethod]
public void TestCalculator_Hello()
{
var calc = new Calculator(1);

var privateObject = new PrivateObject(calc);

string expected = "hello!";

string result = privateObject.Invoke("HelloTest");
Assert.AreEqual(expected, result);
}


}


However, I got this error message:




Error CS0246 The type or namespace name 'PrivateObject' could not be found




I've looked up for articles and tutorials but I still don't know what I am doing wrong.










share|improve this question


















  • 1





    You may be missing a reference to its assembly Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll docs.microsoft.com/en-us/dotnet/api/…

    – Nkosi
    Nov 13 '18 at 3:14


















2















I am using Visual Studio 2017 and I was trying to create a unit test of a private method in C# (code below):



[TestClass]
public class CalculatorTests
{
[TestMethod]
public void TestCalculator_Hello()
{
var calc = new Calculator(1);

var privateObject = new PrivateObject(calc);

string expected = "hello!";

string result = privateObject.Invoke("HelloTest");
Assert.AreEqual(expected, result);
}


}


However, I got this error message:




Error CS0246 The type or namespace name 'PrivateObject' could not be found




I've looked up for articles and tutorials but I still don't know what I am doing wrong.










share|improve this question


















  • 1





    You may be missing a reference to its assembly Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll docs.microsoft.com/en-us/dotnet/api/…

    – Nkosi
    Nov 13 '18 at 3:14
















2












2








2


1






I am using Visual Studio 2017 and I was trying to create a unit test of a private method in C# (code below):



[TestClass]
public class CalculatorTests
{
[TestMethod]
public void TestCalculator_Hello()
{
var calc = new Calculator(1);

var privateObject = new PrivateObject(calc);

string expected = "hello!";

string result = privateObject.Invoke("HelloTest");
Assert.AreEqual(expected, result);
}


}


However, I got this error message:




Error CS0246 The type or namespace name 'PrivateObject' could not be found




I've looked up for articles and tutorials but I still don't know what I am doing wrong.










share|improve this question














I am using Visual Studio 2017 and I was trying to create a unit test of a private method in C# (code below):



[TestClass]
public class CalculatorTests
{
[TestMethod]
public void TestCalculator_Hello()
{
var calc = new Calculator(1);

var privateObject = new PrivateObject(calc);

string expected = "hello!";

string result = privateObject.Invoke("HelloTest");
Assert.AreEqual(expected, result);
}


}


However, I got this error message:




Error CS0246 The type or namespace name 'PrivateObject' could not be found




I've looked up for articles and tutorials but I still don't know what I am doing wrong.







c# unit-testing






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 13 '18 at 3:11









PauloPaulo

141




141








  • 1





    You may be missing a reference to its assembly Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll docs.microsoft.com/en-us/dotnet/api/…

    – Nkosi
    Nov 13 '18 at 3:14
















  • 1





    You may be missing a reference to its assembly Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll docs.microsoft.com/en-us/dotnet/api/…

    – Nkosi
    Nov 13 '18 at 3:14










1




1





You may be missing a reference to its assembly Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll docs.microsoft.com/en-us/dotnet/api/…

– Nkosi
Nov 13 '18 at 3:14







You may be missing a reference to its assembly Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll docs.microsoft.com/en-us/dotnet/api/…

– Nkosi
Nov 13 '18 at 3:14














2 Answers
2






active

oldest

votes


















0














While PrivateObject shares the same Microsoft.VisualStudio.TestTools.UnitTesting namespace as TestMethodAttribute and related attribues, it belong to a separate assembly



Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll


Check to make sure that the assembly is referenced by the test project.



You also need to cast the result because Invoke returns an object



string result = (string)privateObject.Invoke("HelloTest");





share|improve this answer































    0














    if you hover over PrivateObject( and right click.. is there an option for go to definition?



    that command will tell you what it thinks that class is..



    if you cannot go to definition via the context menu, then it means you're missing a reference and the compiler doesn't know what PrivateObject is..



    If that is the case, you can add a reference to it via your NuGet Package Manager or by right clicking the project and going to Add Reference.



    Also remember to add the Namespace to the top of the file with a using statement, once those are all in place it should know what that object is.
    You should not get any errors at that point, and your Go to Definition context menu should take you to an actual class definition.






    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53273228%2fthe-type-or-namespace-name-privateobject-could-not-be-found%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      While PrivateObject shares the same Microsoft.VisualStudio.TestTools.UnitTesting namespace as TestMethodAttribute and related attribues, it belong to a separate assembly



      Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll


      Check to make sure that the assembly is referenced by the test project.



      You also need to cast the result because Invoke returns an object



      string result = (string)privateObject.Invoke("HelloTest");





      share|improve this answer




























        0














        While PrivateObject shares the same Microsoft.VisualStudio.TestTools.UnitTesting namespace as TestMethodAttribute and related attribues, it belong to a separate assembly



        Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll


        Check to make sure that the assembly is referenced by the test project.



        You also need to cast the result because Invoke returns an object



        string result = (string)privateObject.Invoke("HelloTest");





        share|improve this answer


























          0












          0








          0







          While PrivateObject shares the same Microsoft.VisualStudio.TestTools.UnitTesting namespace as TestMethodAttribute and related attribues, it belong to a separate assembly



          Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll


          Check to make sure that the assembly is referenced by the test project.



          You also need to cast the result because Invoke returns an object



          string result = (string)privateObject.Invoke("HelloTest");





          share|improve this answer













          While PrivateObject shares the same Microsoft.VisualStudio.TestTools.UnitTesting namespace as TestMethodAttribute and related attribues, it belong to a separate assembly



          Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll


          Check to make sure that the assembly is referenced by the test project.



          You also need to cast the result because Invoke returns an object



          string result = (string)privateObject.Invoke("HelloTest");






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 13 '18 at 3:22









          NkosiNkosi

          111k16123190




          111k16123190

























              0














              if you hover over PrivateObject( and right click.. is there an option for go to definition?



              that command will tell you what it thinks that class is..



              if you cannot go to definition via the context menu, then it means you're missing a reference and the compiler doesn't know what PrivateObject is..



              If that is the case, you can add a reference to it via your NuGet Package Manager or by right clicking the project and going to Add Reference.



              Also remember to add the Namespace to the top of the file with a using statement, once those are all in place it should know what that object is.
              You should not get any errors at that point, and your Go to Definition context menu should take you to an actual class definition.






              share|improve this answer




























                0














                if you hover over PrivateObject( and right click.. is there an option for go to definition?



                that command will tell you what it thinks that class is..



                if you cannot go to definition via the context menu, then it means you're missing a reference and the compiler doesn't know what PrivateObject is..



                If that is the case, you can add a reference to it via your NuGet Package Manager or by right clicking the project and going to Add Reference.



                Also remember to add the Namespace to the top of the file with a using statement, once those are all in place it should know what that object is.
                You should not get any errors at that point, and your Go to Definition context menu should take you to an actual class definition.






                share|improve this answer


























                  0












                  0








                  0







                  if you hover over PrivateObject( and right click.. is there an option for go to definition?



                  that command will tell you what it thinks that class is..



                  if you cannot go to definition via the context menu, then it means you're missing a reference and the compiler doesn't know what PrivateObject is..



                  If that is the case, you can add a reference to it via your NuGet Package Manager or by right clicking the project and going to Add Reference.



                  Also remember to add the Namespace to the top of the file with a using statement, once those are all in place it should know what that object is.
                  You should not get any errors at that point, and your Go to Definition context menu should take you to an actual class definition.






                  share|improve this answer













                  if you hover over PrivateObject( and right click.. is there an option for go to definition?



                  that command will tell you what it thinks that class is..



                  if you cannot go to definition via the context menu, then it means you're missing a reference and the compiler doesn't know what PrivateObject is..



                  If that is the case, you can add a reference to it via your NuGet Package Manager or by right clicking the project and going to Add Reference.



                  Also remember to add the Namespace to the top of the file with a using statement, once those are all in place it should know what that object is.
                  You should not get any errors at that point, and your Go to Definition context menu should take you to an actual class definition.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 13 '18 at 3:26









                  JBoothUAJBoothUA

                  845424




                  845424






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53273228%2fthe-type-or-namespace-name-privateobject-could-not-be-found%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Florida Star v. B. J. F.

                      Danny Elfman

                      Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues