bitblack / moq

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

Exceptions and performance issue while mocking a large interface #370

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Hello,

I'm using Moq v3.5.716.1 and I want to mock a large interface (~630 methods).

While processing the following lines some exceptions occure:

Dim mJob As New Mock(Of IJobInterface)
target._job = mJob.Object

########
ContextSwitchDeadlock was detected
Message: The CLR has been unable to transition from COM context 0x5f09e50 to 
COM context 0x5f09f08 for 60 seconds. The thread that owns the destination 
context/apartment is most likely either doing a non pumping wait or processing 
a very long running operation without pumping Windows messages. This situation 
generally has a negative performance impact and may even lead to the 
application becoming non responsive or memory usage accumulating continually 
over time. To avoid this problem, all single threaded apartment (STA) threads 
should use pumping wait primitives (such as CoWaitForMultipleHandles) and 
routinely pump messages during long running operations.

########
System.AccessViolationException occurred
  Message="Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
  Source="DynamicProxyGenAssembly2"
  StackTrace:
       at Castle.Proxies.IJobInterfaceProxyfd1dbe502eb3485ea1b3d4e2411f83e4..cctor()
  InnerException: 

########
System.Reflection.TargetInvocationException occurred
  Message="Exception has been thrown by the target of an invocation."
  Source="mscorlib"
  StackTrace:
       at System.RuntimeFieldHandle.SetValue(Object obj, Object value, RuntimeTypeHandle fieldType, FieldAttributes fieldAttr, RuntimeTypeHandle declaringType, Boolean& domainInitialized)
       at System.Reflection.RtFieldInfo.InternalSetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, CultureInfo culture, Boolean doVisibilityCheck, Boolean doCheckConsistency)
  InnerException: System.TypeInitializationException
       Message="The type initializer for 'Castle.Proxies.IJobInterfaceProxyfd1dbe502eb3485ea1b3d4e2411f83e4' threw an exception."
       TypeName="Castle.Proxies.IJobInterfaceProxyfd1dbe502eb3485ea1b3d4e2411f83e4"
       InnerException: System.AccessViolationException
            Message="Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
            Source="DynamicProxyGenAssembly2"
            StackTrace:
                 at Castle.Proxies.IJobInterfaceProxyfd1dbe502eb3485ea1b3d4e2411f83e4..cctor()
            InnerException: 

########
Microsoft.VisualStudio.TestTools.TestTypes.Unit.TestFailedException occurred
  Message="Exception of type 'Microsoft.VisualStudio.TestTools.TestTypes.Unit.TestFailedException' was thrown."
  Source="Microsoft.VisualStudio.QualityTools.Tips.UnitTest.Adapter"
  StackTrace:
       at Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestExecuter.HandleMethodException(Exception ex)
  InnerException: 

########
System.Threading.ThreadInterruptedException occurred
  Message="Thread was interrupted from a waiting state."
  Source="mscorlib"
  StackTrace:
       at System.Threading.Thread.SleepInternal(Int32 millisecondsTimeout)
       at System.Threading.Thread.Sleep(Int32 millisecondsTimeout)
  InnerException: 

########

It also takes several minutes and several GBytes of memory.
Am I doing something wrong or is there another way to mock that object. I need 
this mock for every unit test so I need a faster way to do this.

IJobInterface is an Interface of a C++ COM class if it's important for you. 
I've attached the Interop.dll. Add it as a reference and import the e3 
namespace.

There are a lot more interfaces inside just ignore them.

Cheers

Original issue reported on code.google.com by helix...@gmail.com on 28 Oct 2013 at 7:59

Attachments:

GoogleCodeExporter commented 8 years ago
Hello,

any ideas or do you need more information?

Best regards

Original comment by helix...@gmail.com on 4 Nov 2013 at 10:56