chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes
When I test a method that uses Environment.GetFolderPath(...) I recieve a NullReferenceException with the following message:

TestCase 'SomeNamespace.UnitTests.SomeClassTest.SomeMethodTest' failed: System.NullReferenceException : Type must be declared abstract if any of its methods are abstract.
at System.Enum.GetTypeCode()
at System.Convert.GetTypeCode(Object value)
at System.Enum.ToUInt64(Object value)
at System.Enum.IsDefined(Type enumType, Object value)
at System.Environment.GetFolderPath(SpecialFolder folder)
at SomeNamespace.SomeClass.SomeMethod()
c:...SomeClassTest.cs(28,0): at SomeNamespace.UnitTests.SomeClassTest.SomeMethodTest()

The following code will reproduce the error:

Class
using System;

namespace SomeNamespace {
   public class SomeClass {
      public SomeClass() {

      }

      // This method will fail during a test since it 
      // calls Environment.GetFolderPath(...).
      public void SomeMethod() {
         Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
      }
   }
}


TestClass
using NUnit.Framework;
using TypeMock;

namespace SomeNamespace.UnitTests {
   [TestFixture()]
   public class SomeClassTest {
      private SomeClass someClass;

      public SomeClassTest() {
      }

      [SetUp()]
      public void Initialize() {
         MockManager.Init();

         someClass = new SomeClass();
      }

      [TearDown()]
      public void Cleanup() {
         MockManager.Verify();
      }

      [Test()]
      public void SomeMethodTest() {
         // This will fail because Environment.GetFolderPath(...)
         // is called in SomeMethod.
         someClass.SomeMethod();
      }
   }
}


I am using the following software:
- Windows 2003 Server
- Visual Studio .Net 2003
- TestDriven .Net 1.0.915
- NUnit 2.2
- TypeMock 2.2.2

Thanks,
Andy Blubaugh

PS
TypeMock is an absolutely phenomenal product! Keep up the good work!
asked by temp@lydianart.com (1.2k points)

3 Answers

0 votes
Hi Andy,
I have tested this on my computer and it works as a charm, the problem is probrably somewhere else.
What is the .NET version that you are running?
Do you have Visual Studio 2005 installed?

When I test a method that uses Environment.GetFolderPath(...) I recieve a NullReferenceException

I am using the following software:
- Windows 2003 Server
- Visual Studio .Net 2003
- TestDriven .Net 1.0.915
- NUnit 2.2
- TypeMock 2.2.2


TypeMock is an absolutely phenomenal product! Keep up the good work!

Thanks :-)
answered by richard (3.9k points)
0 votes
I am running .Net 1.1 SP1 and I do not have Visual Studio .Net 2005 installed. I am developing on a virtual PC, so perhaps there is a problem with my virtual PC. I will install the same software on my home PC and see if I reproduce the same problem.

Thanks,
Andy Blubaugh
answered by temp@lydianart.com (1.2k points)
0 votes
Hi,
This issue was taken offline, a fix has been made and will be released shortly.
answered by scott (32k points)
...