- •maranGraphics
- •CREDITS
- •ACKNOWLEDGMENTS
- •ABOUT THE AUTHORS
- •AUTHORS’ ACKNOWLEDGMENTS
- •TABLE OF CONTENTS
- •HOW TO USE THIS BOOK
- •INTRODUCTION TO C#
- •START VISUAL STUDIO .NET
- •OPEN A NEW C# PROJECT
- •OPEN A C# WEB PROJECT
- •SET JSCRIPT .NET AS THE DEFAULT SCRIPT LANGUAGE
- •EXPLORE THE CLASS VIEW WINDOW
- •VIEW THE CONTENTS WINDOW
- •GET HELP USING THE INDEX WINDOW
- •SEARCH FOR HELP
- •ADD COMPONENTS FROM THE TOOLBOX
- •ADD A TASK TO THE TASK LIST
- •CHANGE FORM PROPERTIES IN THE PROPERTIES WINDOW
- •ADD A CUSTOM TOOLBAR
- •DELETE A TOOLBAR
- •CHANGE THE VISUAL STUDIO ENVIRONMENT
- •MANAGE OPEN WINDOWS
- •OPEN A PROJECT
- •VIEW THE MAIN METHOD
- •COMBINE PROGRAM TYPES
- •ADD REFERENCE TYPES
- •ADD OPERATORS
- •INSERT ATTRIBUTES
- •ENTER CLASSES
- •ADD COMMENTS TO CODE
- •WRITE YOUR FIRST PROGRAM
- •ENTER XML DOCUMENTATION
- •ACCESS DOCUMENTATION
- •LOG A BUG REPORT
- •VIEW INFORMATION ABOUT C# BUILDING BLOCKS
- •PROGRAM CLASSES
- •ADD A CLASS
- •EMPLOY CLASS INHERITANCE
- •PROGRAM INSTANCE CONSTRUCTORS
- •INSERT DESTRUCTORS
- •PROGRAM STRUCTS
- •DISPLAY HEAP AND STACK INFORMATION
- •FIND TYPE INFORMATION
- •PROGRAM CONSTANT EXPRESSIONS
- •SPECIFY VALUE TYPES
- •PROGRAM NUMERIC TYPES
- •PROGRAM THE BOOLEAN TYPE
- •DECLARE REFERENCE TYPES
- •ENTER REFERENCE TYPE DECLARATIONS
- •CONVERT VALUE TYPES TO REFERENCE TYPES
- •PROGRAM POINTER TYPES
- •INSERT THE VOID TYPE
- •ADD INTERFACE PROPERTIES
- •ADD AN INTERFACE INDEX
- •VIEW INFORMATION ABOUT METHODS
- •ADD A METHOD
- •ADD STATIC METHODS
- •INCLUDE NON-STATIC METHODS
- •ENTER DELEGATES
- •PROGRAM EVENTS
- •ADD AN EVENT-HANDLING METHOD
- •VIEW INFORMATION ABOUT ARRAYS
- •ENTER SINGLE-DIMENSIONAL ARRAYS
- •ADD MULTIDIMENSIONAL ARRAYS
- •PROGRAM ARRAY-OF-ARRAYS
- •ITERATE THROUGH ARRAY ELEMENTS
- •SORT ARRAYS
- •SEARCH ARRAYS
- •IMPLEMENT A COLLECTIONS CLASS
- •PROGRAM STRUCTS
- •ADD AN INDEXER
- •INCLUDE ENUMERATIONS
- •CREATE STRING LITERALS AND VARIABLES
- •ASSIGN VALUES TO STRINGS
- •CONCATENATE STRINGS
- •COMPARE STRINGS
- •SEARCH FOR SUBSTRINGS
- •REPLACE CHARACTERS
- •EXTRACT SUBSTRINGS
- •CHANGE THE CHARACTER CASE
- •TRIM SPACES
- •REMOVE CHARACTERS
- •SPLIT A STRING
- •JOIN STRINGS
- •PAD STRINGS
- •VIEW INFORMATION ABOUT PROPERTIES
- •COMPARE PROPERTIES AND INDEXERS
- •PROGRAM PROPERTY ACCESSORS
- •DECLARE ABSTRACT PROPERTIES
- •INCLUDE PROPERTIES ON INTERFACES
- •VIEW INFORMATION ABOUT WINDOWS FORMS
- •ADD A WINDOWS FORM IN THE WINDOWS FORM DESIGNER
- •SET THE FORM TYPE
- •CHOOSE THE STARTUP WINDOWS FORM
- •CREATE A MODAL FORM
- •LAYOUT A FORM
- •SET A FORM LOCATION
- •CHANGE FORM PROPERTIES
- •CREATE A TRANSPARENT FORM
- •AN INTRODUCTION TO WEB FORMS AND CONTROLS
- •CREATE AN ASP.NET WEB SITE
- •CREATE A WEB FORM
- •ADD SERVER CONTROLS TO A WEB FORM
- •READ AND CHANGE PROPERTIES FROM OBJECTS ON A WEB FORM
- •USING SERVER-SIDE COMPONENTS ON WEB FORMS
- •INTRODUCING DATA ACCESS WITH ADO.NET
- •DISPLAY DATA WITH THE DATAGRID CONTROL
- •CONFIGURE THE DATAGRID CONTROL
- •INSERT DATA INTO A SQL DATABASE
- •UPDATE DATA FROM A SQL DATABASE
- •DELETE DATA FROM A SQL DATABASE
- •EXECUTE A STORED PROCEDURE IN A SQL DATABASE
- •READ XML FROM A FILE
- •SAVE XML TO A FILE
- •QUERY XML WITH XPATH
- •APPLY XSL TO XML
- •INTRODUCTION TO DISTRIBUTED APPLICATIONS
- •CREATE AN APPLICATION WITH PRIVATE ASSEMBLIES
- •CREATE AN APPLICATION WITH SHARED ASSEMBLIES
- •VERSION A SHARED ASSEMBLY
- •CONFIGURE A CLIENT FOR A VERSIONED ASSEMBLY
- •CREATE A WEB SERVICE
- •USING A WEB SERVICE
- •INTRODUCTION TO EXCEPTION HANDLING
- •THROWING AN EXCEPTION
- •HANDLING EXCEPTIONS WITH THE CATCH BLOCK
- •USING THE FINALLY BLOCK
- •WRITE ERRORS TO THE APPLICATION LOG
- •BASIC EXAMPLES
- •WHAT’S ON THE CD-ROM
- •USING THE E-VERSION OF THIS BOOK
- •INDEX
- •Symbols & Numbers
C#
VERSION A SHARED ASSEMBLY
ou can version assemblies if you use shared Yassemblies. Versioning helps the CLR determine
which physical class to load when an object request is made from a client application. Versioning of the same component enables you to manage distributing updates to applications without breaking clients.
You build version numbers from four sets of numbers that you separate by periods: Major, Minor, Revision, and Build Number. You configure the version number in the AssemblyVersion assembly-level attribute that you find in the AssemblyInfo file. To do so, you need to understand the compatibility between the two versions of the same component.
The numbered steps below enable you to create two versions of the same shared component. After you register each version, you see two rows for the component in the GAC, one for each version. Both lines look identical, except for the version number (one being 1.0.0.0 and the other being 2.0.0.0). Versioning in .NET allows for side-by-side execution of the same component, which gives the capability to have an instance of each version running at the same time on the same machine, which is a useful, new capability of the .NET platform.
VERSION A SHARED ASSEMBLY
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Create two directories for |
|
Á Open the |
|
|
|
|
|||
|
|
|
|
|
|
|
|
|
|
|
|
|
|||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|||||
|
|
|
|
|
|
|
|
|
|
‡ Change the |
|||||||
|
|
|
|
||||||||||||||
|
|
|
|
|
|
|
|
versions of the |
AssemblyInfo.cs file. |
|
AssemblyVersion to a |
||||||
|
|
|
. |
|
|
|
|
|
|
later version number. |
|||||||
|
|
|
|
|
|
|
|
the component into |
|
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|||
|
|
|
|
|
|
|
|
earlier version directory. |
|
|
|
|
|
|
|
CREATING AND DEPLOYING DISTRIBUTED APPLICATIONS 14
You can determine different compatibility scenarios with the four sets of numbers that make up a version:
Incompatible — Change to the assembly making it incompatible with previous versions. Two versions are incompatible when the Major and Minor numbers between the two versions do not match.
Maybe Compatible — Change to the assembly that is thought to be compatible and carries less risk than an incompatible change. However, backward compatibility is not guaranteed. An example is a service pack or a release of a new daily build.
QFE (Quick Fix Engineering) — Engineering fix that customers must upgrade. An example is an emergency security fix. Does not impact compatibility.
If you install a new version of a shared component on your clients machine, the runtime determines if it can use the new version for calls from existing clients. For example, if you compile a client against a shared component with version 2.1.1.101, and then install a new version at a later date that has version 2.1.1.211, the client application uses the newer version 2.1.1.211 the next time it makes a request to load the assembly.
° Open the Photo.cs file. · Change the message to display the later version number.
‚ Build the component.
— Open File Explorer and navigate to the bin\Debug directory.
± Copy the component to the directory for the later version of the component.
267
C#
CONFIGURE A CLIENT FOR A VERSIONED ASSEMBLY
ou can utilize versioned assemblies to give your client Yapplications an upgrade path for newer, optimized or
enhanced components. With the versioning capabilities of .NET, you can use an assembly that has extended its members without the need to recompile. The version binding policy determines which version you need to use for a calling client to a shared assembly. The .NET runtime and/or the configuration file for the application determines what your client’s version binding policy is. The configuration file can override the .NET runtime binding by setting the versioning in the <bindingRedirect> element of the <runtime> element.
The process of using a versioned assembly is not any different than what you do with an unversioned shared assembly. You just need to make sure that you select the correct version. Shared assemblies with multiple versions will have multiple entries with the same Global Assembly Name, but each entry for that Global Assembly Name will have a different number in the version column. For more information on shared assemblies, see page 260. To check that you have the right version, after you have made the reference, you can view the properties of the reference in the reference list in the project solution.
CONFIGURE A CLIENT FOR A VERSIONED ASSEMBLY
Accessibility |
1.0.0.0 |
C:\WINNT\Microsoft.NET\Fra... |
■ The Add Reference dialog |
› Click Browse. |
box appears. |
|
CREATING AND DEPLOYING DISTRIBUTED APPLICATIONS 14
To control the binding of a client to a versioned assembly that your client application uses, you can create a configuration file. The example shows how to use the configuration file to redirect the binding from one version to another version. For you to test the example with the code that is created in the numbered steps below, you will have to update the publicKeyToken to match the hash of the public key that you created on page 260.
EXAMPLE:
<configuration>
<runtime>
<assemblyBinding
xmlns="urn:schemas-microsoft- com:asm.v1">
<dependentAssembly>
<assemblyIdentity name= "VersionedPhotoAlbum"
publicKeyToken=
"e79f3eb79bb2bf0a"
culture=""/>
<bindingRedirect oldVersion= "1.0.0.0"
newVersion="2.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
■ The Select Component dialog box appears.
ˇ Go to the later version of the server component.
Á Click the component.
‡ Click Open.
° Click OK.
· Press F5 to save, build, and run the console application.
‚ Open the command prompt and navigate to the directory where the client was created.
— Run the client application.
■ A message appears showing the properties set for the file and the correct version number.
269