2

I'm trying to create a CLR function in SQLServer that calls a web service. When I create the first assembly, the AssemblyVersion in AssemblyInfo.cs is 1.0.*. I'll run sgen to create the accompanying XMLSerializers assembly, and I don't see any problems there.

>"C:\Program Files\Microsoft SDKs\Windows\v7.0\Bin\sgen.exe" /force /assembly:Ra
elen.DemoCLRFunction.dll
Microsoft (R) Xml Serialization support utility
[Microsoft (R) .NET Framework, Version 2.0.50727.3038]
Copyright (C) Microsoft Corporation. All rights reserved.
Serialization Assembly Name: Raelen.DemoCLRFunction.XmlSerializers, Version=1.0.
3868.13304, Culture=neutral, PublicKeyToken=null.
Generated serialization assembly for assembly C:\dev\freight-workspace\Raelen.De
moCLRFunction\Raelen.DemoCLRFunction\bin\Debug\Raelen.DemoCLRFunction.dll --> 'C
:\dev\freight-workspace\Raelen.DemoCLRFunction\Raelen.DemoCLRFunction\bin\Debug\
Raelen.DemoCLRFunction.XmlSerializers.dll'.

In SQLServer, the first assembly loads fine, but I'm getting the following error trying to load the XMLSerializers assembly:

Msg 10300, Level 16, State 2, Line 7
Assembly 'Raelen.DemoCLRFunction.XmlSerializers' references assembly 
'raelen.democlrfunction, version=0.0.0.0, culture=neutral, publickeytoken=null.',
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.

I can't figure out why it's trying to reference version 0.0.0.0. Is that indeed the cause of the error, and if so, why is the XMLSerializers assembly referencing the wrong version number?

bhnat
  • 97
  • 2
  • 11
  • When you say 'first assembly', do you mean `raelen.democlrfunction`? – Rabid Aug 04 '10 at 13:19
  • And are either assemblies signed using a strong named key? – Rabid Aug 04 '10 at 14:34
  • Yeah, by first assembly I'm referring to raelen.democlrfunction. That's the dll that I used sgen to create Raelen.DemoCLRFunction.XmlSerializers.dll. Neither are signed using a strong named key. – bhnat Aug 04 '10 at 16:14
  • I tried signing it, but I'm still getting the same message. The version number in this message match the version number of Raelen.DemoCLRFunction.dll when I look at the properties for that assembly in management studio. (message to follow) – bhnat Aug 04 '10 at 17:30
  • Msg 10300, Level 16, State 2, Line 7 Assembly 'Raelen.DemoCLRFunction.XmlSerializers' references assembly 'raelen.democlrfunction, version=1.0.3868.22118, culture=neutral, publickeytoken=6d8315b39b3c11fb.', 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. – bhnat Aug 04 '10 at 17:30

2 Answers2

3

If you are running x64 SQL server check if your project build target to the Any CPU platform. I have encountered the same problem and made the following table;

A1 the referenced assembly; A2 references.

A1 \ A2   x86   x64   Any CPU
x86        X     V     X
x64        V     V     V
Any CPU    V     V     V
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Shmalex
  • 171
  • 2
  • 11
3

I had this problem and I eventually worked it out. I was referencing an x86 assembly on a 64 bit server. I rebuilt the referenced assembly as Any CPU, installed in on the server, re-added the reference to the project, rebuilt my project as Any CPU, and then SQL Server could resolve the reference and install the assembly.

A message along the lines of "You're referencing an assembly that's built for the wrong platform" would have been rather useful :)

TarkaDaal
  • 18,798
  • 7
  • 34
  • 51