Retrieve Plug-in/Custom Workflow Activity DLL from Database

I ran into an issue today that the client can’t find the plug-in project that some independent consultants built a year ago.  Since they can’t get in touch with the consultants who wrote the plug-in, they have two options to get retrieve the code.  One option was rewrite the plug-in from scratch and the other option was to retrieve the plug-in from the CRM database since the plug-ins are registered in the database.

To rewrite the plug-in code would require a lot of effort, so they chose the second option.  To retrieve the custom plug-in from CRM database is easy.  Here are the steps to do that.

  1. Retrieve the Plug-in encoded string from the Organization MSCRM database.  The plug-ins are stored in the Plugin PluginAssemblyBase table.

     SELECT Content FROM PluginAssemblyBase
    WHERE PluginAssemblyId = '[Plugin Guid]'
    
  2. Copy and paste the Content string into a text file.

  3. Write a simple C# command line application to convert the plug-in string to DLL. 

     string inputFileName = "Plugin.txt";
    string outputFileName = "Plugin.dll";
    
    FileStream fileStream = File.Open(fileName, FileMode.Open);
    byte[] buffer = new byte[fileStream.Length];
    fileStream.Read(buffer, 0, buffer.Length);
    fileStream.Close();
    ASCIIEncoding encoding = new ASCIIEncoding( );
    this.buffer = encoding.GetString(buffer);
    
    FileStream fileStream = new FileStream(outputFileName, FileMode.Create);
    byte[] buffer = Convert.FromBase64String(this.buffer);
    fileStream.Write(buffer, 0, buffer.Length);
    fileStream.Close();
    
  4. After you retrieved the DLL from the database, then you may use .Net Reflector to extract the code from this plug-in.

That’s it! Just in case you run into the same situation that you have to retrieve your plug-in or custom workflow activity from MSCRM database, you can follow the steps above.  I hope this helps!