Why does CREATE ASSEMBLY fail with the error 'Unable to resolve token'?

0

I'm working with some SQL 2005 CLR code written in C#. We have recently altered a few of the functions to allow NULL parameters. We did this by changing parameters from 'double' to 'SqlDecimal' types. We successfully tested the changes in development and have moved to deploy the updates to the production server. We're using a SQL script to drop the existing code from the server and to then create the updated assembly and related objects. The SQL script which we used in development and testing has been deployed to the production server with no changes, but when we run it there we see an error:

Creating CLR assemblies
Msg 6218, Level 16, State 2, Line 2
CREATE ASSEMBLY for assembly 'Company.Db.CLRStoredProcedures' failed because assembly 'Company.Db.CLRStoredProcedures' failed verification. Check if the referenced assemblies are up-to-date and trusted (for external_access or unsafe) to execute in the database. CLR Verifier error messages if any will follow this message
[ : StoredProcedures::clrproc_OSGBtoWGS84][mdToken=0x600002e][offset 0x0000002C] Unable to resolve token.

I have Googled this error but can't seem to find anything sensible. In the changes we made there were no new or changed references and so I don't believe it's related to anything missing from the server, the code has previously worked there for quite a while. Does anyone know what is going on here?

sql-server-2005
sqlclr
clrstoredprocedure
asked on Stack Overflow Jul 30, 2010 by Elliveny

2 Answers

0

This isn't an answer to my own question, but it does give a clue what is going on and - very usefully - is a work around and so it might help someone in a similar situation.

The deployment script I refered to above was created by scripting the development database objects. Instead of doing that I discovered that if I:

  1. Start the SQL Profiler capturing the SQL statements being executed against my development db.
  2. Use the 'Deploy' function in Visual Studio to deploy the project to my SQL Server.
  3. Select the SQL Profiler File -> Export -> Extract SQL Server Events -> Extract Transact-SQL Events menu option to save the captured depolyment SQL to a file.
  4. Clean up the file a little using a text editor.
  5. Run the captured SQL on the production server.

Then it works :-)

So there must be some difference between the script that I create AFTER the objects have been deployed when compared to the deployment script which Visual Studio generates.

This doesn't explain the 'Unable to resolve token' issue as such, but it does perhaps give us a clue what is happening and, more importantly, a way around it.

That said, I'm still keen to understand what the 'Unable to resolve token' error means...

answered on Stack Overflow Jul 30, 2010 by Elliveny
0

I was running into a similarly inexplicable error about "Unable to resolve token" for a method that was present in my assembly. Only by changing the target platform from .NET 4.5 to .NET 4.0 was I able to get it to work. Some long explanation about why that might have worked is in this msdn blog.

answered on Stack Overflow Jun 11, 2015 by Anssssss

User contributions licensed under CC BY-SA 3.0