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

  • Home
  • SEARCH
  • 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 105689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:28:43+00:00 2026-05-11T01:28:43+00:00

I have created a new solution with a minimal amount of code that represents

  • 0

I have created a new solution with a minimal amount of code that represents the issue I am having. This is the simplest I could get it down to.

namespace EntServ.BusinessObjects {     /// <summary>     /// Summary description for EntServSession     /// </summary>     public class EntServSession     {         public EntServSession()         {          }          public static EntServSession Login(string username, string password)         {             EntServSession ret = null;              if (username == 'test'  && password == 'pass')                 ret = new EntServSession();              return ret;         }      } } 

I started with a new solution, and created one class in the App_Code folder with one static method similar to one of the methods I was having an issue with. I right-clicked on the classname, and click ‘Create Unit Tests…’. It offered to create a new Test project for me, I accepted the defaults and clicked okay. It generated the following file:

using EntServ.BusinessObjects; using Microsoft.VisualStudio.TestTools.UnitTesting; using Microsoft.VisualStudio.TestTools.UnitTesting.Web; using System.Data;  namespace EntServObjectTests {       /// <summary>     ///This is a test class for EntServSessionTest and is intended     ///to contain all EntServSessionTest Unit Tests     ///</summary>     [TestClass()]     public class EntServSessionTest     {           private TestContext testContextInstance;          /// <summary>         ///Gets or sets the test context which provides         ///information about and functionality for the current test run.         ///</summary>         public TestContext TestContext         {             get             {                 return testContextInstance;             }             set             {                 testContextInstance = value;             }         }          #region Additional test attributes         //          //You can use the following additional attributes as you write your tests:         //         //Use ClassInitialize to run code before running the first test in the class         //[ClassInitialize()]         //public static void MyClassInitialize(TestContext testContext)         //{         //}         //         //Use ClassCleanup to run code after all tests in a class have run         //[ClassCleanup()]         //public static void MyClassCleanup()         //{         //}         //         //Use TestInitialize to run code before running each test         //[TestInitialize()]         //public void MyTestInitialize()         //{         //}         //         //Use TestCleanup to run code after each test has run         //[TestCleanup()]         //public void MyTestCleanup()         //{         //}         //         #endregion           /// <summary>         ///A test for Login         ///</summary>         // TODO: Ensure that the UrlToTest attribute specifies a URL to an ASP.NET page (for example,         // http://.../Default.aspx). This is necessary for the unit test to be executed on the web server,         // whether you are testing a page, web service, or a WCF service.         [TestMethod()]         [HostType('ASP.NET')]         [AspNetDevelopmentServerHost('%PathToWebRoot%\\EntServ2-ASP.NET\\trunk\\WWW', '/WWW')]         [UrlToTest('http://localhost/WWW')]         public void LoginTest()         {             string username = string.Empty; // TODO: Initialize to an appropriate value             string password = string.Empty; // TODO: Initialize to an appropriate value             EntServSession expected = null;             EntServSession actual = EntServSession_Accessor.Login(username, password);             Assert.AreEqual(expected, actual);             Assert.Inconclusive('Verify the correctness of this test method.');         }      } } 

I tried running the test and it tries to compile and I get the build error:

Error   1    The type or namespace name 'EntServSession' could not be found  (are you missing a using directive or an assembly reference?)   C:\Projects\EntServ-ASP.NET\trunk\Tests\EntServObjectTests\EntServSessionTest.cs 82 13 EntServObjectTests 

I publish the web site and put a reference to the App_code.dll in the test project and I no longer get a build error. I instead get the following exception error. I put break points on every line of the class, and the debugger does not stop on any line .

Error Message Test method EntServObjectTests.EntServSessionTest.LoginTest threw exception:  System.InvalidCastException: Unable to cast object of type 'EntServ2.BusinessObjects.EntServSession' to type 'EntServ2.BusinessObjects.EntServSession'..  Stack Trace EntServ2.BusinessObjects.EntServSession_Accessor.Login(String username, String password) EntServObjectTests.EntServSessionTest.LoginTest() in C:\Projects\EntServ2-ASP.NET\trunk\Tests\EntServObjectTests\EntServSessionTest.cs: line 83 
  • 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. 2026-05-11T01:28:44+00:00Added an answer on May 11, 2026 at 1:28 am

    Re-edit:

    I can’t really solve your exact problem the InvalidCastException as this is probably one of those red-herring / rabbit holes problems that take you days to figure out and much hair pulling out. I am sure it will have something to do with assembly versions being different when you are publishing them??

    I don’t usually do this and you can vote me down for bad advice, but can I recommend that you convert your asp.net website to a web application? (either this or move the offending code to a class library). I know that this is not the answer you are looking for, but it’s tough love what can I say. You will find in the long run it will be far easier and I won’t go into all the benefits as I’m sure you will have heard of them or can google them.

    I am sure that this will be a much quicker solution to your problem… and after all who really wants to publish their site each time they run their unit-tests?

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

Sidebar

Ask A Question

Stats

  • Questions 96k
  • Answers 96k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can use the SOSEX extensions to examine each generations… May 11, 2026 at 7:10 pm
  • Editorial Team
    Editorial Team added an answer The int version is fine, but NSInteger is preferred. NSInteger… May 11, 2026 at 7:10 pm
  • Editorial Team
    Editorial Team added an answer I figured out the answer to the second question. I… May 11, 2026 at 7:10 pm

Related Questions

I have a situation where I am using wpf data binding and validation using
This question is a little involved. I wrote an algorithm for breaking up a
I have created a class for a dashboard item which will hold information such
I tried searching here for a similar solution but didn't see one so I

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.