Skip to main content
session.clr is a CLRSessionProxy — available on every NSPSession that is attached to a .NET CLR application. It gives you direct access to the managed runtime: read fields by type name, invoke methods, and snapshot the heap, all without modifying the target application or writing any .NET code.

When to Use session.clr

Use session.clr when the field or method you need is not already surfaced in session.state. The high-level session state (session.get_str(...), session.get_int(...), etc.) reflects the semantic model that the NSP probe has already extracted. session.clr lets you reach below that model — reading raw CLR fields and invoking arbitrary managed methods. As a rule of thumb:
  • Start with session.state for any value the probe already exposes.
  • Use session.clr when you need runtime-specific fields, internal state, or method return values that are not in the semantic model.
CLR helpers require a probe confidence of at least 0.85. If the probe is still attaching, session.clr calls will raise NSPActionError with code clr_not_attached. Check session.state.runtime == RuntimeKind.CLR and session.confidence >= 0.85 before using CLR methods.

Prerequisites

read_field(type_name, field_name, *, timeout_ms)

Read the value of a single .NET field from the target process.
type_name
str
required
The fully-qualified .NET type name, e.g. "MissionPlanner.FlightData". Namespace-qualified names are required.
field_name
str
required
The field name, case-sensitive, exactly as it appears in the .NET source.
timeout_ms
int
default:"10000"
Maximum time in milliseconds to wait for the CLR bridge to respond.
Python types returned by read_field():

read_fields(type_name, *field_names, timeout_ms)

Read multiple fields from the same type in a single round-trip. This is more efficient than calling read_field() repeatedly.
type_name
str
required
Fully-qualified .NET type name.
*field_names
str
required
One or more field names to read.
timeout_ms
int
default:"10000"
Maximum time in milliseconds to wait for the CLR bridge.

invoke(type_name, method_name, args, *, timeout_ms)

Invoke a .NET method on the target process and return its result. Arguments are automatically coerced to the correct .NET types based on the target method’s parameter signature.
type_name
str
required
Fully-qualified .NET type name.
method_name
str
required
Method name, case-sensitive.
args
list[Any]
default:"None"
Positional arguments. Each value is coerced to the .NET type that matches the method’s parameter signature.
timeout_ms
int
default:"10000"
Maximum time to wait for the method to return.

Type Coercion Reference

When calling invoke(), supply Python values and the SDK maps them to .NET types automatically:

heap_snapshot(*, include_prefix, max_instances, timeout_ms)

Walk the CLR managed heap and return instances of matching types. Each returned object includes the type name and a field-value map.
include_prefix
str
default:"\"\""
Filter objects to types whose fully-qualified name starts with this prefix.
max_instances
int
default:"64"
Maximum number of object instances to return.
timeout_ms
int
default:"30000"
Timeout for the full heap walk, in milliseconds.
Heap snapshots pause the CLR garbage collector and can take 5–30 seconds depending on heap size. Use read_field() and read_fields() for real-time monitoring. Reserve heap_snapshot() for discovery and one-time debugging sessions.

Error Reference

Full Example: Mission Planner Telemetry Monitor