Monday, 23 June 2025

How to convert plugin assembly (dll) into base 64 bytes using console application (C#).

 using System;

using System.IO;

using System.ServiceModel.Description;

using Microsoft.Rest;

using Microsoft.Xrm.Sdk;

using Microsoft.Xrm.Sdk.Query;

using Microsoft.Xrm.Tooling.Connector;

namespace ConsoleApp2

{

    internal class Program

    {

        static void Main(string[] args)

        {

            string connectionString = @"AuthType=OAuth;

                Username=*****************;

                Password=*****************;

                Url=https://*****************.crm8.dynamics.com;

                AppId=*****************;

                 LoginPrompt=Auto";

            Console.WriteLine("Connecting to Dynamics 365..");


            using (CrmServiceClient serviceClient = new CrmServiceClient(connectionString))

            {

                if (!serviceClient.IsReady)

                {

                    Console.WriteLine("Failed to connect: " + serviceClient.LastCrmError);

                    return;

                }

                IOrganizationService service = (IOrganizationService)serviceClient.OrganizationWebProxyClient ?? (IOrganizationService)serviceClient.OrganizationServiceProxy;

                Console.WriteLine("connected to Dynamics Crm ");

                QueryExpression query = new QueryExpression("pluginassembly")

                {

                    ColumnSet = new ColumnSet("name", "content")

                };

                EntityCollection results = service.RetrieveMultiple(query);


                foreach (Entity plugin in results.Entities)

                {

                    string name = plugin.GetAttributeValue<string>("name");

                    string content = plugin.GetAttributeValue<string>("content");

                    if (string.IsNullOrEmpty(content))

                    {

                        Console.WriteLine($"Assembly '{name}' has no content.");

                        continue;

                    }

                    byte[] dllBytes = Convert.FromBase64String(content);

                    string fileName = $"{name}.dll";

                    File.WriteAllBytes(fileName, dllBytes);

                    Console.WriteLine($"Downloaded: {fileName}");

                }

                Console.WriteLine("All assemblies downloaded successfully.");

            }

        }

    }

}

Notes -Replace credentials as per your  CRM environment.

Download a plugin assembly (DLL) from Dynamics 365 CRM.

 CRM does not allow direct download of the DLL file from the UI. However, there are several ways to retrieve the plugin DLL from the CRM environment. we achieve this requirement using XrmToolBox.  

  • Open XrmToolBox.
  • Install and open Assembly Recovery Tool.
  • Connect to your Dynamics CRM instance.
  • It will list all deployed assemblies.
  • Select the assembly and click Download.
Connect D365 Environment 



Configuration ==> Tool Library ==>Search "Assembly Recovery Tool" and install.


Tool==>Assembly Recovery Tool.

Double click on "Assembly Recovery Tool" all Assemble file will be appear. 


Select "Assemble "and  click on "Export to Disk "


Note :- All Assemble file store under "pluginassembly" entity.







How to convert plugin assembly (dll) into base 64 bytes using console application (C#).

 using System; using System.IO; using System.ServiceModel.Description; using Microsoft.Rest; using Microsoft.Xrm.Sdk; using Microsoft.Xrm.Sd...