Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

XrmServiceContext.Create

(0) ShareShare
ReportReport
Posted on by 511

Hi

I'm currently upgrading to 8.2 from an earlier version. (the business wants it to be 8.2)

I'm getting an error on XrmServiceContext.Create(entity).

I'm guessing this has been superseded by something else.

Can anyone let me know what I should be looking for?

I'm also having difficulty with update and a couple of other methods.

Thanks
Lee

  • Lee-Martin Profile Picture
    511 on at
    RE: XrmServiceContext.Create

    This didn't work as private readonly IOrganizationService _serviceContext; would always be null

  • Lee-Martin Profile Picture
    511 on at
    RE: XrmServiceContext.Create

    I've added a line at the top of my code

    private readonly IOrganizationService _serviceContext;

    This replaces the call to XRMServiceContext (which refers to the xrm.cs file)

    This eliminates the compile error.

    Is this the right approach or will I get lots of problems later on?

  • Lee-Martin Profile Picture
    511 on at
    RE: XrmServiceContext.Create

    I've a copy of the old xrm.cs file

    There are missing methods in the new one.

    Is this a result of the upgrade to 8.2?

    What I am reading tells me that Microsoft.Xrm.Sdk.IOrganizationService should give me what I require

    old file

    /// Represents a source of entities bound to a CRM service. It tracks and manages changes made to the retrieved entities.
    /// </summary>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("CrmSvcUtil", "6.0.0000.0809")]
    public partial class XrmServiceContext : Microsoft.Xrm.Client.CrmOrganizationServiceContext
    {

    /// <summary>
    /// Constructor.
    /// </summary>
    public XrmServiceContext()
    {
    }

    /// <summary>
    /// Constructor.
    /// </summary>
    public XrmServiceContext(Microsoft.Xrm.Client.CrmConnection connection) :
    base(connection)
    {
    }

    /// <summary>
    /// Constructor.
    /// </summary>
    public XrmServiceContext(string contextName) :
    base(contextName)
    {
    }

    /// <summary>
    /// Constructor.
    /// </summary>
    public XrmServiceContext(Microsoft.Xrm.Sdk.IOrganizationService service) :
    base(service)
    {
    }

    new file

    /// <summary>
    /// Represents a source of entities bound to a CRM service. It tracks and manages changes made to the retrieved entities.
    /// </summary>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("CrmSvcUtil", "8.2.1.8676")]
    public partial class XrmServiceContext : Microsoft.Xrm.Sdk.Client.OrganizationServiceContext
    {

    /// <summary>
    /// Constructor.
    /// </summary>
    public XrmServiceContext(Microsoft.Xrm.Sdk.IOrganizationService service) :
    base(service)
    {
    }

  • Lee-Martin Profile Picture
    511 on at
    RE: XrmServiceContext.Create

    Severity Code Description Project File Line Suppression State

    Error CS1061 'XrmServiceContext' does not contain a definition for 'Associate' and no accessible extension method 'Associate' accepting a first argument of type 'XrmServiceContext' could be found (are you missing a using directive or an assembly reference?)

  • Lee-Martin Profile Picture
    511 on at
    RE: XrmServiceContext.Create

    It's shared above

  • meelamri Profile Picture
    13,212 User Group Leader on at
    RE: XrmServiceContext.Create

    Could you please share the error?

  • Lee-Martin Profile Picture
    511 on at
    RE: XrmServiceContext.Create
    Mehdi El Amri wrote the following post at 10 May 2021 2:38 AM:

    Hi Lee,

    You should use 4.5.2

    ---

    Thanks, changed it

    Unfortunately it's still not solved the issue :(

  • Suggested answer
    meelamri Profile Picture
    13,212 User Group Leader on at
    RE: XrmServiceContext.Create

    Hi Lee,

    You should use 4.5.2

  • Lee-Martin Profile Picture
    511 on at
    RE: XrmServiceContext.Create

    I've got the target framework as 4.7.2

    Could it be that I need to use an earlier framework for the 8.2 sdk?

  • Lee-Martin Profile Picture
    511 on at
    RE: XrmServiceContext.Create

    Thank you but the code is not all mine, the xrm.cs file is being generated for me, and I am expected to use it.

    Is there anything available which directly helps me with the issue I am having?

    the code is using Microsoft.Xrm.Sdk.IOrganizationService

    but I cannot access .Create . Associate .Update etc...

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,278 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,002 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans