My favorites | Sign in
moq
Project Home Downloads Wiki Issues Source
New issue   Search
for
  Advanced search   Search tips   Subscriptions
Issue 344: Exception thrown when using Moq with Microsoft Moles
2 people starred this issue and may be notified of changes. Back to list
Status:  New
Owner:  ----


Sign in to add a comment
 
Reported by mgress...@gmail.com, Jun 6, 2012
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.
Jul 12, 2012
#1 Digi...@gmail.com
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: 

Sign in to add a comment

Powered by Google Project Hosting