web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to fix plugin error on Pre Update: Context is not initialized or already cleaned up

(0) ShareShare
ReportReport
Posted on by 193

Hi All,

I encountered the error Context is not initialized or already cleaned up on my plugin that is triggered Pre Update of Account entity. See code below. 8764.code.png

Can you please let me know what is the fix on this? Thanks!

Context is not initialized or already cleaned up

*This post is locked for comments

I have the same question (0)
  • gdas Profile Picture
    50,091 Moderator on at

    May I know why you are not retrieving context from the service provider parameter of the execute method? 

    Here is sample code -

            public void Execute(IServiceProvider serviceProvider)
            {
    
                // Obtain the execution context from the service provider.
                IPluginExecutionContext context = (IPluginExecutionContext)
                    serviceProvider.GetService(typeof(IPluginExecutionContext));
    
                     ---------------------
                     ----------------------
  • Kalpavruksh D365 CoE Profile Picture
    2,545 on at

    Hi,

    Can you share the details of the following function as it is calling some internal function which may be causing an issue: if(context.MessageName=="Update")

    {

    Pre_Update(localcontext);

    }

  • Suggested answer
    Kalpavruksh D365 CoE Profile Picture
    2,545 on at

    Hi,

    Please do not use the base plugin class concept(LocalPluginContext) . Define the context inside the class and pass as a parameter to other methods.

    context.png

    https://github.com/microsoft/PowerApps-Samples/blob/master/cds/orgsvc/C%23/FollowupPlugin/FollowupPlugin/SampleProgram.cs

    If found useful, please mark this answer as a verified answer.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
ScottDurow Profile Picture

ScottDurow 2

#2
GJones Profile Picture

GJones 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans