1

How do I add c# class library/ class dll in SQL CLR project ?.

I add the class library dll/ class dll but got error in SQL server 2012 during assembly creation

Assembly references assembly 'system.runtime.serialization, version=4.0.0.0, culture=neutral, which is not present in the current database. SQL Server attempted to locate and automatically load the referenced assembly from the same location where referring assembly came from, but that operation has failed (reason: 2(The system cannot find the file specified.)). Please load the referenced assembly into the current database and retry your request.

1 Answer 1

1

You have to register unsupported libraries before you can use them.

-- You will have to use the Runtime Serialization from .NET v3

ALTER DATABASE [<<Database Name>>] SET TRUSTWORTHY ON;
CREATE ASSEMBLY AnyName_You_Want
FROM 
--'C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Runtime.Serialization.dll'
'C:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation\System.Runtime.Serialization.dll'
WITH PERMISSION_SET = UNSAFE;

Excerpt:

Unsupported libraries can still be called from your managed stored procedures, triggers, user-defined functions, user-defined types, and user-defined aggregates. The unsupported library must first be registered in the SQL Server database, using the CREATE ASSEMBLY statement, before it can be used in your code. Any unsupported library that is registered and run on the server should be reviewed and tested for security and reliability.

For example, the System.DirectoryServices namespace is not supported. You must register the System.DirectoryServices.dll assembly with UNSAFE permissions before you can call it from your code. The UNSAFE permission is necessary because classes in the System.DirectoryServices namespace do not meet the requirements for SAFE or EXTERNAL_ACCESS. For more information, see CLR Integration Programming Model Restrictions and CLR Integration Code Access Security.

CLR integration in SQL Server only supports a subset of .NET Framework Libraries. The libraries/namespaces supported by CLR integration in SQL Server are:

  • CustomMarshalers
  • Microsoft.VisualBasic
  • Microsoft.VisualC
  • mscorlib
  • System
  • System.Configuration
  • System.Data
  • System.Data.OracleClient
  • System.Data.SqlXml
  • System.Deployment
  • System.Security
  • System.Transactions
  • System.Web.Services
  • System.Xml
  • System.Core.dll
  • System.Xml.Linq.dll
Sign up to request clarification or add additional context in comments.

2 Comments

I did that but still getting this message and not able to create assembly using system.web. Assembly 'System.Web' references assembly 'system.web, version=4.0.0.0, culture=neutral, publickeytoken=b03f5f7f11d50a3a.', which is not present in the current database. SQL Server attempted to locate and automatically load the referenced assembly from the same location where referring assembly came from, but that operation has failed (reason: version, culture or public key mismatch). Please load the referenced assembly into the current database and retry your request.
Did the command for creating the 'System.Runtime.Serialization assembly worked? And what the command you used for System.Web?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.