Pose 1.2.1

.NET Standard 2.0
Install-Package Pose -Version 1.2.1
dotnet add package Pose --version 1.2.1
<PackageReference Include="Pose" Version="1.2.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Pose --version 1.2.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Pose, 1.2.1"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Pose as a Cake Addin
#addin nuget:?package=Pose&version=1.2.1

// Install Pose as a Cake Tool
#tool nuget:?package=Pose&version=1.2.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Windows build status License: MIT NuGet version


Pose allows you to replace any .NET method (including static and non-virtual) with a delegate. It is similar to Microsoft Fakes but unlike it Pose is implemented entirely in managed code (Reflection Emit API). Everything occurs at runtime and in-memory, no unmanaged Profiling APIs and no file system pollution with re-written assemblies.

Pose is cross platform and runs anywhere .NET is supported. It targets .NET Standard 2.0 so it can be used across .NET platforms including .NET Framework, .NET Core, Mono and Xamarin. See version compatibility table here.


Available on NuGet

Visual Studio:

PM> Install-Package Pose

.NET Core CLI:

dotnet add package Pose


Pose gives you the ability to create shims by way of the Shim class. Shims are basically objects that let you specify the method you want to replace as well as the replacement delegate. Delegate signatures (arguments and return type) must match that of the methods they replace. The Is class is used to create instances of a type and all code you want to apply your shims to is isolated using the PoseContext class.

Shim static method

using Pose;

Shim consoleShim = Shim.Replace(() => Console.WriteLine(Is.A<string>())).With(
    delegate (string s) { Console.WriteLine("Hijacked: {0}", s); });

Shim static property getter

using Pose;

Shim dateTimeShim = Shim.Replace(() => DateTime.Now).With(() => new DateTime(2004, 4, 4));

Shim static property setter

using Pose;

Shim setterShim = Shim.Replace(() => Console.Title, true).With((string title) => { Console.Title = "My Title"; });

Shim instance property getter

using Pose;

class MyClass
    public int MyProperty { get; set; }
    public void DoSomething() => Console.WriteLine("doing someting");

Shim classPropShim = Shim.Replace(() => Is.A<MyClass>().MyProperty).With((MyClass @this) => 100);

Shim instance property setter

using Pose;

Shim classPropShim = Shim.Replace(() => Is.A<MyClass>().MyProperty, true).With((MyClass @this, int prop) => { @this.MyProperty = prop * 10; });

Shim constructor

using Pose;

Shim ctorShim = Shim.Replace(() => new MyClass()).With(() => new MyClass() { MyProperty = 10 });

Shim instance method of a Reference Type

using Pose;

Shim classShim = Shim.Replace(() => Is.A<MyClass>().DoSomething()).With(
    delegate (MyClass @this) { Console.WriteLine("doing someting else"); });

Note: The first argument to an instance method replacement delegate is always the instance of the class

Shim method of specific instance of a Reference Type

using Pose;

MyClass myClass = new MyClass();
Shim myClassShim = Shim.Replace(() => myClass.DoSomething()).With(
    delegate (MyClass @this) { Console.WriteLine("doing someting else with myClass"); });

Shim instance method of a Value Type

using Pose;

Shim structShim = Shim.Replace(() => Is.A<MyStruct>().DoSomething()).With(
    delegate (ref MyStruct @this) { Console.WriteLine("doing someting else"); });

Note: You cannot shim methods on specific instances of Value Types

Isolating your code

// This block executes immediately
PoseContext.Isolate(() =>
    // All code that executes within this block
    // is isolated and shimmed methods are replaced

    // Outputs "Hijacked: Hello World!"
    Console.WriteLine("Hello World!");

    // Outputs "4/4/04 12:00:00 AM"

    // Outputs "doing someting else"
    new MyClass().DoSomething();

    // Outputs "doing someting else with myClass"

}, consoleShim, dateTimeShim, classPropShim, classShim, myClassShim, structShim);

Caveats & Limitations

  • Breakpoints - At this time any breakpoints set anywhere in the isolated code and its execution path will not be hit. However, breakpoints set within a shim replacement delegate are hit.
  • Exceptions - At this time all unhandled exceptions thrown in isolated code and its execution path are always wrapped in System.Reflection.TargetInvocationException.


  • Performance Improvements - Pose can be used outside the context of unit tests. Better performance would make it suitable for use in production code, possibly to override legacy functionality.
  • Exceptions Stack Trace - Currently when exceptions are thrown in your own code under isolation, the supplied exception stack trace is quite confusing. Providing an undiluted exception stack trace is needed.

Issues & Contributions

If you find a bug or have a feature request, please report them at this repository's issues section. Contributions are highly welcome, however, except for very small changes kindly file an issue and let's have a discussion before you open a pull request.


This project is licensed under the MIT license. See the LICENSE file for more info.

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on Pose:

Repository Stars
Template engine based on Microsoft's Razor parsing engine for .NET Core
Version Downloads Last updated
1.2.1 340,197 6/26/2018
1.2.0 2,102 1/8/2018
1.1.0 14,252 11/23/2017
1.0.1 8,880 10/18/2017
1.0.0 918 10/10/2017