Friday, May 6, 2016

Explore a managed solution’s plugin assembly programmatically in Dynamics CRM Online.

Reference -

https://debajmecrm.com/2015/11/21/tips-tricks-explore-a-managed-solutions-plugin-assembly-programmatically-in-dynamics-crm-online/comment-page-1/#comment-698



My client is running CRM 2015 online and all of a sudden, this managed assembly started throwing error. It contained some cool stuffs. So we cannot get rid of it. After multiple discussions with our client, we decided to rewrite the stuffs in the assembly. So we need the assembly. But how do we do it?
Since it is a managed solution, you cannot export it. After putting my head around it, I created a console application to get out the DLL. Just a few lines of code and I am pretty sure that if you are from a programming background like me, you would love this. So let’s see the code here.
private static void ReadPluginAssembly(OrganizationServiceProxy proxy)
        {
            var queryExp = new QueryExpression("pluginassembly");
            queryExp.Criteria.AddCondition("name",ConditionOperator.Like, "TestPlugins%");
            queryExp.ColumnSet.AddColumn("content");
            var result = proxy.RetrieveMultiple(queryExp);
            var base64Content = result.Entities[0].GetAttributeValue<string>("content");
            var byteContent = Convert.FromBase64String(base64Content);
           System.IO.File.WriteAllBytes(@"c:\debajit\TestPlugins.dllteContent);
        }
Let me explain the code here a bit. First I have queried the pluginassembly entity for the particular assembly in question here and retrieve the content field. The content field is where CRM stores the entire content of the plugin assembly as base 64 encoded string.
So I get the content and covert the base64 string to byte content. And then I saved the byte content to an assembly with the same name.
And how do I get the code from here. Use the wonderful Red-Gate .NET reflector or ILSpy and you would find much of the code. With little bit of modifications, you can just copy paste the entire code.
Hope you find this interesting.

No comments:

Post a Comment