MethodBoundaryAspect.Fody 3.7.0

dotnet add package MethodBoundaryAspect.Fody --version 3.7.0
                    
NuGet\Install-Package MethodBoundaryAspect.Fody -Version 3.7.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MethodBoundaryAspect.Fody" Version="3.7.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MethodBoundaryAspect.Fody" Version="3.7.0" />
                    
Directory.Packages.props
<PackageReference Include="MethodBoundaryAspect.Fody" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MethodBoundaryAspect.Fody --version 3.7.0
                    
#r "nuget: MethodBoundaryAspect.Fody, 3.7.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package MethodBoundaryAspect.Fody@3.7.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MethodBoundaryAspect.Fody&version=3.7.0
                    
Install as a Cake Addin
#tool nuget:?package=MethodBoundaryAspect.Fody&version=3.7.0
                    
Install as a Cake Tool

MethodBoundaryAspect.Fody

Run your own code when a method starts, ends or throws, by putting an attribute on it:

[Log]
public int Add(int a, int b) => a + b;

MethodBoundaryAspect.Fody is a Fody weaver: the calls to your aspect are woven into the IL of the method at build time. There is no runtime proxy, no dependency injection container and no interface or virtual method required. It works for static, private, generic and async methods of any class, on .NET Framework 4.6.2+ and .NET (Core) / .NET Standard 2.0+.

Typical aspects: logging, measuring execution time, transaction handling, exception wrapping, showing a wait cursor, argument validation, caching.

Quickstart

  1. Add this package (it brings Fody along).

  2. Add a FodyWeavers.xml file to the project root:

    <Weavers>
      <MethodBoundaryAspect />
    </Weavers>
    
  3. Write an aspect by deriving from OnMethodBoundaryAspect and overriding any of OnEntry, OnExit and OnException:

    using System;
    using MethodBoundaryAspect.Fody.Attributes;
    
    public sealed class LogAttribute : OnMethodBoundaryAspect
    {
        public override void OnEntry(MethodExecutionArgs args) =>
            Console.WriteLine($"Entering {args.Method.Name}({string.Join(", ", args.Arguments)})");
    
        public override void OnExit(MethodExecutionArgs args) =>
            Console.WriteLine($"{args.Method.Name} returned {args.ReturnValue}");
    
        public override void OnException(MethodExecutionArgs args) =>
            Console.WriteLine($"{args.Method.Name} failed: {args.Exception.Message}");
    }
    
  4. Apply it to a method, a class, a property or the whole assembly ([assembly: Log]) and build:

    public class Calculator
    {
        [Log]
        public int Add(int a, int b) => a + b;
    }
    
    new Calculator().Add(1, 2);
    // Entering Add(1, 2)
    // Add returned 3
    

What an aspect can do

All three aspect methods get a MethodExecutionArgs with the information of the call:

Property Content
Instance the object the method is called on, null for static methods
Method the called method as MethodBase
Arguments the argument values (can be changed with [AllowChangingInputArguments] on the aspect)
ReturnValue the return value in OnExit, can be overwritten
Exception the thrown exception in OnException
FlowBehavior Return in OnEntry skips the method body, Continue in OnException swallows the exception
MethodExecutionTag any object you want to pass from OnEntry to OnExit/OnException of the same call
  • Select the methods with [DisableWeaving], regular expression filters for namespace, type and method name, and the visibility of the methods (AttributeTargetMemberAttributes).
  • Combine aspects on one method and order them with [AspectOrderIndex].
  • Async methods are supported: OnEntry runs when the method is called, OnExit when it returns its Task (args.ReturnValue is that task, the work may not be finished), OnException when the asynchronous work fails.
  • Low overhead: the weaver only provides the MethodExecutionArgs properties your aspects use, and creates aspects without state once instead of for every call.

Documentation

The complete documentation is the README on GitHub and the pages in its docs folder:

Questions and bug reports: GitHub issues. MIT license.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.6.2

  • .NETStandard 2.0

  • .NETStandard 2.1

NuGet packages (56)

Showing the top 5 NuGet packages that depend on MethodBoundaryAspect.Fody:

Package Downloads
TensorFlow.NET

Google's TensorFlow full binding in .NET Standard. Building, training and infering deep learning models. https://tensorflownet.readthedocs.io

TensorFlow.Keras

Keras for .NET Keras is an API designed for human beings, not machines. Keras follows best practices for reducing cognitive load: it offers consistent & simple APIs, it minimizes the number of user actions required for common use cases, and it provides clear & actionable error messages.

Marmat.Win.Template.WinForm

基于Marmat框架标准的默认实现。

EDennis.AspNetCore.Base

Alpha version that still requires (a) updated code comments, (b) updated wiki documentation, and (c) completed sample solution

Allure.Xunit.StepExtensions

Allure.Xunit.StepAttribute

GitHub repositories (3)

Showing the top 3 popular GitHub repositories that depend on MethodBoundaryAspect.Fody:

Repository Stars
SciSharp/TensorFlow.NET
.NET Standard bindings for Google's TensorFlow for developing, training and deploying Machine Learning models in C# and F#.
kendryte/nncase
Open deep learning compiler stack for Kendryte AI accelerators ✨
OpenSagas-csharp/servicecomb-pack-csharp
The .NET omega agent for Apache incubator-servicecomb-saga https://github.com/apache/servicecomb-pack
Version Downloads Last Updated
3.7.0 47 11/13/2026
3.6.0 17,681 10/21/2026
3.5.0 1,222 10/20/2026
3.4.0 259 10/20/2026
3.3.0 259 10/19/2026
3.2.1 606 10/18/2026
3.2.0 10,878 9/28/2026
3.1.0 652 9/28/2026
3.0.0 1,105 9/27/2026
2.0.152 1,154 10/19/2026
2.0.151 695 10/18/2026
2.0.150 1,675,181 11/26/2024
2.0.149 1,507,727 7/9/2023
2.0.148 1,066,347 11/11/2022
2.0.146 17,813 9/23/2022
Loading failed