locked
Issue Debugging tests with HostType = Moles

    Question

  • Hi

     

    I’m using visual studio 2008 and moles version 0.93. Everything works well except when I try to debug any test that uses a Moled type. The test skips all my breakpoints. And I get the following message in the output window:

    Unable to attach. Check for one of the following.

    1. The application you are trying to debug uses a version of the Microsoft .NET Framework that is not supported by the debugger.

    2. The debugger has made an incorrect assumption about the Microsoft .NET Framework version your application is going to use.

    3. The Microsoft .NET Framework version specified by you for debugging is incorrect

    Please see the Visual Studio .NET debugger documentation for correctly specifying the Microsoft .NET Framework version your application is going to use for debugging.

    If I try debbuger.Break () I get a message: "No symbols are loaded for any call stack frame. The source code cannot be displayed."

    I’m in a crunch right now chasing an issue with one our main components and it has been a pain (like I need novocaine) trying to figure anything out without being able to step through the code. Can anyone help please?

    Thanks,

    Bzz…

    • Edited by Buzzerr Tuesday, August 24, 2010 12:31 PM formatting again...
    Tuesday, August 24, 2010 12:30 PM

Answers

  • Ok, that definitely a problem. It should be v2.0.50727 for VS2008. I think this might be a big regression in 0.93.

    - Go to program files\Microsoft visual studio 9.0\common7\ide\privateassemblies
    - delete Microsoft.Moles.VsHost.exe.config and Microsoft.Moles.VsHost.x86.exe.config

    then try again to see if we load in the correct CLR


    Jonathan "Peli" de Halleux - Try Pex online at www.pexforfun.com!
    • Marked as answer by Buzzerr Tuesday, August 24, 2010 11:12 PM
    Tuesday, August 24, 2010 7:11 PM

All replies

  • That is strange. Could you print to the console which .NET runtime version executes under Moles? 

         Console.WriteLine(typeof(Object).Assembly.Location));

    Since you're using VS2008, I expect to see mscorlib.dll from the v2.0.50727 folder. However, the message seems to say otherwise.


    Jonathan "Peli" de Halleux - Try Pex online at www.pexforfun.com!
    • Marked as answer by Buzzerr Tuesday, August 24, 2010 11:11 PM
    • Unmarked as answer by Buzzerr Tuesday, August 24, 2010 11:12 PM
    Tuesday, August 24, 2010 1:39 PM
  • Hi Peli -

    Thanks for getting back to me so quickly.  Sorry it took so long to get back to you.  I was in a meeting getting yelled at by the "architect" that wrote the bug :)

    C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll

    Thanks in advance,

    Buzz

    Tuesday, August 24, 2010 3:11 PM
  • Ok, that definitely a problem. It should be v2.0.50727 for VS2008. I think this might be a big regression in 0.93.

    - Go to program files\Microsoft visual studio 9.0\common7\ide\privateassemblies
    - delete Microsoft.Moles.VsHost.exe.config and Microsoft.Moles.VsHost.x86.exe.config

    then try again to see if we load in the correct CLR


    Jonathan "Peli" de Halleux - Try Pex online at www.pexforfun.com!
    • Marked as answer by Buzzerr Tuesday, August 24, 2010 11:12 PM
    Tuesday, August 24, 2010 7:11 PM
  • Peli,

     

    thanks I was having the same issue as Buzzerr and your post fixed it for me.

     

     

    Thanks again,

    Dan


    huh
    Tuesday, August 24, 2010 10:25 PM
  • Awesome!  That did the trick!

     BTW - Being able to stub and mole non virtual and static stuff (for free!!) is awesome

    Thanks peli!

    Tuesday, August 24, 2010 11:12 PM
  • Hi Peli,

                                 I am using VS 2008 9.02.210228 3.5 SP1 (.NET). For me i can't debug my method where hostype = "moles". Here is the code below.

     

     [TestMethod]
            [HostType("Moles")]
            public void CheckValidFileWithMoles()
            {
                //arrange
                var fileName = "test.txt";
                var content = "test hello siva!!!";
                MFileSystem.ReadAllTextString = delegate(string f)
                {
                    Assert.IsTrue(f == fileName);
                    return content;
                };
                //act
                var test = new TestReader();
                test.LoadFile(fileName);
                //assert
                Assert.AreEqual(content, test.Content);
            }

     

    I can hit my break point-- Did Test-->Debug-->Tests in Current Context. However If i remove HostType ="Moles" it is breaking at var fileName="test.txt" but exiting threading line 3----- MFileSystem.ReadAllTextString = delegate(string f)

    Wednesday, September 01, 2010 9:02 PM
  • > exiting threading line 3----- MFileSystem.ReadAllTextString = delegate(string f)

    That is expect. Moles makes sure that the code instrumentation is in place when executing. If you remove [HostType("Moles")] from the test, the code does not get instrumented and Moles will throw an exception at this line.

         MFileSystem.ReadAllTextString = delegate(string f)

    > I can hit my break point-- Did Test-->Debug-->Tests in Current Context.

    I'm a bit confused. Can you hit your breaking point where you have the [HostType("Moles")] attribute? Where is the breakpoint?


    Jonathan "Peli" de Halleux - Try Pex online at www.pexforfun.com!
    Wednesday, September 01, 2010 9:57 PM
  • This happened to me too.

    I was able to fix it by following Peli's response.

    Note that I also had to restart Visual Studio for it to work.

    Thanks Peli for the work around!

    Wednesday, September 08, 2010 7:15 PM
  • Ok, that definitely a problem. It should be v2.0.50727 for VS2008. I think this might be a big regression in 0.93.

    - Go to program files\Microsoft visual studio 9.0\common7\ide\privateassemblies
    - delete Microsoft.Moles.VsHost.exe.config and Microsoft.Moles.VsHost.x86.exe.config

    then try again to see if we load in the correct CLR


    Jonathan "Peli" de Halleux - Try Pex online at www.pexforfun.com!


    Hi Peli

    I've got the same problem with VS 2010 Premium.

    I've deleted both files (program files\Microsoft visual studio 10.0\common7\ide\privateassemblies) and tried restarting VS and I cannot debug yet.

    This is the version of my .net framework: C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll

    Thanks

    Friday, December 03, 2010 3:57 PM
  • Hi,

    I'm running into the same issue in VS 2008 Professional with Moles/Pex build 0.94.51023.0.  I don't seem to be hitting any of the break points in my code when I run my test case.

    I did look into applying the workaround, but I couldn't find the aforementioned config files under C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies.

    Please find below the test method (based on the tutorial):

            [TestMethod]
            [HostType("Moles")]
            public void CheckValidFileWithMoles()
            {
                // arrange
                var fileName = "test.txt";
                var content = "test";
                MStaticFileSystem.ReadAllTextString = delegate(string f)
                {
                    Assert.IsTrue(f == fileName);
                    return content;
                };

                // act
                var test = new StaticTestReader();
                test.LoadFile(fileName);

                // assert
                Assert.AreEqual(content, test.Content);
                Console.WriteLine(typeof (Object).Assembly.Location);

    Thanks.

    Friday, December 03, 2010 7:46 PM