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 6122109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:51:38+00:00 2026-05-23T15:51:38+00:00

I made a simple test of the Castle Dynamic Proxy library: public class Printer

  • 0

I made a simple test of the Castle Dynamic Proxy library:

public class Printer
{
    public virtual void Write(string msg)
    {
        Console.Write(msg); 
    }
}

public class CastleDynamicProxy
{
    public static void Test()
    {
        ProxyGenerator generator = new ProxyGenerator();

        Printer logger = generator.CreateClassProxy<Printer>(new TestInterceptor());

        logger.Write("Hello, World!"); 
    }
}

Now in my interceptor I want to time the function, but its causing a StackOverflowException because I am calling the target method inside the Intercept method, causing an infinite loop:

public class TestInterceptor : IInterceptor
{
    public void Intercept(IInvocation invocation)
    {
       var accessor = invocation.Proxy as IProxyTargetAccessor;

       MethodInfo target = accessor.DynProxyGetTarget().GetType().GetMethod("Write"); 

       var s = Stopwatch.StartNew(); 

       target.Invoke(invocation.InvocationTarget, invocation.Arguments);

       s.Stop(); 
    }
}

Is there anyway around this, either by 1) stopping the interceptions process altogether, or 2) removing my interceptor after I have used it for what I need, before getting into an infinite loop?

  • 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. Editorial Team
    Editorial Team
    2026-05-23T15:51:39+00:00Added an answer on May 23, 2026 at 3:51 pm

    Are you sure that’s what you want to do? I’ve created a timing interceptor as well to see if a method call (such as a DB query) exceeds a threshold, and if so to log it.

    Instead of manually invoking the target, just use invocation.Proceed() to tell it to go ahead with the intercepted call.

    My code looks like this:

            public void Intercept(IInvocation invocation)
            {
                var timer = Stopwatch.StartNew();
    
                // i think you want this to proceed with the invocation...
                invocation.Proceed();
    
                timer.Stop();
    
                // check if threshold is exceeded
                if (timer.Elapsed > _threshold)
                {
                    // log it to logger of choice
                }
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I made a simple Test Class to simplify my actual problem : public class
I'm using AbstractTransactionalJUnit4SpringContextTests to run a simple test: public class MyTests extends AbstractTransactionalJUnit4SpringContextTests {
I have made a simple test application for the issue, two winforms each containing
I'm putting together a simple test made up of two tutorials available online for
I have a little trouble getting gettext to work. I made a simple test
I have made a super simple test case of a problem I'm having with
I am just starting to learn Core Audio and made a simple test application
I've made a simple installer that installs test.txt, but there are several problems: The
My PHP is not PHPing, so made simple test... must be missing something obvious.
.NET 2.0 introduced VTS (Version Tolerant Serialization, http://msdn.microsoft.com/en-us/library/ms229752(VS.80).aspx ) A simple test project reveals

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.