0

How can the size (MB) of a workflow assembly be reduced?

An assembly with 4 custom workflow activities is 2.5 MB with the class that crmcsvutil.exe generates from CRM; the same assembly is 18 KB when the generated class is not included in the project!

Plugin registration often fails after timing out, so I would really like to reduce the size of the assembly.

I have tried placing the generated class in a separate assembly and referencing it, and placing the assembly in the GAC, but get an error.

This is when the assembly is registered in the sandbox (which I really prefer):

Assembly 'Tinkerbell.Workflows, Version=2.0.3.4, Culture=neutral, PublicKeyToken=692195edcbe6b163' is partially trusted, which causes the CLR to make it entirely security transparent regardless of any transparency annotations in the assembly itself.  In order to access security critical code, this assembly must be fully trusted.'

This is when the assembly is registered outside of the sandbox:

'Object of type 'Microsoft.Xrm.Sdk.Entity' cannot be converted to type 'BusinessUnit'.'

What are the options here?
I am unwilling to give up early bound classes.

2 Answers 2

2

You can generate only the early bound entities you need, with this utility Filtering generated entities with CrmSvcUtil.

You just need to specify a xml with the desired entities:

<filter>
  <entities>
    <entity>systemuser</entity>
    <entity>team</entity>
    <entity>role</entity>
    <entity>businessunit</entity>
  </entities>
</filter> 
1

You could manually edit the class file that CRM generates to strip out all but the entities that you need but that would be a bit of a pain and would need to be redone if you ever regenerated the CRM class file.

Is there a reason why you don't want to abandon early classes? Late bound does have some advantages and is slightly quicker. If you want to keep the early bound feel then you can write your own classes and then write mapping functions that translate from your classes to entities.

6
  • I do not want to give up Linq to CRM. Can I still use Linq without the generated classes?
    – Bvrce
    Feb 12, 2014 at 8:46
  • 1
    Not really, you would have to use some of the other methods of getting at CRM data, once you have that data you can still use LINQ to Objects. Personally I use QueryExpression unless I need to do aggregates then I use FetchXML. I then write my own classes to contain my business logic and finally mapping functions to translate between the two. If you want to stick with LINQ to CRM then you will have to trim the CRM generated file.
    – Kevin Ross
    Feb 12, 2014 at 9:08
  • I would need an industrial lawnmower to trim that file. Thank you for the insight into how you query CRM. I am aware that there are performance benefits to FetchXML and QueryExpression, but the readability and ease of use of Linq to CRM is great.
    – Bvrce
    Feb 12, 2014 at 9:14
  • Do you have any idea why I get that error when registering the assembly outside of the sandbox? I would like to have the generated class in an assembly in the GAC, but keep getting that error, or similar depending on the entity.
    – Bvrce
    Feb 12, 2014 at 9:19
  • Sorry but I can't help you on that. With the one plugin I have that uses Early Bound classes I have included the class file within the plugin DLL so it does not have to try to get it from the GAC.
    – Kevin Ross
    Feb 12, 2014 at 9:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.