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.
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]'
Copy and paste the Content string into a text file.
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();
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!
Comments
- Anonymous
July 20, 2011
This approach won't work if the size of plug-in is huge. Datatype of "Content" is text, so if the size of the string is larger than (2^31 - 1), then string will be truncated. For smaller plug-ins this approach will work fine. For decoding purpose some one can use following URL rather writing the Code www.opinionatedgeek.com/.../base64decode