Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 139105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:22:32+00:00 2026-05-11T07:22:32+00:00

The solution for this error has escaped me for several days now, and it

  • 0

The solution for this error has escaped me for several days now, and it is time to come here for help. The short version is, I have a unit test that fails on the build server but no other environment.

The method I’m testing is an extension method for ILog in log4net. The purpose of this extension method is to make a debug log of the current method, when called and I use it for debugging. The code to do this is pretty straight forward.

public static void MethodHead(this ILog log, params object[] parameters) {     /* Assert */     log.AssertNonNull();      /* Since this is an expensive operation, don't do it if Debug is not enabled */     if (log.IsDebugEnabled)     {         StackTrace stackTrace = new StackTrace();          /* Get calling method */         MethodBase method = stackTrace.GetFrame(1).GetMethod();          string logMessage = string.Format('{0}.{1}({2})', method.DeclaringType.Name, method.Name, parameters.ToDelimitedString(', '));         log.Debug(logMessage);     } } 

In this method I check that debug mode is enabled, because I don’t want to do StackTrace if nothing is supposed to get logged (because of performance issues). When I test this method I will use Rhino Mocks to mock the ILog interface and let IsDebugEnabled return true.

Please consider following NUnit test method.

[Test(Description = 'Verify that MethodHead extension method will log with calling class.method(arguments)')] public void MethodHeadShouldLogCurrentMethodNameWithArguments() {     /* Setup */     MockRepository mocks = new MockRepository();     ILog log = mocks.CreateMock<ILog>();     string[] arguments = new string[] { 'CAT', 'IN', 'A', 'HAT' };      string logMessage = string.Format('{0}.{1}({2})',         'MethodHeadTest', 'CallingMethod', arguments.ToDelimitedString(', '));      With.Mocks(mocks).Expecting(delegate     {         /* Record */         Expect.Call(log.IsDebugEnabled).Return(true);         Expect.Call(delegate { log.Debug(logMessage); });     })     .Verify(delegate     {         /* Verify */         CallingMethod(log, arguments);     }); }  private void CallingMethod(ILog log, params object[] arguments) {     log.MethodHead(arguments); } 

This executes well in my development environment, Visual Studio 2008 with TestDriven.NET. It does execute well if I run the test through nunit-console.exe or nunit-gui. It even runs well if I use my NAnt script to execute the test.

However, my build server fails this test when it runs through NAnt which is executed from CruiseControl.NET. When I run it manually with nunit-console.exe on the build server it succeeds.

The error and stack trace are the following.

Rhino.Mocks.Exceptions.ExpectationViolationException : ILog.Debug('**<>c__DisplayClass8.<MethodHeadShouldLogCurrentMethodNameWithArguments>b__5**(CAT, IN, A, HAT)'); Expected #0, Actual #1.  ILog.Debug('MethodHeadTest.CallingMethod(CAT, IN, A, HAT)'); Expected #1, Actual #0.  at Rhino.Mocks.MethodRecorders.UnorderedMethodRecorder.DoGetRecordedExpectation(IInvocation invocation, Object proxy, MethodInfo method, Object[] args) at Rhino.Mocks.MethodRecorders.MethodRecorderBase.GetRecordedExpectation(IInvocation invocation, Object proxy, MethodInfo method, Object[] args) at Rhino.Mocks.Impl.ReplayMockState.DoMethodCall(IInvocation invocation, MethodInfo method, Object[] args) at Rhino.Mocks.Impl.ReplayMockState.MethodCall(IInvocation invocation, MethodInfo method, Object[] args) at Rhino.Mocks.MockRepository.MethodCall(IInvocation invocation, Object proxy, MethodInfo method, Object[] args) at Rhino.Mocks.Impl.RhinoInterceptor.Intercept(IInvocation invocation) at Castle.DynamicProxy.AbstractInvocation.Proceed() at ILogProxy86e676a4761d4509b43a354c1aba33ed.Debug(Object message) at Vanilla.Extensions.LogExtensions.MethodHead(ILog log, Object[] parameters) in d:\Build\Mint\WorkingDirectory\Source\Main\Vanilla\Extensions\LogExtensions.cs:line 42 at Vanilla.UnitTests.Extensions.LogExtensions.MethodHeadTest.<>c__DisplayClass8.<MethodHeadShouldLogCurrentMethodNameWithArguments>b__5() in d:\Build\Mint\WorkingDirectory\Source\Test\Vanilla.UnitTests\Extensions\LogExtensions\MethodHeadTest.cs:line 99 at Rhino.Mocks.With.FluentMocker.Verify(Proc methodCallsToBeVerified) at Vanilla.UnitTests.Extensions.LogExtensions.MethodHeadTest.MethodHeadShouldLogCurrentMethodNameWithArguments() in d:\Build\Mint\WorkingDirectory\Source\Test\Vanilla.UnitTests\Extensions\LogExtensions\MethodHeadTest.cs:line 90 

So the problem is that the build server thinks that this method has another (dynamic?) name. Or rather it is Rhino Mocks that makes this assumption?

I don’t get anywhere with this error since I can’t recreate it on my development machine. I’m happy for all input I can get.

Thank you!

Mikael Lundin

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T07:22:32+00:00Added an answer on May 11, 2026 at 7:22 am

    Looks like CallingMethod was optimized away on the build server. When you repeated the test manually, did you really use exactly the same assembly?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 98k
  • Answers 98k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer First: Try to avoid <xsl:for-each>. It's a bad choice most… May 11, 2026 at 7:39 pm
  • Editorial Team
    Editorial Team added an answer custom source libraries accessible to SQL Server... no problem says… May 11, 2026 at 7:39 pm
  • Editorial Team
    Editorial Team added an answer You mean something like this: The 'Left Menu' 2 column… May 11, 2026 at 7:39 pm

Related Questions

I have the following code to convert a distinguishedName to a sAMAccountName: Dim de
While cross-site scripting is generally regarded as negative, I've run into several situations where
We get this error in Visual Studio 2005 and TFS very often. Can anyone
I have a question regarding handling errors in a J2EE application. Our current application

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.