Microsoft Knowledge Base Email Alertz

How to upgrade or downgrade an assembly that has a referenced assembly for a CLR object in an instance of SQL Server 2005

Search KbAlertz

Advanced Search

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]











Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks

Article ID: 917407 - Last Review: May 11, 2007 - Revision: 1.2

How to upgrade or downgrade an assembly that has a referenced assembly for a CLR object in an instance of SQL Server 2005

Bug #: 490 (SQL Hotfix)

On This Page

SUMMARY

When you try to upgrade or downgrade an assembly for a common language runtime (CLR) object in an instance of Microsoft SQL Server 2005, you cannot change the version of the referenced assemblies in the metadata of the assembly. Additionally, if you use a strong-named assembly for a CLR object, you cannot downgrade the assembly by using the ALTER ASSEMBLY statement.

INTRODUCTION

This article describes how to upgrade or downgrade an assembly that has a referenced assembly for a CLR object in an instance of SQL Server 2005.

MORE INFORMATION

How to upgrade or downgrade an assembly

In SQL Server 2005, you can use the ALTER ASSEMBLY statement to upgrade or downgrade a stand-alone assembly that was not created with a strong name. For a strong-named assembly, you can upgrade but cannot downgrade the assembly by using the ALTER ASSEMBLY statement.

You cannot upgrade or downgrade an assembly in the following scenario:
  • Assembly A is created for a CLR object in an instance. Assembly A has a referenced assembly. The referenced assembly is assembly B.
  • Assembly B has no referenced assembly.
  • You recompile assembly A to reference a different version of assembly B.
In this scenario, you can use the ALTER ASSEMBLY statement to upgrade assembly B to a new version. If assembly B is not a strong-named assembly, you can also downgrade assembly B to an old version. However, you cannot use the ALTER ASSEMBLY statement to upgrade or to downgrade assembly A to the recompiled version.

This behavior occurs because SQL Server creates a CLR fusion policy when you create assembly A. This CLR fusion policy automatically maps the version of assembly B in the metadata of assembly A to the actual version of assembly B. SQL Server loads the new version of assembly B at run time when you upgrade or downgrade assembly B to some other version. This behavior occurs even though assembly A refers to the original version of assembly B. However, when you try to upgrade or downgrade assembly A when assembly A contains a new version of assembly B in the metadata, the ALTER ASSEMBLY statement will fail, and you receive error messages that resemble the following:
Error message 1
Msg 6529, Level 16, State 1, Line 1
ALTER ASSEMBLY failed because the identity of referenced assembly 'RefAsm' has changed. Make sure the version, name, and public key have not changed.
Error message 2
Msg 6282, Level 16, State 1, Line 1
ALTER ASSEMBLY failed because the referenced assemblies would change. The referenced assembly list must remain the same.

Upgrade or downgrade the assembly

Notes
  • These steps upgrade or downgrade assembly A in the scenario that was described in the "How to upgrade or downgrade an assembly" section.
  • This example assumes that the versions of the two assemblies are both 1.0.0.0 and the assemblies are both written in C#. When you follow these steps, you try to upgrade assembly A and assembly B to version 2.0.0.0.
To upgrade or downgrade assembly A, follow these steps.
  1. Back up version 1.0.0.0 of assembly B to a folder.
  2. Modify and then recompile assembly B to version 2.0.0.0.
  3. Use the ALTER ASSEMBLY statement to upgrade assembly B in SQL Server 2005.
  4. Modify and then recompile assembly A to version 2.0.0.0. When you do this, reference version 1.0.0.0 of assembly B from the backup that you made in step 1. To do this, use the Csc.exe compiler tool together with the /reference switch. For example, use the following command:
    csc /target:library /out:AssemblyA.dll AssemblyA.cs AssemblyInfo.cs /reference:"BackupFolder\AssemblyB.dll"
    Note To verify the version of assembly B in the metadata of assembly A, open assembly A by using the Ildasm.exe utility. Then, verify the metadata information for the referenced assembly under the MANIFEST section.
  5. Use the ALTER ASSEMBLY statement to upgrade assembly A in SQL Server 2005.

How to downgrade a strong-named assembly

If you use a strong-named assembly for a CLR object, SQL Server 2005 does not support using the ALTER ASSEMBLY statement to downgrade assemblies. If you try to downgrade the version of an assembly by using the ALTER ASSEMBLY statement, you receive an error message that resembles the following:
Msg 6579, Level 16, State 1, Line 1
Alter assembly from 'Asm1, version=1.1.0.0, culture=neutral, publickeytoken=3a52b896cff0513d, processorarchitecture=msil' to 'Asm1, version=1.0.0.0, culture=neutral, publickeytoken=3a52b896cff0513d, processorarchitecture=msil' is not a compatible upgrade.
When you want to downgrade a strong-named assembly, follow these steps:
  1. Drop all objects that depend on the assembly.
  2. Drop the newer version of the assembly.
  3. Create the older version of the assembly.
  4. Create all required objects that depend on the assembly.
Note You can upgrade a strong-named assembly by using the ALTER ASSEMBLY statement. However, if the upgrade involves a referenced assembly, you must follow the same steps that are listed in the "Upgrade or downgrade an assembly" section.

REFERENCES

For more information about the ALTER ASSEMBLY statement, visit the following Microsoft Developer Network (MSDN) Web site:
http://msdn2.microsoft.com/en-us/library/ms186711.aspx (http://msdn2.microsoft.com/en-us/library/ms186711.aspx)
For more information about the Ildasm.exe utility, visit the following MSDN Web site:
http://msdn2.microsoft.com/en-us/library/aa309387(VS.71).aspx (http://msdn2.microsoft.com/en-us/library/aa309387(VS.71).aspx)

APPLIES TO
  • Microsoft SQL Server 2005 Standard Edition
  • Microsoft SQL Server 2005 Developer Edition
  • Microsoft SQL Server 2005 Enterprise Edition
  • Microsoft SQL Server 2005 Express Edition
  • Microsoft SQL Server 2005 Workgroup Edition
Keywords: 
kbexpertiseadvanced kbsql2005clr kbhowto KB917407
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate