12

I'm using CrmSvUtil this way:

crmsvcutil.exe /url:http://crm2011/MyTestOrg/XRMServices/2011/Organization.svc /out:GeneratedCode.cs /namespace:Xrm /serviceContextName:XrmDataContext

And the output contains thousands of business objects and this context class:

[System.CodeDom.Compiler.GeneratedCodeAttribute("CrmSvcUtil", "5.0.9688.1533")]
public partial class XrmDataContext : Microsoft.Xrm.Sdk.Client.OrganizationServiceContext

But looking at the samples (namely .\sdk\walkthroughs\portal\consoleappwalkthrough) I clearly can see there that the context class should be derived from a more mighty sub class of OrganizationServiceContext -> CrmOrganizationServiceContext:

[System.CodeDom.Compiler.GeneratedCodeAttribute("CrmSvcUtil", "5.0.9688.583")]
public partial class XrmServiceContext : Microsoft.Xrm.Client.CrmOrganizationServiceContext

I definitely need CrmOrganizationServiceContext because only then I have the constructors I need. So what I'm doing wrong or which setting did I miss?

springy76
  • 3,706
  • 2
  • 24
  • 46
  • 3
    This wil cause issues if you use the generated code in a plugin/custom activity since it takes a dependency on microsoft.xrm.client.dll. This DLL is not included in the default server installation and you will need to ensure that the dll is present on the server (dev/qa/prod). I decided against using the /codecustomization flag for that reason and decided to stick with the "OrganizationContext" derived class instead. – Abhijeet Patel Aug 14 '12 at 03:35
  • Good to know. My current usage case were external data-import/-export tools (console-apps) which access CRM on the local network. – springy76 Aug 17 '12 at 11:15
  • Hi, Thank you springy76 for posing the exact question I had, and Thank you Abhijeet Patel for posting the answer, however am stuck with one more question as to when would one use either of the methods mentioned above? Is there any advantage of one over the other, other than the dll being available in the prod server? – Jaya Sep 30 '13 at 18:51

2 Answers2

14

Check out the parameters given @ the web version of that SDK sample. They will generate the class you're looking for.

CrmSvcUtil.exe /codeCustomization:"Microsoft.Xrm.Client.CodeGeneration.CodeCustomization, Microsoft.Xrm.Client.CodeGeneration" /out:Xrm\Xrm.cs /url:http://Crm/Contoso/XRMServices/2011/Organization.svc /domain:CONTOSO /username:administrator /password:pass@word1 /namespace:Xrm /serviceContextName:XrmServiceContext
Peter Majeed
  • 5,304
  • 2
  • 32
  • 57
  • 2
    I love "undocumented" CLI parameters -- maybe there even is one for creating one class per file like it was possible with v4? R# is dying on these 5MB C# files. – springy76 Jan 26 '12 at 09:53
  • As was mentioned, you can filter out the default `Xrm.cs` file to only include the entities you're interested in to some degree of satisfaction. I mention a few ways to do this in a recent question I asked. http://stackoverflow.com/questions/8946223/how-can-i-make-crmsvcutil-exe-generate-unduplicated-error-free-early-bound-opti – Peter Majeed Jan 26 '12 at 15:09
  • @springy76: And yeah - these undocumented features are killing me. I don't see the specs for the `/codeCustomization` parameter anywhere, but it's things like this that we need. – Peter Majeed Jan 26 '12 at 15:10
  • @springy76 You can create an extension for the CrmSvcUtil utility. More information [here](http://erikpool.blogspot.com/2011/03/filtering-generated-entities-with.html) – Mikhail T. Jan 26 '12 at 11:07
  • Just a note but this string only works with Dynamics CRM 2011; you have to remove /serviceContextName:XrmServiceContext to make it work for CRM 4.0. – Russ Clarke Feb 02 '12 at 13:09
  • Hi, Thank you springy76 for posting the exact question I had, and Thank you Peter Majeed for posting the answer, however am stuck with one more question as to when would one use either of the methods mentioned above? Is there any advantage of one over the other, other than the dll being available in the prod server? – Jaya Sep 30 '13 at 19:17
  • 1
    @user1639515 I asked the same question: http://stackoverflow.com/questions/21270081/what-changes-does-referencing-codegeneration-codecustomization-make-to-the-early – Daryl Oct 01 '14 at 13:43
0

Use the Early Bound Generator, and select check the check box "Use Xrm Client". It'll generate the Context with the base class you're expecting.

Daryl
  • 18,592
  • 9
  • 78
  • 145