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

  • Home
  • SEARCH
  • 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 904339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:01:56+00:00 2026-05-15T16:01:56+00:00

I’d like to have access to the bytecode that is currently running or about

  • 0

I’d like to have access to the bytecode that is currently running or about to run in order to detect certain instructions and take specific actions (depending the instructions). In short, I’d like to monitor the bytecode in order to add safety control (see EDIT #1 for explanation).

Is this possible? I know there are some AOP frameworks that notify you of specific events, like an access to a field or the invocation of a method, but I’d like to skip that extra layer and just look at all the bytecode myself, throughout the entire execution of the application.

I’ve already looked at the following questions (…among many many others 😉 ):
    Preprocessing C# – Detecting Methods
    What CLR/.NET bytecode tools exist?
as well as several AOP frameworks (although not in great detail, since they don’t seem to do quite what I need) and I’m familiar with Mono.Cecil.

I appreciate alternative suggestions, but I don’t want to introduce the overhead of an AOP framework when what I actually need is access to the bytecode, without all the stuff they add on top to make it more user-friendly (… admittedly very useful stuff when you don’t want to go low-level).

Thanks 🙂


EDIT #1: more details on what I want to do.

Basically, I have a C# application and I need to monitor the instructions it wants to run in order to detect read or write operations to fields (operations Ldfld and Stfld) and insert some instructions before the read/write takes place: I may need to acquire locks, or if that fails abort the operation. Also, I may need to update a read log (in case of a read) or write log (in case of a write).

In fact, what I’d really like to do is to replace the read/write instruction with my own custom code, but it that fails I think I could manage just inserting some instructions before and after.


EDIT #2: PostSharp

Dave suggests I use PostSharp

The problem is at compile time I still don’t know which classes I’m going to need to weave, so I’d like to delay this until they are loaded. As I understand, this isn’t possible with PostSharp? Please correct me if I’m wrong.

I know PostSharp does load-time static weaving, but apparently “there is currently no “off-the-shelf” way to perform it” (notice however that this post is from PostSharp 1.5; maybe this has changed). I guess it would still be easier than just doing everything myself, but I can’t find any info on how PostSharp would help me in this case. I guess I’ll ask in the PostSharp forums.

  • 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-15T16:01:56+00:00Added an answer on May 15, 2026 at 4:01 pm

    The answer is no. You can use the (extremely low-level and unmanaged-code-only) Profiling API to receive notifications of certain events, but not of access to fields, which is what I wanted. Plus, it’s not supposed to be used in production:

    (from the previous link)

    Profiling in production environments
    with high-availability requirements.
    The profiling API was created to
    support development-time diagnostics.
    It has not undergone the rigorous
    testing required to support production
    environments.

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

Sidebar

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.