Question

I have a bunch of SQL CLR assemblies on SQL 2008 R2. These assemblies were targeted with .Net Framework 3.5. Given SQL 2008 supported 2.0 .NET framework version, I am assuming SQL loaded the safe assemblies from System GAC and expected unsafe assemblies to be installed in SQL. My references to these unsafe assemblies are .NET version 2.0. Now when I restored this database to SQL 2012 my CLR code is failing with "reference to unsafe assembly version 4.0 not found". I did not understand this error. The 2.0 version of the unsafe system assembly exists in the DB mdf file itself. Why is SQL looking for 4.0? I think I am missing what "SQL supports x version of .NET framework" means.

Was it helpful?

Solution

I was able to get to the root cause of the issue I was facing. SQL 2012 supports .NET framework version 4.0 for SQLCLR and hence loads all framework assemblies from 4.0 framework. Hence I needed to upgrade all my assemblies to use 4.0 framework assemblies. http://blogs.msdn.com/b/dohollan/archive/2012/04/20/sql-server-2012-sqlclr-net-framework-version.aspx?CommentPosted=true#commentmessage

But things didnt work for me even after that. It turns out in 4.0, .NET changed some framework assemblies like System.ServiceModel from Pure .Net assemblies to mixed mode assemblies. Such assemblies cannot be loaded by SQL CLR. So all user defined assemblies depending on mixed mode assemblies pre 2012 dont work anymore on 2012 :( Most badly hit are previously working SQL and WCF integrations completely breaking in 2012 sicne WCF depends on ServiceModel. More here http://blogs.msdn.com/b/psssql/archive/2013/02/23/unable-to-register-net-framework-assembly-not-in-the-supported-list.aspx

We ended up writing a simple Webservice wrapper over our WCF operation and writing a Webservice client in SQLCLR.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top