bitblack / moq

Automatically exported from code.google.com/p/moq
Other
0 stars 0 forks source link

Exception thrown when using Moq with Microsoft Moles #344

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.Create a testme thod and decorate with [HostType("Moles")]
2.Create a mocked variable in the test method
3.Run the test method

What is the expected output? What do you see instead?
Test should pass.  Instead, a TypeInitializationException is thrown upon 
executing the line of code that creates a mocked variable.  The exception 
message is "The type initializer for 'Moq.Extensions' threw an exception."

What version of the product are you using? On what operating system?
.NET 4.0 version of Build 4.0.10827.  Windows 7 x64.

Please provide any additional information below.
We were previously on version 3.1 which seemed to work fine with Microsoft 
Moles.  When we upgraded to 4.0, we started seeing the noted exception.  We 
have reverted to version 3.1 for now because we have a fairly large investment 
in Moles.

Original issue reported on code.google.com by mgress...@gmail.com on 6 Jun 2012 at 8:04

GoogleCodeExporter commented 8 years ago
I am also seeing this issue using .NET 4.0, MOQ 4.0.10827, Win 7 x64, Moles 
0.94.51023.0.  The exception detail is:

System.TypeInitializationException was unhandled by user code
  Message=The type initializer for 'MyCompany.UnitTests.Framework.UnitTestBase' threw an exception.
  Source=MyCompany.UnitTests.Framework
  TypeName=MyCompany.UnitTests.Framework.UnitTestBase
  StackTrace:
       at MyCompany.UnitTests.Framework.UnitTestBase.get_Container()
       at MyCompany.UnitTests.Client.Features.DocumentsViewModel.DocumentOverViewViewModelTestWithMoq.RegisterDependencies() in D:\Project\SuperDepartment\DocuMagic\Development\Mudders\MyCompany\UnitTests\Client\Features\DocumentModuleTests\DocumentOverViewViewModelTestWithMoq.cs:line 265
       at MyCompany.UnitTests.Client.Features.DocumentsViewModel.DocumentOverViewViewModelTestWithMoq.ClassInitialize(TestContext context) in D:\Project\SuperDepartment\DocuMagic\Development\Mudders\MyCompany\UnitTests\Client\Features\DocumentModuleTests\DocumentOverViewViewModelTestWithMoq.cs:line 42
  InnerException: System.TypeInitializationException
       Message=The type initializer for 'Moq.Extensions' threw an exception.
       Source=Moq
       TypeName=Moq.Extensions
       StackTrace:
            at Moq.Extensions.ThrowIfNotMockeable(Type typeToMock)
            at Moq.Mock`1.CheckParameters()
            at Moq.Mock`1..ctor(MockBehavior behavior, Object[] args)
            at Moq.Mock`1..ctor(MockBehavior behavior)
            at Moq.Mock`1..ctor()
            at MyCompany.UnitTests.Framework.FakeEntities.get_DocuMagicUserInfo() in D:\Project\SuperDepartment\DocuMagic\Development\Mudders\MyCompany\UnitTests\Framework\FakeEntities.cs:line 105
            at MyCompany.UnitTests.Framework.UnitTestBase.RegisterDependencies() in D:\Project\SuperDepartment\DocuMagic\Development\Mudders\MyCompany\UnitTests\Framework\UnitTestBase.cs:line 44
            at MyCompany.UnitTests.Framework.UnitTestBase.Initialize() in D:\Project\SuperDepartment\DocuMagic\Development\Mudders\MyCompany\UnitTests\Framework\UnitTestBase.cs:line 37
            at MyCompany.UnitTests.Framework.UnitTestBase..cctor() in D:\Project\SuperDepartment\DocuMagic\Development\Mudders\MyCompany\UnitTests\Framework\UnitTestBase.cs:line 17
       InnerException: System.Security.VerificationException
            Message=Operation could destabilize the runtime.
            Source=Moq
            StackTrace:
                 at Moq.Extensions..cctor()
            InnerException: 

Original comment by Digi...@gmail.com on 12 Jul 2012 at 7:08