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 8233525
In Process

The Archive Base Latest Questions

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

The following is the test code. namespace ConsoleApplication2 { class MyClass {} class Program

  • 0

The following is the test code.

namespace ConsoleApplication2
{
    class MyClass {}
    class Program
    {
        static void Main(string[] args) { }

        List<MyClass> Test() { return new List<MyClass>(); }
    }
}

Then using Visual studio create a union test for method Test().

    [TestMethod()]
    [DeploymentItem("ConsoleApplication2.exe")]
    public void TestTest()
    {
        Program_Accessor target = new Program_Accessor(); // TODO: Initialize to an appropriate value
        List<MyClass_Accessor> actual;
        actual = target.Test();
        Assert.IsTrue(actual != null);
    }

It will get the following exception when running the test. How to workaround the issue?

Test method TestProject1.ProgramTest.TestTest threw exception:  
System.InvalidCastException: Unable to cast object of type 'System.Collections.Generic.List`1[ConsoleApplication2.MyClass]' to type 'System.Collections.Generic.List`1[ConsoleApplication2.MyClass_Accessor]'.

I tried the following method and it doesn’t work too.

IEnumerable<MyClass> Test1() { return new 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:09:33+00:00Added an answer on June 7, 2026 at 6:09 pm

    Your program and your method are not public so MSTest and any other code cannot call it. MS Test built wrapper Program_Accessor to use your code through reflection.

    Change your code to use public access modifier and regenerate the test. It is the easiest way to learn unit-testing.

    public class Program
    {
       public class MyClass{}
    
       static void Main(string[] args) { }
    
       public List<MyClass> Test() { return new List<MyClass>(); }
    }
    

    You may use InternalsVisibleToAttribute if you do not want to make MyClass public.

    Friend Assemblies in MSDN

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

Sidebar

Related Questions

I have the following code: class Test { public static void main(String[] args) {
Consider the following code: namespace DisposeTest { using System; class Program { static void
How would you test the following code? public IList<T> Find(DetachedCriteria criteria) { return criteria.GetExecutableCriteria(session).List<T>();
I have the following code require 'test_helper' class ApplicationControllerTest < ActionController::TestCase test should display
I can't figure out why the following code fails: # test.ps1 `$args: ($args) `$args
I have the following test code (based on standard monodroid HelloWorld) namespace TestGREF {
My test code in C#: namespace DSnA { public abstract class Test : IComparable
In the following code: using namespace std; //ostream& operator<< (ostream& out,const string & str)
I'm getting uninitialized constant Date (NameError) with the following code: class Test attr_accessor :reqs
I wanted to test the following code (which works fine for a non-null list)

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.