Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 general forum
Suggested answer

XrmServiceContext.Create

Posted on by 507

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
    Lee-Martin 507 on at
    RE: XrmServiceContext.Create

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

  • Lee-Martin Profile Picture
    Lee-Martin 507 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
    Lee-Martin 507 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
    Lee-Martin 507 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
    Lee-Martin 507 on at
    RE: XrmServiceContext.Create

    It's shared above

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

    Could you please share the error?

  • Lee-Martin Profile Picture
    Lee-Martin 507 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
    meelamri 13,198 User Group Leader on at
    RE: XrmServiceContext.Create

    Hi Lee,

    You should use 4.5.2

  • Lee-Martin Profile Picture
    Lee-Martin 507 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
    Lee-Martin 507 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...

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 288,584 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,864 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans