One of the first hurdles new BizTalk developers face is the strict requirement for Strong-Named Assemblies. If you try to build a BizTalk solution that references an unsigned library, Visual Studio will block you with this error:
“Assembly generation failed — Referenced assembly ‘…’ does not have a strong name”
Indeed, a friend of mine who is taking the first steps in BizTalk called me exactly to ask me how to solve this exact same error.
📝 One-Minute Brief
Encountering the error “Assembly generation failed — Referenced assembly does not have a strong name” is common when using external libraries in BizTalk orchestrations. Because BizTalk requires all assemblies in the Global Assembly Cache (GAC), referenced projects must be signed. This post details how to generate an .snk file and sign your projects. More importantly, it provides a clever “resign” batch script using ildasm and ilasm to apply a strong name to third-party or open-source DLLs even if you don’t have the original source code.
Cause
This problem occurs when a custom type from an unsigned referenced assembly is used within the orchestration.
Solution
Apply a strong name to the referenced assembly. If it is a custom assembly that you can recompile, use the strong name tool to create a .snk (key) file and then reference that key file in the assembly properties for the project. For more information about strong-naming an assembly.
To configure a strong name assembly key file
- On the Start menu, point to All Programs, point to Microsoft Visual Studio 2010, point to Visual Studio Tools, and then click Visual Studio Command Prompt (2010).
- At the command prompt, from the folder where you want to store the key file, type the following command, and then press ENTER:
sn /k file_name .snk
Example: sn /k ErrorHandling.snk
A confirmation message, Key pair written to <file_name>.snk, displays on the command line. - In Visual Studio Solution Explorer, right-click the project and then click Properties.
- Click the Signing tab and choose to Browse in the Choose a strong name key file drop-down box.
- Browse to the key file and click it. Click Open, and then close the project properties.
- Repeat steps 3 through 6 for each project in the solution that you want to deploy using this strong name assembly key file.
For those assemblies that are open source, you can simply recompile everything with a strong name. But for those that come already compiled by a 3rd party, you need to disassemble and reassemble again with a strong name.
To make everything simple, I usually use this batch:
call "%VS80COMNTOOLS%vsvars32.bat"
ildasm /all /out=%1.il %1.dll
ilasm /dll /key=....actvalue.snk %1.il
pause
You can invoke it by passing the assembly file name as a unique argument, like:
resign.bat somelibrary
This allows you to resign every assembly without needing source code.
Hope you find this helpful! If you liked the content or found it useful and would like to support me in writing more, consider buying (or helping to buy) a Star Wars Lego set for my son.
nice tip…very helpful information 🙂