locked
Sql Server 2012 Error when creating assembly from System.IdentityModel.dll' RRS feed

  • Question

  • Hello

    We are trying to call a WCF from a CLR procedure in Sql Server 2012. We implemented this in Sql Server 2005 and works fine, but now we want to upgrade it to 2012. The database has trustworthy set "on".

    When we run this command:

         CREATE ASSEMBLY 

         [System.IdentityModel] from 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.IdentityModel.dll'

         with permission_set = UNSAFE

    we receive this error:

    CREATE ASSEMBLY for assembly 'System.IdentityModel' failed because assembly 'System.IdentityModel' 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.IdentityModel.SafeKeyHandle::SafeCryptImportKey][mdToken=0x600014c][offset 0x00000033] Unmanaged pointers are not a verifiable type.

    [ : System.IdentityModel.SecurityBufferDescriptor::.ctor][mdToken=0x600024b][offset 0x00000017][found Native Int][expected unmanaged pointer] Unexpected type on the stack.

    [ : System.IdentityModel.SafeDeleteContext::InitializeSecurityContext][mdToken=0x6000254][offset 0x0000033F][found Native Int][expected address of Native Int] Unexpected type on the stack.

    [ : System.IdentityModel.SafeDeleteContext::InitializeSecurityContext][mdToken=0x6000254][offset 0x000000A7][found address of value 'System.IdentityModel.SecurityBufferStruct'][expected address of Native Int] Unexpected type on the stack.

    [ : System.IdentityModel.SafeDeleteContext::InitializeSecurityContext][mdToken=0x6000254][offset 0x000000B2][found address of Native Int] Expected numeric type on the stack.

    [ : System.IdentityModel.SafeDeleteContext::InitializeSecurityContext][mdToken=0x6000254][offset 0x00000338][found Native Int][expected address of Native Int] Unexpected type on the stack.

    [ : System.IdentityModel.SafeDeleteContext::InitializeSecurityContext][mdToken=0x6000254][offset 0x000001CD][found address of value 'System.IdentityModel.SecurityBufferStruct'][expected address of Native Int] Unexpected type on the stack.

    [ : System.IdentityModel.SafeDeleteContext::InitializeSecurityContext][mdToken=0x6000254][offset 0x000001D2][found address of Native Int] Expected numeric type on the stack.

    [ : System.IdentityModel.SafeDeleteContext::InitializeSecurityContext][mdToken=0x6000254][offset 0x000001C1][found Native Int][expected address of Native Int] Unexpected type on the stack.

    [ : System.IdentityMode...

    We tried to target a previous version of .Net framework  but without success (I don't know hot to setup Sql Management Studio to use a different .Net Framework).

    Do you have any idea what to try?

    Thank you very much

    Friday, May 25, 2012 2:19 PM

Answers

  • Based on my understanding that you are trying to register a 64-bit, system ..NET 4.0 library on a 64-bit installation of SQL Server 2012, I wouldn’t think this should fail verification. The error messages you are getting (for System.IdentityModel.dll) look similar to messages you’d get for invalid IL instructions (.NET intermediate language).  Only time I’ve seen this is when you have the wrong bitness or wrong version of .NET system DLL or you’ve dropped a bit when trying to catalog an assembly from a bitstream that’s been corrupted.
     
    Either 64-bit 4.0 System.IdentityModel.dll really is doing strange with the IL or the .NET IL verifier in SQL Server 2012 can’t handle it. They are using unmanaged void*, but not sure that this along should fail verification. And the library is calling native methods, but that shouldn’t necessarily cause verification failure either AFAIK.
     
    So I’d suggest reporting it as a bug on Connect to see if you can get an answer as to why these specific IL constructs (in this well-known system assembly) fail SQL Server’s verification routines.
     
    Cheers,
    Bob
    • Marked as answer by Rosimo Tuesday, May 29, 2012 9:18 AM
    Tuesday, May 29, 2012 7:19 AM

All replies

  • Hi Rosimo,

    As far as I know, we cannot use assemblies which created by CLR 2.0 in CLR 4.0 environment, because in CLR4.0, lots of resource have been changed. A workround is recreated that assembly in CLR 4.0 environment.


    Best Regards,
    Iric
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, May 28, 2012 8:28 AM
  • Hello Iric

    Thank you for your answer. This is exactly what I am trying to do, I want to recreate the assembly in the CLR 4.0 environment. I started a new project but in order to call the WCF, I need to reference a number of dlls from the .Net Framework.

    I try to run this command on the sample database from 2012 - Adventure Works - but I get the same error.

    This is how it happens, step by step:

    When I publish my ssdt project, I get the following error message:

    (47,1): SQL72014: .Net SqlClient Data Provider: Msg 6503, Level 16, State 12, Line 1 Assembly 'system.servicemodel, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089.' was not found in the SQL catalog.

    That's why I go to Management Studio and try to manually load the servicemodel assembly:

    CREATE ASSEMBLY
    [System.ServiceModel]
    from'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.ServiceModel.dll'with
    permission_set = UNSAFE

    I get the following error message:

    Warning: The Microsoft .NET Framework assembly 'system.servicemodel, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089, processorarchitecture=msil.' 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.

    Warning: The Microsoft .NET Framework assembly 'system.xaml, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089,processorarchitecture=msil.' 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.

    Warning: The Microsoft .NET Framework assembly 'system.runtime.serialization, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089, processorarchitecture=msil.' 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.

    Warning: The Microsoft .NET Framework assembly 'smdiagnostics, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089, processorarchitecture=msil.' 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.

    Warning: The Microsoft .NET Framework assembly 'system.identitymodel, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089, processorarchitecture=msil.' 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 'System.ServiceModel' failed because assembly 'System.IdentityModel' 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.IdentityModel.SafeKeyHandle::SafeCryptImportKey][mdToken=0x600014c][offset 0x00000033] Unmanaged pointers are not a verifiable type.

    [ :

    System.IdentityModel.SecurityBufferDescriptor::.ctor][mdToken=0x600024b][offset 0x00000017][found Native Int][expected unmanaged pointer] Unexpected type on the stack.

    [ :

    System.IdentityModel.SafeDeleteContext::InitializeSecurityContext][mdToken=0x6000254][offset 0x0000033F][found Native Int][expected address of NativeInt] Unexpected type on the stack.

    [ :

    System.IdentityModel.SafeDeleteContext::InitializeSecurityContext][mdToken=0x6000254][offset 0x000000A7][found address of value'System.IdentityModel.SecurityBufferStruct'][expected address of Native Int] Unexpected type on the stack.

    [ :

    System.IdentityModel.SafeDeleteContext::InitializeSecurityContext][mdToken=0x6000254][offset 0x000000B2][found address of Native Int] Expected numeric type on the stack.

    [ :

    System.IdentityModel.SafeDeleteContext::InitializeSecurityContext][mdToken=0x6000254][offset 0x00000338][found Native Int][expected address of NativeInt] Unexpected type on the stack.

    [ :

    System.IdentityModel.SafeDeleteContext::InitializeSecurityContext][mdToken=0x6000254][offset 0x000001CD][found address of value'System.IdentityModel.SecurityBufferStruct'][expected address of Native Int]Unexpected type on the stack.

    [ :

    System.IdentityModel.SafeDeleteContext::InitializeSecurityContext][mdToken=0x6000254][offset 0x000001D2][found address of Native Int] Expected numeric type on the stack.

    [ :

    System.IdentityModel.SafeDeleteContext::InitializeSecurityContext][mdToken=0x6000254][offset 0x000001C1][found Native Int][expected address of NativeInt] Unexpected type on the stack.

    [ : System.IdentityModel...

    ----------------------------------------------------------------------------

    So, System.ServiceModel loading failed because of System.IdentityModel.dll.

    I also tried to load System.IdentityModel alone:

    CREATE ASSEMBLY [System.IdentityModel] from
    
    'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.IdentityModel.dll'
    
    with permission_set = UNSAFE

    but with no success, getting same error message as above.


    Thank you

    Monday, May 28, 2012 9:40 AM
  • I forgot to mention that my installation is on 64 bits.

    I also observed that in the Refferenced Assembly folder (c:\Program Files\Reference Assemblies\Microsoft\Framework) there is no folder for 4.0 version. (There are folders only for 3.0 and 3.5 framework).

    I will try to repeat the process on a 32 bits environment and see what is happening.

     

    Monday, May 28, 2012 9:45 AM
  • Based on my understanding that you are trying to register a 64-bit, system ..NET 4.0 library on a 64-bit installation of SQL Server 2012, I wouldn’t think this should fail verification. The error messages you are getting (for System.IdentityModel.dll) look similar to messages you’d get for invalid IL instructions (.NET intermediate language).  Only time I’ve seen this is when you have the wrong bitness or wrong version of .NET system DLL or you’ve dropped a bit when trying to catalog an assembly from a bitstream that’s been corrupted.
     
    Either 64-bit 4.0 System.IdentityModel.dll really is doing strange with the IL or the .NET IL verifier in SQL Server 2012 can’t handle it. They are using unmanaged void*, but not sure that this along should fail verification. And the library is calling native methods, but that shouldn’t necessarily cause verification failure either AFAIK.
     
    So I’d suggest reporting it as a bug on Connect to see if you can get an answer as to why these specific IL constructs (in this well-known system assembly) fail SQL Server’s verification routines.
     
    Cheers,
    Bob
    • Marked as answer by Rosimo Tuesday, May 29, 2012 9:18 AM
    Tuesday, May 29, 2012 7:19 AM
  • Thank you for your help.

    Indeed it seems like a bug, we reported it on Microsoft Connect, if anyone has the same problem, you can vote for the bug here:

    https://connect.microsoft.com/SQLServer/feedback/details/744584/unable-to-load-system-identitymodel-dll-assembly-into-sql-server-2012#details

    We also tried to implement it on the 32 bits version but we also get an error there (a different error).

    As a workaround we are trying to implement the communication based on TCP/IP, without using the WCF.

    We will post here future development on this issue, for reference for other users.

    Tuesday, May 29, 2012 9:23 AM
  • The issue with failing to CREATE ASSEMBLY for System.IdentityModel.dll for .NET framework 4.0 version in SQL Server 2012 has been resolved with a security hotfix recently released by .NET team.

    MS13-004: Description of the security update for the .NET Framework 4 on Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7, and Windows Server 2008 R2: January 8, 2013

    http://support.microsoft.com/kb/2742595

    My testing has shown that there is no issue on CREATE ASSEMBLY with .NET 4.5 assembly of System.IdentityModel.dll in SQL Server 2012.


    Nathan Schoenack


    Tuesday, February 5, 2013 1:49 PM
  • Does that count for Server 2012 as well?
    Wednesday, September 11, 2013 7:25 PM
  • I have the same issue, I am not able to install the hotfix for windows server 2012. Do you have any solution?
    Thursday, October 12, 2017 7:03 PM