Skip to content

Fix NullReferenceException when plugins with post-images fire via Multiple requests#322

Merged
mkholt merged 3 commits intomasterfrom
feature/311-nullreferenceexception-when-update-plugi
Mar 23, 2026
Merged

Fix NullReferenceException when plugins with post-images fire via Multiple requests#322
mkholt merged 3 commits intomasterfrom
feature/311-nullreferenceexception-when-update-plugi

Conversation

@mkholt
Copy link
Member

@mkholt mkholt commented Mar 20, 2026

When Update/Create is triggered via UpdateMultipleRequest/CreateMultipleRequest, plugins registered on the single operation with post-images crashed because the Multiple->Single cross-trigger passed null for pre/post images.

  • Add null guards for preImage/postImage in AddPostImageAttributesToEntity
  • Fix operator precedence bug in CreatePluginContext where ImageType.Both bypassed null check
  • Retrieve per-entity images from DB in Multiple->Single cross-trigger
  • Make Core.TryRetrieve internal so PluginManager can access it

Fixes Issue: #311

…tiple requests

When Update/Create is triggered via UpdateMultipleRequest/CreateMultipleRequest,
plugins registered on the single operation with post-images crashed because the
Multiple->Single cross-trigger passed null for pre/post images.

- Add null guards for preImage/postImage in AddPostImageAttributesToEntity
- Fix operator precedence bug in CreatePluginContext where ImageType.Both bypassed null check
- Retrieve per-entity images from DB in Multiple->Single cross-trigger
- Make Core.TryRetrieve internal so PluginManager can access it

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Issue: #311
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes plugin image handling when CreateMultiple/UpdateMultiple cross-triggers Create/Update steps, preventing NullReferenceException for plugins that rely on post/pre images and improving correctness of image population in the generated plugin execution context.

Changes:

  • Add null guards in AddPostImageAttributesToEntity to prevent NREs when pre/post images are not available.
  • Fix operator precedence in CreatePluginContext so ImageType.Both no longer bypasses the null check.
  • In Multiple→Single cross-triggering, retrieve per-entity images from the in-memory DB via Core.TryRetrieve (and expose TryRetrieve internally to allow this).

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/XrmMockup365Test/TestMultipleRequestPluginImages.cs Adds regression tests covering UpdateMultiple/CreateMultiple image behavior and cross-trigger stability.
tests/TestPluginAssembly365/Plugins/ContactPostImageOnUpdatePlugin.cs Adds a test plugin that asserts PostEntityImages presence by creating a Task with a marker.
src/XrmMockup365/Plugin/PluginTrigger.cs Adds null guards and fixes image-type conditional precedence when building plugin images.
src/XrmMockup365/Plugin/PluginManager.cs Retrieves per-entity images during Multiple→Single cross-trigger and wires them into plugin triggering.
src/XrmMockup365/Core.cs Makes TryRetrieve internal for reuse by PluginManager; also fixes a log message character.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

mkholt and others added 2 commits March 20, 2026 22:31
… tests

Use RegisterPluginStep (avoids XrmPluginCore method group resolution bug
with RegisterStep that causes StackOverflow). Simplify test assertions to
focus on verifying the NullReferenceException fix.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Issue: #311
Resolve conflicts in PluginManager.cs by taking master's IPluginExecutionContext4
image collection implementation, which supersedes our TryRetrieve-based approach.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Issue: #311
@mkholt mkholt merged commit e6d4aa1 into master Mar 23, 2026
2 checks passed
@mkholt mkholt deleted the feature/311-nullreferenceexception-when-update-plugi branch March 23, 2026 07:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants