Click here to Skip to main content
15,881,424 members
Articles / Database Development / SQL Server

Struggling with System.IO.Packaging when Creating a CLR Procedure

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
19 Oct 2012CPOL1 min read 14.8K   2   5
System.IO.Packaging namespace in WindowsBase may cause problems when trying to create a CLR procedure.

The Problem

I started to create a small CLR procedure into SQL Server 2012 Express Edition which would utilize System.IO.Packaging namespace. In order to use this namespace, WindowsBase must be referenced. After adding the required reference, everything seemed to be fine when compiling the assembly.

Now when trying to register the newly created assembly to SQL Server, I got an error message stating:

Msg 10301, Level 16, State 1, Line 1

Assembly 'Test' references assembly 'system.xaml, version=4.0.0.0, culture=neutral, 
publickeytoken=b77a5c561934e089.', 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. 

Now, this was surprising, but understandable. So I added System.Xaml to the project references; After all, I had no use for the visual interface in my project.

After compiling the project, I re-tried to register the assembly. This time, I received a different error:

Warning: The Microsoft .NET Framework assembly 'system.xaml, version=4.0.0.0, culture=neutral, 
publickeytoken=b77a5c561934e089.' you are registering is not fully tested in the SQL Server hosted 
environment and is not supported. In the future, if you upgrade or service this assembly or the 
.NET Framework, your CLR integration routine may stop working. Please refer SQL Server Books Online 
for more details.

Msg 6218, Level 16, State 2, Line 1

CREATE ASSEMBLY for assembly 'Test' failed because assembly 'System.Xaml' 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
[ : System.Windows.Markup.ValueSerializer::CanConvertToString][mdToken=0x6000002][offset 0x00000000] Code size is zero.
[ : System.Windows.Markup.ValueSerializer::CanConvertFromString][mdToken=0x6000003][offset 0x00000000] Code size is zero.
[ : System.Windows.Markup.ValueSerializer::ConvertToString][mdToken=0x6000004][offset 0x00000000] Code size is zero.
[ : System.Windows.Markup.ValueSerializer::ConvertFromString][mdToken=0x6000005][offset 0x00000000] Code size is zero.
[ : System.Windows.Markup.ValueSerializer::TypeReferences][mdToken=0x6000006][offset 0x00000000] Code size is zero.
[ : System.Windows.Markup.ValueSerializer::.ctor][mdToken=0x6000001][offset 0x00000000] Code size is zero.
[ : System.Windows.Markup.ValueSerializer::.cctor][mdToken=0x600000d][offset 0x00000000] Code size is zero.
[ : System.Windows.Markup.ValueSerializer::GetSerializerFor][mdToken=0x6000007][offset 0x00000000] Code size is zero.
[ : System.Windows.Markup.ValueSerializer::GetSerializerFor][mdToken=0x6000008][offset 0x00000000] Code size is zero.
[ : System.Windows.Markup.ValueSerializer::GetSerializerFor][mdToken=0x6000009][offset 0x00000000] Code size is zero.
[ : System.Windows.Markup.ValueSerializer::GetSerializerFor][mdToken=0x600000a][offset 0x00000000] Code size is zero.
[ : System.Windows.Markup.ValueSerializer::GetConvertToException][mdToken=0x600000b][offset 0x00000000] Code size is zero.
[ : System.Windows.Markup.ValueSerializer::GetConvertFromException][mdToken=0x600000c][offset 0x00000000] Code size is zero.
[ : System.Windows.Markup.MemberDefinition::.ctor][mdToken=0x6000010][offset 0x00000000] Code size is zero.
[ : System.Windows.Markup.PropertyDefinition::get_Name][mdToken=0x6000011][offset 0x00000000] Code size is... 

So after all, I wasn't able to register the assembly to SQL Server at all.

What About Other Versions

Well, I tried the same with SQL Server 2008 R2 with no success. The error message was different and I needed to reference accessibility assembly which wasn't verified against SQL Server.

I also tried this with SQL Server 2005 and it was quite a big surprise that SQL Server 2005 seems to accept my assembly.

Conclusions

So it looks like newer versions of SQL Server don't accept WindowsBase reference. While I do understand this since lots of the classes in this assembly are used in creating a user interface, I don't quite understand why some basic functionality such as System.IO.Packaging is included in the same assembly.

Another potential problem is the System.Security.RightsManagement namespace which is included in WindowsBase.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
Europe Europe
Biography provided

Comments and Discussions

 
QuestionLocation of namespaces Pin
Maciej Skierski11-Oct-12 17:54
Maciej Skierski11-Oct-12 17:54 
QuestionFailure to load is apparently be design Pin
Maciej Skierski11-Oct-12 12:40
Maciej Skierski11-Oct-12 12:40 
AnswerRe: Failure to load is apparently be design Pin
Wendelius11-Oct-12 17:39
mentorWendelius11-Oct-12 17:39 
QuestionSurprised! Pin
Mehdi Gholam6-Oct-12 19:51
Mehdi Gholam6-Oct-12 19:51 
AnswerRe: Surprised! Pin
Wendelius7-Oct-12 2:00
mentorWendelius7-Oct-12 2:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.