I'm creating a CLR assembly for SQL Server 2008, which only supports .NET 2.0 assemblies. Furthermore, SQL Server also requires a strong name key with each assembly you want to register.
The assembly I am trying to create references the .NET 2.0 version of json.net (https://json.codeplex.com/). However, my project is unable to generate an SNK file because Newtonsoft.Json.dll itself is unsigned. (At least that's the error I am getting when I try to build my project and sign it.)
I got around this using the trick described here: http://buffered.io/posts/net-fu-signing-an-unsigned-assembly-without-delay-signing/
However, when reassembling Newtonsoft.Json.dll with my project's SNK, it must be generating the DLL with a target framework higher than .NET 2.0. I know this because I'm getting the following error in SQL Server:
CREATE ASSEMBLY for assembly 'Newtonsoft.Json' failed because the assembly is built for an unsupported version of the Common Language Runtime.
Does anyone know how to make ilasm.exe generate the assembly in target framework .NET 2.0? Or perhaps I'm approaching the problem wrong altogether - if there is a better solution to using Newtonsoft.Json in a CLR assembly in 2008, I would love to know. Thank you!
Make sure you run ilasm
from the right directory. Each version of .NET Framework has its tools in a different directory.
If you're using one from the PATH, you can type where ilasm
at a prompt to find out what version is being found.
I suspect this advice from the blog you linked is leading you astray
We need to open a command prompt which has the .NET framework binaries in the PATH environment variable. The easiest way to do this is to open a Visual Studio command prompt (which is usually under the “Visual Studio Tools” subfolder of “Visual Studio 20XX” in your programs menu).
No mention of version, or the fact that the .NET Framework runtime has installed the tools for more versions than you have Visual Studio installs.
For example, on my system I have ilasm in
C:\Windows\Microsoft.NET\Framework\v2.0.50727
and also
C:\Windows\Microsoft.NET\Framework64\v4.0.30319
(and others)
Running the v4 one, which is what I get from "Visual Studio 2013 x64 Native Tools Command Prompt" will create a .NET 4-compatible assembly, running the v2 one creates a .NET 2-compatible assembly.