1

I have a c# class library which is called by SQL stored procedure (CLR). The class library performs some calculations and returns a table back to SQL.

I have added assemblies to SQL before, however when i was adding the class library. I get the following error

'MyExporter' references assembly 'microsoft.csharp, 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: 2(The system cannot find the file specified.)). Please load the referenced assembly into the current database and retry your request.

I did a bit of research and found out that SQL does not support Microsoft.charp library. I need to remove any references to microsoft.charp in my class library. I have now removed microsoft.charp from the reference section in my class library and I was using dynamic keyword. Which i have now changed to object.

Currently, I get a error in my C# library as follows

Severity    Code    Description Project File    Line    Suppression State
Error   CS0656  Missing compiler required member 'Microsoft.CSharp.RuntimeBinder.Binder.Convert'    Optimal.SynTI.Exporter  D:\Workspace\SynTQV5 Projects\MyExporter\DataCollater.cs    731 Active

I understand this one line of code is not going to give you any insight, but this is where the c# error lies

// Select the first item as the sheet ID.
// Get the Sheet Id from the array.
iNVls.SheetID = item.FinalData[0].Value;

I also am using Linq in my class library, do i have to remove any references to linq as well?

Thank you

Abe
  • 1,879
  • 2
  • 24
  • 39
  • Do you get the error when compiling, or when you call the SQLCLR procedure? – stuartd Dec 19 '16 at 14:53
  • Possible duplicate of [Sql Server CLR load assembly failed](http://stackoverflow.com/questions/6581813/sql-server-clr-load-assembly-failed) – JuanR Dec 19 '16 at 14:57
  • when i compile my c# class library – Abe Dec 19 '16 at 15:01
  • .. in which case, it sounds like you have something left over which wants to reference `Microsoft.CSharp` – stuartd Dec 19 '16 at 15:03
  • Juan - I have gone through that link you specified before. I understand Microsoft.Charp cannot be installed into SQL and I have already installed system.web successfully. Thank you. – Abe Dec 19 '16 at 15:03
  • Stuartd - Can it be to do with LINQ? I have removed all dynamic keywords. No sure what is lingering. – Abe Dec 19 '16 at 15:04
  • Do you still get that same error, "CS0656 Missing compiler required member"? Dynamic Assembly loading is not allowed in SQLCLR, even for UNSAFE assemblies. – Solomon Rutzky Dec 19 '16 at 15:07
  • Also, I assume you are using at least SQL Server 2012, or newer? If so, then LINQ should be available if you are using LINQ to Objects or LINQ to XML. LINQ to SQL is not supported in SQLCLR since the `System.Data.Linq` library is not supported. – Solomon Rutzky Dec 19 '16 at 15:16
  • srutzky - I am using SQL Server 2014. I am only using linq in my C# library. Will this be an issue? – Abe Dec 19 '16 at 15:43
  • @Abe It depends on what you are doing with LINQ. As I mentioned LINQ to Objects and XML is supported, LINQ to SQL is not. If you aren't sure what is or is not supported, then check the [Supported .NET Framework Libraries](https://msdn.microsoft.com/en-us/library/ms403279.aspx) page, and remember that Namespace does not always equal Assembly. If your references are all supported, then please update the question with the _exact_ current error. P.S. You need to prefix a users name with `@` in order for that person to get the notification. – Solomon Rutzky Dec 19 '16 at 15:49

0 Answers0