Smocks icon indicating copy to clipboard operation
Smocks copied to clipboard

Unexpected opcode: Initobj

Open VinS101 opened this issue 7 years ago • 0 comments

I am getting this error when trying to setup a callback for a static method that has two int? arguments with default values of null.

My static method looks like this:

public List<EventTriggerAction> LookupActions(int? fieldValueChangedID = null, int? eventTriggerActionID = null)
{
	using (var conn = new SqlConnection(ConnectionString.Sql))
	{
		using (var cmd = new SqlCommand("EventTriggerActionGroup_LookupActions", conn))
		{
			// DB call
		}
	}
}

My test:

Smock.Run(context =>
{
    EventTriggerActionGroup group = EventTriggerActionGroupTests.Mock();
    context.Setup(() => group.LookupActions(null, null)).Returns(mockLookUpActions);
    
    scheduleSet.ExecuteAllEventTriggerActionGroups(); // Method that depends on LookupActions()
    Assert.IsNull(scheduleSet);
});

Stacktrace:

System.NotImplementedException: Unexpected opcode: Initobj
    at Smocks.IL.Visitors.NumberPoppedVisitor.Visit(Instruction instruction)
   at Smocks.IL.Visitors.InstructionVisitorBase`1.VisitType(Instruction instruction, TypeReference typeReference)
   at Smocks.IL.Visitors.InstructionVisitorBase`1.VisitInlineType(Instruction instruction, TypeReference operand)
   at Smocks.IL.InstructionExtensions.Accept[T](Instruction instruction, IInstructionVisitor`1 visitor)
   at Smocks.IL.ExpressionDecompiler`1.GetNumberPoppedByInstruction(Instruction current)
   at Smocks.IL.ExpressionDecompiler`1.IncludeInstructionsUntilStackEmpty(MethodBody body, Instruction instruction, BitArray includedInstructions, Int32 expectedStackSize)
   at Smocks.IL.ExpressionDecompiler`1.Decompile(MethodBody body, Instruction instruction, Object target, Int32 expectedStackSize, Int32 stackEntriesToSkip)
   at Smocks.IL.ExpressionDecompiler`1.Decompile(MethodBody body, Instruction instruction, Object target)
   at Smocks.IL.SetupExtractor.<GetSetupsFromInstructions>d__10.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Smocks.Smock.CreateAssemblyRewriter(Delegate delegate, Configuration configuration)
   at Smocks.Smock.RunAction(Action`1 action, Configuration configuration)
   at Smocks.Smock.Run(Configuration configuration, Action`1 action)
   at Smocks.Smock.Run(Action`1 action)

VinS101 avatar Jan 02 '18 20:01 VinS101