{Tips & Tricks} Explore a managed solution’s plugin assembly programmatically in Dynamics CRM Online.

I never find a good title to explain my blog post. So I would rather suggest you read through my entire post even if blog title seems absolutely non-sense Smile.

So coming back to the topic here, first let me tell you why I needed to do all this stuff. My customer environment contained a managed solution which had a utility plugin. The solution was developed by some consultant company who was working for my customer initially. The source code for the managed solution was with the consultant firm. Unfortunately during handover, the source code handover got missed.

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.dll", byteContent);

        }

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.

Advertisements

About Debajit
I am a Dynamics CRM Most Valuable Professional (MVP) with 10 years of experience in Microsoft .NET Technologies and 7 years of dedicated experience in Microsoft Dynamics CRM. I have worked with companies like Microsoft, SanDisk, PwC, TMF Group and have extensive experience of implementing complex CRM solutions from both offshore and client side. Currently the face of XrmForYou.com with significant experience in delivering corporate training on Dynamics CRM and have already delivered multiple projects to client through XrmForYou.com Author of multiple tools on codeplex including the 'Role Based Views' and 'CRM-Sharepoint Metadata manager & Attachment Extractor' which are available for commercial use under XrmForYou.com For consulting/ training, drop me a note at info@xrmforyou.com or visit our website www.xrmforyou.com

7 Responses to {Tips & Tricks} Explore a managed solution’s plugin assembly programmatically in Dynamics CRM Online.

  1. Rahul says:

    You could include the assembly in unmanaged solution and export it.

    • Debajit says:

      Hi Rahul,
      Even if you include a managed component in unmanaged solution, when you export the solution, the item will not available in the exported solution. Managed components are referred in the solution just as reference.

      Regards
      Debajit

  2. Abhishek says:

    Hi , I appreciate your deep thinking and effort it works. But check the syntax

    var byteContent = Convert.FromBase64String(base64Content);
    System.IO.File.WriteAllBytes(@”c:\abhi\new.dll”, byteContent);

    • Debajit says:

      Thanks for reading my blog. Could you let me know what is wrong here. Sorry but I am not able to find out. my be i am overlooking
      something here

  3. Abhishek says:

    System.IO.File.WriteAllBytes(@”c:\debajit\TestPlugins.dllteContent);- this doesn’t work.

    this worked – System.IO.File.WriteAllBytes(@”c:\abhi\new.dll”, byteContent);

    • Debajit says:

      ot sure from where in the blog you are getting this line.

      System.IO.File.WriteAllBytes(@”c:\debajit\TestPlugins.dllteContent); It has no commas and .dlltecontent I am sure is typo and is not what you meant to write

      Below is the screenshot of the blog code referring to the same line

      Code

      I am pretty sure you are not referring to the path here. That is the path of my machine. If there is anything else, I would correct

      • Abhishek says:

        i am referring to path in my machine, and it’s working correctly. Thanks for great in depth information. It’s only minor typo error. That already you have rectified above.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: