ASP.NET and shared assemblies

  • Thread starter Invalidlastname
  • Start date
I

Invalidlastname

Hi,
We developed some assemblies which use EnterpriseServices queued components.
In order to use EnterpriseServices, these assemblies need to be installed
into GAC. I used the pre-build and post-build events to automate GAC
installation processes and the asp.net application has "copy to local" set
to false for the references of these shared assemblies.

However, every time we made the changes to the shared assemblies, we had to
restart the IIS in order to force the asp.net to use the new version of the
shared assemblies. If we did not restart the IIS, the asp.net will continue
to use the older version of the shared assemblies. I believe the reason of
recycling the IIS is actually to recycle the AppDomain so the ASP.NET will
bind to the most recent version of the shared assemblies. I know by changing
the web.config will recycle the AppDomain too, but since the web.config is
bound to the SourceSafe, by default it is read-only, and we don't want to
modify it for every changes made to the shared assemblies.

I believe this is a very common issue for ASP.NET development using shared
assemblies. There must be a better setup for this kind of the development.
Any helps will be appreciated

ILN
 
M

MSFT

Hello,

How did you add the reference to the web application? Based on my test, the
web application will try to find the latest version of the referenced
assembly. (I added the reference by browsing to the classlibrary file and
set "copy local" to false.

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
I

Invalidlastname

Luke,
The referenced projects, shared assemblies, are in the same solution as
asp.net project. The references were added from Add Reference dialog box >
Projects tab. The "copy local" was set to "false" for the references to the
shared assemblies and to "true" for the references to private assemblies.

the followings are the project file fragment of the shared assembly
(Xyz.Common)
<VisualStudioProject>
<CSHARP
ProjectType = "Local"
ProductVersion = "7.10.3077"
SchemaVersion = "2.0"
ProjectGuid = "{90AB26A7-505B-4E2F-9B80-0B910AFD215F}"
SccProjectName = "SAK"
SccLocalPath = "SAK"
SccAuxPath = "SAK"
SccProvider = "SAK"<Build>
<Settings
ApplicationIcon = ""
AssemblyKeyContainerName = ""
AssemblyName = "Xyz.Common"
AssemblyOriginatorKeyFile = ""
DefaultClientScript = "JScript"
DefaultHTMLPageLayout = "Grid"
DefaultTargetSchema = "IE50"
DelaySign = "false"
OutputType = "Library"
PreBuildEvent = '"C:\Program Files\Microsoft Visual Studio
..NET 2003\SDK\v1.1\Bin\gacutil.exe" /nologo /uf "$(TargetPath)"'
PostBuildEvent = '"C:\Program Files\Microsoft Visual Studio
..NET 2003\SDK\v1.1\Bin\gacutil.exe" /nologo /if "$(TargetPath)"'
RootNamespace = "Xyz.Common"
RunPostBuildEvent = "OnBuildSuccess"
StartupObject = ""<Config
Name = "Debug"
AllowUnsafeBlocks = "false"
BaseAddress = "285212672"
CheckForOverflowUnderflow = "false"
ConfigurationOverrideFile = ""
DefineConstants = "DEBUG;TRACE"
DocumentationFile = ""
DebugSymbols = "true"
FileAlignment = "4096"
IncrementalBuild = "false"
NoStdLib = "false"
NoWarn = ""
Optimize = "false"
OutputPath = "bin\Debug\"
RegisterForComInterop = "false"
RemoveIntegerChecks = "false"
TreatWarningsAsErrors = "false"
WarningLevel = "4"
/>
<Config
Name = "Release"
AllowUnsafeBlocks = "false"
BaseAddress = "285212672"
CheckForOverflowUnderflow = "false"
ConfigurationOverrideFile = ""
DefineConstants = "TRACE"
DocumentationFile = ""
DebugSymbols = "false"
FileAlignment = "4096"
IncrementalBuild = "false"
NoStdLib = "false"
NoWarn = ""
Optimize = "true"
OutputPath = "bin\Release\"
RegisterForComInterop = "false"
RemoveIntegerChecks = "false"
TreatWarningsAsErrors = "false"
WarningLevel = "4"
/>
</Settings>
<References>
<Reference
Name = "System"
AssemblyName = "System"
HintPath =
"..\..\..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.dll"
/>
<Reference
Name = "System.Data"
AssemblyName = "System.Data"
HintPath =
"..\..\..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Data.dll
"
/>
<Reference
Name = "System.XML"
AssemblyName = "System.Xml"
HintPath =
"..\..\..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.XML.dll"
/>
<Reference
Name = "Microsoft.ApplicationBlocks.ExceptionManagement"
Project = "{386CBF50-F4A9-4F05-98CB-B387D2D8F357}"
Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"
Private = "False"
/>
<Reference
Name =
"Microsoft.ApplicationBlocks.ExceptionManagement.Interfaces"
Project = "{5F25F8C2-DA02-46C6-A6CA-01E719EAD35D}"
Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"
Private = "False"
/>
<Reference
Name = "Microsoft.ApplicationBlocks.Data"
Project = "{30933672-466E-4F67-A111-ABF267539146}"
Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"
Private = "False"
/>
<Reference
Name = "System.Web"
AssemblyName = "System.Web"
HintPath =
"..\..\..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Web.dll"
/>
<Reference
Name = "System.Security"
AssemblyName = "System.Security"
HintPath =
"..\..\..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Security
..dll"
/>
<Reference
Name = "System.Web.Services"
AssemblyName = "System.Web.Services"
HintPath =
"..\..\..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Web.Serv
ices.dll"
/>
</References>
</Build>

The followings are the project file fragment of the asp.net web application

<VisualStudioProject>
<CSHARP
ProjectType = "Web"
ProductVersion = "7.10.3077"
SchemaVersion = "2.0"
ProjectGuid = "{B92F596B-4F30-4FC2-9F84-5AD62B56C0DA}"
SccProjectName = "SAK"
SccLocalPath = "SAK"
SccAuxPath = "SAK"
SccProvider = "SAK"<Build>
<Settings
ApplicationIcon = ""
AssemblyKeyContainerName = ""
AssemblyName = "Subscribers"
AssemblyOriginatorKeyFile = ""
DefaultClientScript = "JScript"
DefaultHTMLPageLayout = "Flow"
DefaultTargetSchema = "IE50"
DelaySign = "false"
OutputType = "Library"
PreBuildEvent = ""
PostBuildEvent = ""
RootNamespace = "Xyz.Web.Subscribers"
RunPostBuildEvent = "OnBuildSuccess"
StartupObject = ""<Config
Name = "Debug"
AllowUnsafeBlocks = "false"
BaseAddress = "285212672"
CheckForOverflowUnderflow = "false"
ConfigurationOverrideFile = ""
DefineConstants = "DEBUG;TRACE"
DocumentationFile = ""
DebugSymbols = "true"
FileAlignment = "4096"
IncrementalBuild = "false"
NoStdLib = "false"
NoWarn = ""
Optimize = "false"
OutputPath = "bin\"
RegisterForComInterop = "false"
RemoveIntegerChecks = "false"
TreatWarningsAsErrors = "false"
WarningLevel = "4"
/>
<Config
Name = "Release"
AllowUnsafeBlocks = "false"
BaseAddress = "285212672"
CheckForOverflowUnderflow = "false"
ConfigurationOverrideFile = ""
DefineConstants = "TRACE"
DocumentationFile = ""
DebugSymbols = "false"
FileAlignment = "4096"
IncrementalBuild = "false"
NoStdLib = "false"
NoWarn = ""
Optimize = "true"
OutputPath = "bin\"
RegisterForComInterop = "false"
RemoveIntegerChecks = "false"
TreatWarningsAsErrors = "false"
WarningLevel = "4"
/>
</Settings>
<References>
<Reference
Name = "System"
AssemblyName = "System"
HintPath =
"..\..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.dll"
/>
<Reference
Name = "System.Drawing"
AssemblyName = "System.Drawing"
HintPath =
"..\..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Drawing.dll
"
/>
<Reference
Name = "System.Data"
AssemblyName = "System.Data"
HintPath =
"..\..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Data.dll"
/>
<Reference
Name = "System.Web"
AssemblyName = "System.Web"
HintPath =
"..\..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Web.dll"
/>
<Reference
Name = "System.XML"
AssemblyName = "System.Xml"
HintPath =
"..\..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.XML.dll"
/>
<Reference
Name = "Xyz.Common"
Project = "{90AB26A7-505B-4E2F-9B80-0B910AFD215F}"
Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"
Private = "False"
/>
<Reference
Name = "Microsoft.ApplicationBlocks.ExceptionManagement"
Project = "{386CBF50-F4A9-4F05-98CB-B387D2D8F357}"
Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"
Private = "False"
/>
<Reference
Name =
"Microsoft.ApplicationBlocks.ExceptionManagement.Interfaces"
Project = "{5F25F8C2-DA02-46C6-A6CA-01E719EAD35D}"
Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"
Private = "False"
/>
<Reference
Name = "System.Web.Services"
AssemblyName = "System.Web.Services"
HintPath =
"..\..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Web.Service
s.dll"
/>
<Reference
Name = "Microsoft.ApplicationBlocks.Data"
Project = "{30933672-466E-4F67-A111-ABF267539146}"
Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"
Private = "False"
/>
<Reference
Name = "Xyz.DAL"
Project = "{6559D88E-6265-4424-AC2D-8E4BC4462361}"
Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"
/>
<Reference
Name = "Xyz.Accounts"
Project = "{FAE55257-8189-49CC-8421-AE34C85300BF}"
Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"
/>
<Reference
Name = "Xyz.Async"
Project = "{E6D51F3B-F4A7-4A25-BAC1-6013EF66C4B4}"
Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"
Private = "False"
/>
</References>
</Build>



We used queued components for asynchronous processes. If the

ILN
 
J

Jim Cheshire [MSFT]

ILN,

That article is not entirely accurate. As long as you don't make a change
that causes the assembly hash value to change, you can update a new version
of the assembly in the GAC and the ASP.NET application will automatically
use the new version without changing anything. (It should be noted that
you do still have to reload the app domain.)

What changes the hash value? If you change the assembly name, the major or
minor version, the public key token, or the culture, the hash value will
change. As long as you don't modify any one of these, you would use the
following procedure to update the assembly in the GAC.

1. Run sn to create a new verification entry for the new version. Do that
as
follows:

sn -Vr <assembly>

2. Run Gacutil to reinstall the assembly as follows:

gacutil /nologo /if <assembly>

Once you do that, simply open the web.config, add a new blank line, and
save the web.config. That will force a reload of the app domain and your
application will use the new assembly.

If you have changed the hash value by changing one of the above, the
easiest way to force your application to use the new version in cases where
you can't redirect the assembly binding in a configuration file is to use a
publisher policy assembly. Most people will say that you should use a
publisher policy file, but that's not entirely accurate. The publisher
policy file is used to create the publisher policy assembly, and it's
actually the publisher policy assembly that redirects the binding.

Here is an example of doing this. In this example, my assembly is called
jcGAC.dll and I am changing the version number from 1.0.0.0 to 2.0.0.0.

1. Change code in version 1.0.0.0 of the assembly.

2. Change version number in assemblyinfo.cs to reflect new version.

3. Rebuild assembly.

4. Create publisher policy file in any text editor. You will need to
replace "<public_key>" with the public key for your version 1.0 assembly.

<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="jcGAC"
publicKeyToken="<public_key>"
culture="neutral" />
<bindingRedirect oldVersion="1.0.0.0"
newVersion="2.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

5. Use al to create the publisher policy assembly. The publisher policy
assembly MUST have the following file format:
policy.major_ver.minor_ver.assembly.dll

The major and minor version shown here would be the major and minor
versions for your original version, not the updated new version. Below is
an example of the command entered to create the publisher policy assembly
for my assembly jcGAC.dll using the keyfile jcgac.snk. Note that the
publisher policy file in created in step 4 was saved as pub.config.

al /link:pub.config /out:policy.1.0.jcGAC.dll /keyfile:jcgac.snk


6. Install publisher policy assembly into the GAC.

gacutil /i policy.2.0.jcGAC.dll

7. Install version 2.0.0.0 of your assembly into the GAC.

gacutil /i jcGAC.dll

8. Restart the app domains by either saving a change to the machine.config
or by resetting IIS.

9. Run the ASP.NET app.

After taking these steps, any ASP.NET application that originally
referenced version 1.0.0.0 will now bind to version 2.0.0.0.


Assembly binding is a fairly complex subject, but I hope that this helps
explain a bit.

Jim Cheshire, MCSE, MCSD [MSFT]
Developer Support
ASP.NET
(e-mail address removed)

This post is provided as-is with no warranties and confers no rights.

--------------------
 
I

Invalidlastname

Hi Jim,
Greatly thanks for the excellent details you provided. However, back to my
original question about how to setup the ASP.NET development environment for
using shared assemblies. Please correct me if I am wrong, it seems to me
that we need to add a post-build event to restart the IIS, or "touch" the
web.config for every changes made to the shared assembly projects ( in order
to reload the AppDomain).

I believe developers would appreciate if Microsoft can provide some
guidelines for developing ASP.NET applications with shared assemblies
scenarios. Actually the only reason we need to have shared assemblies is we
are using queued components from EnterpriseService namespace.

ILN



Jim Cheshire said:
ILN,

That article is not entirely accurate. As long as you don't make a change
that causes the assembly hash value to change, you can update a new version
of the assembly in the GAC and the ASP.NET application will automatically
use the new version without changing anything. (It should be noted that
you do still have to reload the app domain.)

What changes the hash value? If you change the assembly name, the major or
minor version, the public key token, or the culture, the hash value will
change. As long as you don't modify any one of these, you would use the
following procedure to update the assembly in the GAC.

1. Run sn to create a new verification entry for the new version. Do that
as
follows:

sn -Vr <assembly>

2. Run Gacutil to reinstall the assembly as follows:

gacutil /nologo /if <assembly>

Once you do that, simply open the web.config, add a new blank line, and
save the web.config. That will force a reload of the app domain and your
application will use the new assembly.

If you have changed the hash value by changing one of the above, the
easiest way to force your application to use the new version in cases where
you can't redirect the assembly binding in a configuration file is to use a
publisher policy assembly. Most people will say that you should use a
publisher policy file, but that's not entirely accurate. The publisher
policy file is used to create the publisher policy assembly, and it's
actually the publisher policy assembly that redirects the binding.

Here is an example of doing this. In this example, my assembly is called
jcGAC.dll and I am changing the version number from 1.0.0.0 to 2.0.0.0.

1. Change code in version 1.0.0.0 of the assembly.

2. Change version number in assemblyinfo.cs to reflect new version.

3. Rebuild assembly.

4. Create publisher policy file in any text editor. You will need to
replace "<public_key>" with the public key for your version 1.0 assembly.

<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="jcGAC"
publicKeyToken="<public_key>"
culture="neutral" />
<bindingRedirect oldVersion="1.0.0.0"
newVersion="2.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

5. Use al to create the publisher policy assembly. The publisher policy
assembly MUST have the following file format:
policy.major_ver.minor_ver.assembly.dll

The major and minor version shown here would be the major and minor
versions for your original version, not the updated new version. Below is
an example of the command entered to create the publisher policy assembly
for my assembly jcGAC.dll using the keyfile jcgac.snk. Note that the
publisher policy file in created in step 4 was saved as pub.config.

al /link:pub.config /out:policy.1.0.jcGAC.dll /keyfile:jcgac.snk


6. Install publisher policy assembly into the GAC.

gacutil /i policy.2.0.jcGAC.dll

7. Install version 2.0.0.0 of your assembly into the GAC.

gacutil /i jcGAC.dll

8. Restart the app domains by either saving a change to the machine.config
or by resetting IIS.

9. Run the ASP.NET app.

After taking these steps, any ASP.NET application that originally
referenced version 1.0.0.0 will now bind to version 2.0.0.0.


Assembly binding is a fairly complex subject, but I hope that this helps
explain a bit.

Jim Cheshire, MCSE, MCSD [MSFT]
Developer Support
ASP.NET
(e-mail address removed)

This post is provided as-is with no warranties and confers no rights.

--------------------
From: "Invalidlastname" <[email protected]>
References: <[email protected]>
Subject: Re: ASP.NET and shared assemblies
Date: Tue, 2 Dec 2003 11:09:34 -0500
Lines: 349
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.3790.0
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.aspnet
NNTP-Posting-Host: dc.cvent.com 65.117.187.221
Path:
cpmsftngxa06.phx.gbl!cpmsftngxa09.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.
phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:194484
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet

BTW
from this article
http://www.aspalliance.com/226
the asp.net will not look for the latest version from GAC, and this is what
I have experienced.

ILN

box

"..\..\..\..\..\.\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Data.dl
l
"..\..\..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.XML.dll
"
"..\..\..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Web.dll
"
"..\..\..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Securit
y
"..\..\..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Web.Ser
v
"..\..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Drawing.dl
l
"..\..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Web.Servic
e
 
J

Jim Cheshire [MSFT]

ILN,

Yes, you would have to reload the app domain. ASP.NET is written
explicitly so that it doesn't rebind to assemblies directly on each need.
If it had to do that, it would cause a critical bottleneck.

The first thing that happens in the binding order is that the CLR says,
"Have I bound to this assembly already?" If the answer is Yes, it simply
uses the previous binding.

Jim Cheshire, MCSE, MCSD [MSFT]
Developer Support
ASP.NET
(e-mail address removed)

This post is provided as-is with no warranties and confers no rights.

--------------------
From: "Invalidlastname" <[email protected]>
References: <[email protected]>
<[email protected]>
<[email protected]>
Subject: Re: ASP.NET and shared assemblies
Date: Wed, 3 Dec 2003 11:26:10 -0500
Lines: 527
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.3790.0
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.aspnet
NNTP-Posting-Host: dc.cvent.com 65.117.187.221
Path: cpmsftngxa06.phx.gbl!cpmsftngxa09.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.
phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:194754
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet

Hi Jim,
Greatly thanks for the excellent details you provided. However, back to my
original question about how to setup the ASP.NET development environment for
using shared assemblies. Please correct me if I am wrong, it seems to me
that we need to add a post-build event to restart the IIS, or "touch" the
web.config for every changes made to the shared assembly projects ( in order
to reload the AppDomain).

I believe developers would appreciate if Microsoft can provide some
guidelines for developing ASP.NET applications with shared assemblies
scenarios. Actually the only reason we need to have shared assemblies is we
are using queued components from EnterpriseService namespace.

ILN



Jim Cheshire said:
ILN,

That article is not entirely accurate. As long as you don't make a change
that causes the assembly hash value to change, you can update a new version
of the assembly in the GAC and the ASP.NET application will automatically
use the new version without changing anything. (It should be noted that
you do still have to reload the app domain.)

What changes the hash value? If you change the assembly name, the major or
minor version, the public key token, or the culture, the hash value will
change. As long as you don't modify any one of these, you would use the
following procedure to update the assembly in the GAC.

1. Run sn to create a new verification entry for the new version. Do that
as
follows:

sn -Vr <assembly>

2. Run Gacutil to reinstall the assembly as follows:

gacutil /nologo /if <assembly>

Once you do that, simply open the web.config, add a new blank line, and
save the web.config. That will force a reload of the app domain and your
application will use the new assembly.

If you have changed the hash value by changing one of the above, the
easiest way to force your application to use the new version in cases where
you can't redirect the assembly binding in a configuration file is to use a
publisher policy assembly. Most people will say that you should use a
publisher policy file, but that's not entirely accurate. The publisher
policy file is used to create the publisher policy assembly, and it's
actually the publisher policy assembly that redirects the binding.

Here is an example of doing this. In this example, my assembly is called
jcGAC.dll and I am changing the version number from 1.0.0.0 to 2.0.0.0.

1. Change code in version 1.0.0.0 of the assembly.

2. Change version number in assemblyinfo.cs to reflect new version.

3. Rebuild assembly.

4. Create publisher policy file in any text editor. You will need to
replace "<public_key>" with the public key for your version 1.0 assembly.

<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="jcGAC"
publicKeyToken="<public_key>"
culture="neutral" />
<bindingRedirect oldVersion="1.0.0.0"
newVersion="2.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

5. Use al to create the publisher policy assembly. The publisher policy
assembly MUST have the following file format:
policy.major_ver.minor_ver.assembly.dll

The major and minor version shown here would be the major and minor
versions for your original version, not the updated new version. Below is
an example of the command entered to create the publisher policy assembly
for my assembly jcGAC.dll using the keyfile jcgac.snk. Note that the
publisher policy file in created in step 4 was saved as pub.config.

al /link:pub.config /out:policy.1.0.jcGAC.dll /keyfile:jcgac.snk


6. Install publisher policy assembly into the GAC.

gacutil /i policy.2.0.jcGAC.dll

7. Install version 2.0.0.0 of your assembly into the GAC.

gacutil /i jcGAC.dll

8. Restart the app domains by either saving a change to the machine.config
or by resetting IIS.

9. Run the ASP.NET app.

After taking these steps, any ASP.NET application that originally
referenced version 1.0.0.0 will now bind to version 2.0.0.0.


Assembly binding is a fairly complex subject, but I hope that this helps
explain a bit.

Jim Cheshire, MCSE, MCSD [MSFT]
Developer Support
ASP.NET
(e-mail address removed)

This post is provided as-is with no warranties and confers no rights.

--------------------
From: "Invalidlastname" <[email protected]>
References: <[email protected]>
Subject: Re: ASP.NET and shared assemblies
Date: Tue, 2 Dec 2003 11:09:34 -0500
Lines: 349
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.3790.0
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.aspnet
NNTP-Posting-Host: dc.cvent.com 65.117.187.221
Path:
cpmsftngxa06.phx.gbl!cpmsftngxa09.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10
 
I

Invalidlastname

Jim,
Again, thank you for giving me such detailed explanations. It is really
helpful.



Jim Cheshire said:
ILN,

Yes, you would have to reload the app domain. ASP.NET is written
explicitly so that it doesn't rebind to assemblies directly on each need.
If it had to do that, it would cause a critical bottleneck.

The first thing that happens in the binding order is that the CLR says,
"Have I bound to this assembly already?" If the answer is Yes, it simply
uses the previous binding.

Jim Cheshire, MCSE, MCSD [MSFT]
Developer Support
ASP.NET
(e-mail address removed)

This post is provided as-is with no warranties and confers no rights.

--------------------
From: "Invalidlastname" <[email protected]>
References: <[email protected]>
<[email protected]>
<[email protected]>
Subject: Re: ASP.NET and shared assemblies
Date: Wed, 3 Dec 2003 11:26:10 -0500
Lines: 527
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.3790.0
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.aspnet
NNTP-Posting-Host: dc.cvent.com 65.117.187.221
Path:
cpmsftngxa06.phx.gbl!cpmsftngxa09.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.
phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:194754
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet

Hi Jim,
Greatly thanks for the excellent details you provided. However, back to my
original question about how to setup the ASP.NET development environment for
using shared assemblies. Please correct me if I am wrong, it seems to me
that we need to add a post-build event to restart the IIS, or "touch" the
web.config for every changes made to the shared assembly projects ( in order
to reload the AppDomain).

I believe developers would appreciate if Microsoft can provide some
guidelines for developing ASP.NET applications with shared assemblies
scenarios. Actually the only reason we need to have shared assemblies is we
are using queued components from EnterpriseService namespace.

ILN



Jim Cheshire said:
ILN,

That article is not entirely accurate. As long as you don't make a change
that causes the assembly hash value to change, you can update a new version
of the assembly in the GAC and the ASP.NET application will automatically
use the new version without changing anything. (It should be noted that
you do still have to reload the app domain.)

What changes the hash value? If you change the assembly name, the
major
or
minor version, the public key token, or the culture, the hash value will
change. As long as you don't modify any one of these, you would use the
following procedure to update the assembly in the GAC.

1. Run sn to create a new verification entry for the new version. Do that
as
follows:

sn -Vr <assembly>

2. Run Gacutil to reinstall the assembly as follows:

gacutil /nologo /if <assembly>

Once you do that, simply open the web.config, add a new blank line, and
save the web.config. That will force a reload of the app domain and your
application will use the new assembly.

If you have changed the hash value by changing one of the above, the
easiest way to force your application to use the new version in cases where
you can't redirect the assembly binding in a configuration file is to
use
a
publisher policy assembly. Most people will say that you should use a
publisher policy file, but that's not entirely accurate. The publisher
policy file is used to create the publisher policy assembly, and it's
actually the publisher policy assembly that redirects the binding.

Here is an example of doing this. In this example, my assembly is called
jcGAC.dll and I am changing the version number from 1.0.0.0 to 2.0.0.0.

1. Change code in version 1.0.0.0 of the assembly.

2. Change version number in assemblyinfo.cs to reflect new version.

3. Rebuild assembly.

4. Create publisher policy file in any text editor. You will need to
replace "<public_key>" with the public key for your version 1.0 assembly.

<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="jcGAC"
publicKeyToken="<public_key>"
culture="neutral" />
<bindingRedirect oldVersion="1.0.0.0"
newVersion="2.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

5. Use al to create the publisher policy assembly. The publisher policy
assembly MUST have the following file format:
policy.major_ver.minor_ver.assembly.dll

The major and minor version shown here would be the major and minor
versions for your original version, not the updated new version. Below is
an example of the command entered to create the publisher policy assembly
for my assembly jcGAC.dll using the keyfile jcgac.snk. Note that the
publisher policy file in created in step 4 was saved as pub.config.

al /link:pub.config /out:policy.1.0.jcGAC.dll /keyfile:jcgac.snk


6. Install publisher policy assembly into the GAC.

gacutil /i policy.2.0.jcGAC.dll

7. Install version 2.0.0.0 of your assembly into the GAC.

gacutil /i jcGAC.dll

8. Restart the app domains by either saving a change to the machine.config
or by resetting IIS.

9. Run the ASP.NET app.

After taking these steps, any ASP.NET application that originally
referenced version 1.0.0.0 will now bind to version 2.0.0.0.


Assembly binding is a fairly complex subject, but I hope that this helps
explain a bit.

Jim Cheshire, MCSE, MCSD [MSFT]
Developer Support
ASP.NET
(e-mail address removed)

This post is provided as-is with no warranties and confers no rights.

--------------------
From: "Invalidlastname" <[email protected]>
References: <[email protected]>
<[email protected]>
<[email protected]>
Subject: Re: ASP.NET and shared assemblies
Date: Tue, 2 Dec 2003 11:09:34 -0500
Lines: 349
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.3790.0
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.aspnet
NNTP-Posting-Host: dc.cvent.com 65.117.187.221
Path:

cpmsftngxa06.phx.gbl!cpmsftngxa09.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10
 
J

Jim Cheshire [MSFT]

ILN,

You are very welcome. That's my day job. :) I'm glad the info helped.
We want developers to understand as much as possible about the internal
implementation of ASP.NET.

Here's a good article that might help as well:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvbdev01/h
tml/vb01g10.asp

Jim Cheshire, MCSE, MCSD [MSFT]
Developer Support
ASP.NET
(e-mail address removed)

This post is provided as-is with no warranties and confers no rights.

--------------------
From: "Invalidlastname" <[email protected]>
References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
Subject: Re: ASP.NET and shared assemblies
Date: Thu, 4 Dec 2003 09:06:49 -0500
Lines: 216
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.3790.0
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
Message-ID: <#[email protected]>
Newsgroups: microsoft.public.dotnet.framework.aspnet
NNTP-Posting-Host: dc.cvent.com 65.117.187.221
Path: cpmsftngxa07.phx.gbl!cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.
phx.gbl
Xref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.framework.aspnet:194372
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet

Jim,
Again, thank you for giving me such detailed explanations. It is really
helpful.



Jim Cheshire said:
ILN,

Yes, you would have to reload the app domain. ASP.NET is written
explicitly so that it doesn't rebind to assemblies directly on each need.
If it had to do that, it would cause a critical bottleneck.

The first thing that happens in the binding order is that the CLR says,
"Have I bound to this assembly already?" If the answer is Yes, it simply
uses the previous binding.

Jim Cheshire, MCSE, MCSD [MSFT]
Developer Support
ASP.NET
(e-mail address removed)

This post is provided as-is with no warranties and confers no rights.

--------------------
From: "Invalidlastname" <[email protected]>
References: <[email protected]>
<[email protected]>
<[email protected]>
Subject: Re: ASP.NET and shared assemblies
Date: Wed, 3 Dec 2003 11:26:10 -0500
Lines: 527
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.3790.0
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.aspnet
NNTP-Posting-Host: dc.cvent.com 65.117.187.221
Path:
cpmsftngxa06.phx.gbl!cpmsftngxa09.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top