locked
VS2010 C# unit tests compile, but don't load in test list editor on 64 bit machine running in 64 bit process RRS feed

  • Question

  • I am trying to write unit tests in vs2010 to test a native 64 bit C++ windows application that includes a .NET assembly registered in the GAC with a processor architecture of AMD64.

    If in the test class (code shown below), I declare a member variable of an type defined as an enum in my external assembly, The code compiles fine, but I get the following error when I open the test list editor and it tries to find the tests in the test class.

    Error loading C:\Users\matt3274\documents\visual studio 2010\Projects\Test64\Test64\bin\Debug\Test64.dll: Unable to load the test container 'C:\Users\matt3274\documents\visual studio 2010\Projects\Test64\Test64\bin\Debug\Test64.dll' or one of its dependencies. Error details: System.IO.FileNotFoundException: Could not load file or assembly 'ESRI.ArcGIS.Version, Version=10.1.0.0, Culture=neutral, PublicKeyToken=8fc3cc631e44ad86' or one of its dependencies. The system cannot find the file specified.

    Note, I don't get this problem if I declare members of interfaces, just enums.

    To stem off any preliminary questions:

    1. I've setup the test settings to be "Run tests in 64 bit process on 64 bit machine"
    2. It's truly a native 64 bit app that I'm testing
    3. My machine is windows server 2008 R2 64 bit.
    4. If I comment out the declaration of the enum member variable (since not used), the assembly can be found and loaded by the test list manager.
    5. If #3 is done, then I can then run the test successfully.

    Here's the code

    using System;
    
    using System.Text;
    
    using System.Collections.Generic;
    
    using System.Linq;
    
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    
    
    
    namespace Test64
    
    {
    
     [TestClass]
    
     public class UnitTest1
    
     {
    
     // Comment this next line out for the dll to be loaded into the test editor
    
     // If not commented out, get:
    
     // Error loading c:\users\matt3274\documents\visual studio 2010\Projects\Test64\Test64\bin\Debug\Test64.dll: 
    
     // Unable to load the test container 'c:\users\matt3274\documents\visual studio 2010\Projects\Test64\Test64\bin\Debug\Test64.dll' 
    
     // or one of its dependencies. Error details: System.IO.FileNotFoundException: 
    
     // Could not load file or assembly 'ESRI.ArcGIS.Version, Version=10.1.0.0, Culture=neutral, PublicKeyToken=8fc3cc631e44ad86'
    
     // or one of its dependencies. The system cannot find the file specified.
    
     private ESRI.ArcGIS.ProductCode productCode = ESRI.ArcGIS.ProductCode.Server;
    
    
    
     // This works since it's an interface, not an enum
    
     private ESRI.ArcGIS.RuntimeInfo ri;
    
    
    
     public UnitTest1()
    
     {
    
     }
    
     
    
     private TestContext testContextInstance;
    
    
    
     public TestContext TestContext
    
     {
    
      get { return testContextInstance; }
    
      set { testContextInstance = value; }
    
     }
    
    
    
     [TestMethod]
    
     public void TestMethod1()
    
     {
    
      bool gotRuntimeInfo = false;
    
      ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Server);
    
      foreach (ESRI.ArcGIS.RuntimeInfo ri in ESRI.ArcGIS.RuntimeManager.InstalledRuntimes)
    
      {
    
      Assert.AreEqual(@"E:\ArcGIS\", ri.Path, "Check path");
    
      gotRuntimeInfo = true;
    
      }
    
      Assert.IsTrue(gotRuntimeInfo, "check to make sure got at least one RuntimeInfo");
    
     }
    
     }
    
    }
    
    
    
    

    Also, if this helps, I see this in the window application event log:

    The description for Event ID 0 from source VSTTExecution cannot be found. Either the component that raises this event is not installed on your local computer or the installation is corrupted. You can install or repair the component on the local computer.
    
    
    
    If the event originated on another computer, the display information had to be saved with the event.
    
    
    
    The following information was included with the event: 
    
    
    
    (devenv.exe, PID 10136, Thread 1) Exception thrown when enumerating assembly: Microsoft.VisualStudio.TestTools.Exceptions.EqtDataException: Unable to load the test container 'C:\Users\matt3274\documents\visual studio 2010\Projects\Test64\Test64\bin\Debug\Test64.dll' or one of its dependencies. Error details: System.IO.FileNotFoundException: Could not load file or assembly 'ESRI.ArcGIS.Version, Version=10.1.0.0, Culture=neutral, PublicKeyToken=8fc3cc631e44ad86' or one of its dependencies. The system cannot find the file specified.
    
    
    
     at Microsoft.VisualStudio.TestTools.TestTypes.Unit.AssemblyEnumerator.EnumerateAssembly(IWarningHandler warningHandler, String location, ProjectData projectData, ObjectHandle assemblyResolverWrapper)
    
     at Microsoft.VisualStudio.TestTools.TestTypes.Unit.AssemblyEnumerator.EnumerateAssembly(IWarningHandler warningHandler, String location, ProjectData projectData, ObjectHandle assemblyResolverWrapper)
    
     at Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestAttributeEnumerator.Read(ITestTypeExtensionClientSidesProvider provider, IWarningHandler warningHandler, String assemblyFileName, ProjectData projectData, TestRunConfiguration testRunConfiguration)
    
    
    
    the message resource is present but the message is not found in the string/message table
    
    

    Any ideas what the problem may be due to?

     

    ********************************************************************

    Updated 9/13/2010 with more information below:

    Here is an even simpler case that I think is related that doesn't require any 3rd party assemblies.

    If I do the following:

    create a brand new test solutiopn/project
    change the platform from "Any CPU" to "x64.
    change the test settings > hosts to "Run tests in 64 bit process on 64 bit machine"

    And compile on my windows server 2008 R2 64 bit machine, I get the following build output:

    ------ Rebuild All started: Project: Simple64Test, Configuration: Release x64 ------

    Simple64Test -> c:\users\matt3274\documents\visual studio 2010\Projects\Simple64Test\bin\x64\Release\Simple64Test.dll

    ========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

    But even more importantly the following Tests output

    Error loading c:\users\matt3274\documents\visual studio 2010\Projects\Simple64Test\bin\x64\Release\Simple64Test.dll: Unable to load the test container 'c:\users\matt3274\documents\visual studio 2010\Projects\Simple64Test\bin\x64\Release\Simple64Test.dll' or one of its dependencies. If you build your test project assembly as a 64 bit assembly, it cannot be loaded. When you build your test project assembly, select "Any CPU" for the platform. To run your tests in 64 bit mode on a 64 bit processor, you must change your test settings in the Hosts tab to run your tests in a 32 bit process. Error details: Could not load file or assembly 'file:///c:\users\matt3274\documents\visual studio 2010\Projects\Simple64Test\bin\x64\Release\Simple64Test.dll' or one of its dependencies. An attempt was made to load a program with an incorrect format.

     

    Searching the forums I came across the following blog that has the text included below:

    http://blogs.msdn.com/b/lkruger/archive/2009/06/08/visual-studio-team-test-load-agent-goes-64-bit.aspx

    There is a Gotcha!
    As I stated earlier, we really only support test assemblies that target the “Any CPU” or “x86” platforms.  Under certain conditions, you may be able to run test assemblies that specifically target the “x64” platform.  However, for certain test types (unit tests in particular), MSTest.exe will need to load the test assembly into its own process.  Since MSTest.exe is a 32 bit process, the test assembly needs to be able to load into a 32 bit process (in other words it must target the x86 or “Any CPU” architecture) to load properly.  This means that if you specifically target the x64 platform and you are using one of these test types, regardless of the setting of the Host Process Platform flag, the test assembly will fail to load and the tests will be aborted. 

     

    To me, this sounds like problem is due to the fact that the process used to update the test list is a 32 bit process.  In this instance, since my project is 64 bit, it fails.  This would also explain my previous problem posted earlier where essentially it couldn't find the aMD64 assembly when trying to read the project to get the tests to populate the test list editor.


    I guess my question now is - Is this really the expected behavior that the VS2010 test list editor doesn't work properly on tests that require true 64-bit assemblies?  Is there any workaround? 

    Any help would be much appreciated,

    Matt Crowder

    • Edited by Matt Crowder Monday, September 13, 2010 10:22 PM Added additional information
    Monday, August 23, 2010 11:49 PM

Answers

  • Hello Matt,

    This is behavior is currently by design,  VS 2010 is a 32 bit application and if your tests have 64 bit assembly dependency then it will fail to display in the UI as the dependency load will fail.

    Thanks,

    Abhishek [MSFT]

     

    Friday, November 5, 2010 12:07 PM

All replies

  • Hello Matt,

    This is behavior is currently by design,  VS 2010 is a 32 bit application and if your tests have 64 bit assembly dependency then it will fail to display in the UI as the dependency load will fail.

    Thanks,

    Abhishek [MSFT]

     

    Friday, November 5, 2010 12:07 PM
  • I can't seem to be able to load and run my unit test in virtual Win 2008, VS2010 ultimate system.  Is it a virtualization issue, or am I missing something!

    I have one simple TestProject in a solution with a single test class that has only one [TestMethod], which simply calls Assert.IsTrue(true);

    My Host machine has Windows 7 pro 64-bit base and Oracle VirtualBox installed.
    The guest virtual machine running under VirtualBox, has the following configuration

    • Win Server 2008 R2 Enterprise, SP1 - 64 bit
    • VS 2010 Ultimate, version 10.0.40219.1 SP1

    I've toggled every permutation of TestProject settings (Any, x86, 64bit) with every permutation of Local.TestSettings->Hosts (64, 32, run in default host, not in default host).
    My Configuration manager is set to Debug build for "Any CPU" platform.

    Additionally, after every re-setting I 1) deleted the bin/debug folder, 2) restarted VS2010, 3) rebuilt the solution, 4) attempted to run the test.

    I can't seem to get around "Could not load file or assembly ... 0x80070057 (E_INVALIDARG)"

    Does anyone have any ideas?

    Tnx,
    Edvin

     

    • Proposed as answer by Edvin Eshagh Sunday, January 8, 2012 9:39 AM
    • Unproposed as answer by Edvin Eshagh Sunday, January 8, 2012 9:39 AM
    Saturday, December 3, 2011 9:43 AM
  • I was able reproduce the issue on Win7-32, Win7-64, and Win2008-R2-64 (as virtual machines via VirtualBox, running on Win7-64 pro host operating system).

    My issue was resolved by adding the following entry in my visual studio devenv.exe.config file.

    <runtime>
       <loadFromRemoteSources enabled="true"/>
       ...
    
    I found the following references useful: 

    Best,
    Edvin Eshagh

    • Proposed as answer by Edvin Eshagh Sunday, January 8, 2012 10:11 AM
    Sunday, January 8, 2012 10:10 AM