johnny 5
johnny 5

Reputation: 21015

Add break point to default constructor

I have a class, which has a default constructor inherently.

public class OneRollingFileAppender : RollingFileAppender
{
    #region RollingFileAppender Overrides

    protected override void Append(LoggingEvent loggingEvent)
    {

        GlobalFactory<ILoggingEventParameterManager>.Instance.Apply(loggingEvent);
        base.Append(loggingEvent);
    }

    #endregion
}

Without editing the code, e.g adding a new constructor or property, how can I breakpoint default constructor?

NOTE: There should be a technique which will to find the code in IL or in memory, and then I'd like to set a breakpoint there.

Upvotes: 4

Views: 1816

Answers (4)

Postlagerkarte
Postlagerkarte

Reputation: 7117

Use WinDbg + SOS Extension

  1. Attach to the process with Windbg (File/Attach to process)

  2. load sos (.loadby sos mscorwks)

  3. Set the breakpoint ( !bpmd mylib.dll Namespace.ClassName..ctor )

If you just want to know when the class is created you can make use of a function breakpoint within Visual Studio. Debug -> New Breakpoint

enter image description here

As Function name you enter your class name.

Upvotes: 4

Jonathan
Jonathan

Reputation: 5018

You can't put a breakpoint in compiled code that you don't control. However, with something like ReSharper, you can step into third party code. See: https://www.jetbrains.com/help/resharper/Debugging_Without_Source_Code.html

Upvotes: 0

Nitesh Singhal
Nitesh Singhal

Reputation: 46

I believe you are using log4net. As you don't have source code so you cannot put break point on your constructor.

Upvotes: 0

MikeH
MikeH

Reputation: 4395

If you create a variable and assign a value in your class you can place a break point there which will be hit when an instance of the class is created.

public class OneRollingFileAppender : RollingFileAppender
{
  int foo = 0; //Place break point here
}

Upvotes: 2

Related Questions