It was my understanding that calling context.GetPolicy<T>() would create an instance of the policy if it wasn't attached to the environment, however I'm seeing the opposite in a pipeline block that's invoked from a custom minion. It's even causing NullReferenceExceptions in some built in pipeline blocks, so clearly something is up.

Any ideas on what might cause this change of behaviour?

1 Answer 1


This happens when you create a CommerceContext without assigning it's Environment property (which has no associated constructor argument). Since policies are resolved from the environment, it will return null if there is no environment available.

So in your minion:

// This will cause GetPolicy to return null
var context = new CommerceContext(this.Logger, base.MinionContext.TelemetryClient, null);

// This will work correctly
var context = new CommerceContext(this.Logger, base.MinionContext.TelemetryClient, null)
    Environment = base.Environment

var options = new CommercePipelineExecutionContextOptions(context);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.