Tuesday, May 20th, 2008

But It Worked On Dev!

By Joel Potischman

If you use SQL Server’s CLR integration to write .NET stored procedures, you may one day deploy your working proc to another server, only to see it blow up with an error like the following:

Msg 6522, Level 16, State 1, Procedure prcMyCLRProc, Line 0
A .NET Framework error occurred during execution of user-defined routine or aggregate "prcMyCLRProc":
System.TypeInitializationException:
The type initializer for 'System.Data.SqlClient.MetaType' threw an exception. --->
System.TypeLoadException:
Could not load type 'System.DateTimeOffset' from assembly 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
System.TypeLoadException:
at System.Data.SqlClient.MetaType..cctor()
System.TypeInitializationException:
at StoredProcedures.prcMyCLRProc(String query)

You check permissions. You confirm CLR integration is enabled and configured properly. You even backup the database on the working box and restore it on the offending one, but no dice. The culprit? Both your servers have .NET Framework 2.0 installed, but only the working one has Service Pack 1, and you’re using one of the new types or methods it introduced.

In our case, SP1 seems to have been corrupted by an extra-large batch of Windows updates, causing System.DateTimeOffset to cease to exist. Not that we’re bitter.

Leave a Comment