Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8235003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:39:34+00:00 2026-06-07T18:39:34+00:00

I got the following error when running the test code. How to workaround the

  • 0

I got the following error when running the test code. How to workaround the issue? I’m using Visual studio 2010 Premium’s built-in MStest.

Test method TestProgram.myProgramTest.GetTypeListTest threw exception: 
System.InvalidCastException: Unable to cast object of type 'System.Collections.Generic.List`1[MyProgram.MyClass]' to type 'System.Collections.Generic.List`1[MyProgram.MyClass_Accessor]'.

Method to be tested:

public class MyProjectClass {
    private List<MyClass> GetTypeList()
    { .... 
    }
}

class MyClass {....} // A POCO class

Test code (Most of the code is automatically generated by Visual studio):

[TestMethod()]
[DeploymentItem("myProgram.exe")]
public void GetTypeListTest()
{
    MyProjFile_Accessor target = new MyProjFile_Accessor ();
    var actual = target.GetTypeList();
    Assert.IsTrue(actual.Count > 2);
}

I really don’t know why this question has been down voted twice, all other code is either irrelevant to the issue or automatically generated by Visual studio
It’s pretty straight forward class definition. And the test fixture was created using VS 2010 wizard. The method just return MyClass can pass the test. The problem is the method with return type of List<MyClass>.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T18:39:37+00:00Added an answer on June 7, 2026 at 6:39 pm

    Class MyClass has no access modifier and C# uses internal access modifier by default.

    Internal means that class is accessible only inside its assembly.

    Unit tests usually implemented in separate assembly and cannot use MyClass.

    MS Tests generated MyClass_Accessor class that is essentially a wrapper that uses reflection to provide access to class itself as well as its methods.

    Change declaration to public class MyClass {....} and re-generate unit test (this is necessary to tell MS Test that _Accessor class is not necessary).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello Everybody! I got the following error, while trying to test a code for
I got the following error while running my perl script with the negative lookaround
On a server running a Qt application I got the following error, as soon
I tried installing TurboGears 1.0 on Windows 7 using tgsetup.py. and got following error
Running the following C# code through NUnit yields Test.ControllerTest.TestSanity: Expected: `<System.DivideByZeroException>` But was: null
I'm migrating toward node.js 0.6.12 and now got the following error messages when using
I got the following output after running make test, but how do i get
I got following error... System.NullReferenceException: Object reference not set to an instance of an
I got the following error: Error 2 Value restriction. The value 'gbmLikelihood' has been
I got the following error while trying to alter a column's data type and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.