Skip to main content
Dynamics 365 general forum
Suggested answer

XrmServiceContext.Create

editSubscribe (0) ShareShare
ReportReport
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

Attachments
  • 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,188 UG 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,188 UG 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

New Blog Features Released!

Check out the new community blog features for viewers and authors…

Setting Up Knowledge Sources for Copilot…

Look at how configuring a comprehensive knowledge base is crucial…

Demystifying Copilot with Georg Glantschnig…

Industry experts answer burning questions directly from our amazing Community…

Leaderboard

#1
Andre Arnaud de Calavon Profile Picture

Andre Arnaud de Cal... 283,126 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 222,646 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,138

Featured topics

Product updates

Dynamics 365 release plans