Guarantee reload of assembly when change is made on network share
- From: "savajx1" <savarino.je@xxxxxxx>
- Date: 13 Jan 2007 09:19:44 -0800
I am implementing a distrubuted application as a set of windows
services. A single windows service is to be installed on the
enterprise client workstations. In order to be able to maintain a
single codebase I load the code for the windows service from a network
share. I need to be able to readily replace any of the assemblies
(*.dlls) that implement the service. As a consequence, I used an
approach that I think that was initially suggested by Suzanne Cook and
loaded my application into a separate application domain (SEE CODE AT
END OF THIS MESSAGE). This approach works fine, with what appears to
be a single exception. I was debugging this service and I could not get
the VS2005 debugger to load/use the revised code (*.dll). It kept on
using the old copy. I made sure that I changed the assembly file
attribute (i.e [assembly: AssemblyFileVersion("2.0.2007.5")]) in both
the service *.exe and the *.dll in which I was implementing the code
change. I eventually found the local subdirectory that the .Net
application was using to load the code(something like
\..\LocalSettings\...\dl3). If I manually deleted this subdirectory,
then the new (revised) code loaded and I could properly debug the
application.
AND FINALLY I CAN GET TO THE POINT/Question!
This is a scientific application and I need to guarantee that when I
replace a *.dll on the file network share that the client service uses
the revised *.dll. I am assuming that it is my use of the "shadow copy"
that caused .Net to maintain the local "cached" copy on the client
workstation. Unlike most enterprise appplications, Like a lot of
programmers, I only have partial control of these departmental
workstations. I have been running this application as a
non-distrubuted application for over 2 years. In this instance since I
have total control of my servers I can easilly make changes, replace
the *.dll in the GAC , and restart the windows service. This is not
your normal enterprise application in the sense that I get changes
weekly and am normally expected to have simple model changes made and
implemented on the same day. There is some flexibility on this but not
much.
Can anyone suggest an approach that would guarantee that when I copy a
new *.dll to the network share and restart the client services (I have
the windows service "sense" the file/version change and automatically
exit and restart ). If not, I'll deep six the "shadow copy" and then
need to signal all of the workstations to stop the service prior to
making a change.
Thanks in advance
Jim Savarino
Center For Health Studies, Group Health Cooperative
savarino.je@xxxxxxx
static void Main(string[] args)
{
if (AppDomain.CurrentDomain.FriendlyName !=
m_sSHADOW_APPDOMAIN)
{
CreateShadowCopyDomain();
}
else { RunApplication(); }
}
[SecurityPermissionAttribute(SecurityAction.Assert,
ControlAppDomain = true)]
private static void CreateShadowCopyDomain()
{
AppDomain oCurrentDom = AppDomain.CurrentDomain;
AppDomainSetup oDomSetup = new AppDomainSetup();
oDomSetup.ApplicationBase =
AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
oDomSetup.ShadowCopyFiles = "true";
System.Security.PermissionSet fullTrust = new
System.Security.PermissionSet(PermissionState.Unrestricted);
fullTrust.AddPermission(new
SecurityPermission(SecurityPermissionFlag.Execution));
System.Reflection.Assembly ass =
Assembly.GetEntryAssembly();
StrongName sn = GetStrongName(ass.GetName());
AppDomain oNewDom =
AppDomain.CreateDomain(m_sSHADOW_APPDOMAIN, oCurrentDom.Evidence,
oDomSetup, fullTrust, sn);
oNewDom.ExecuteAssemblyByName( ass.FullName);
}
Jim Savarino
.
- Prev by Date: Installer putting asssemblies in GAC, but app does not see them?!
- Next by Date: Re: Data caching with multiple HTTPApplication instances
- Previous by thread: Installer putting asssemblies in GAC, but app does not see them?!
- Next by thread: Re: Data caching with multiple HTTPApplication instances
- Index(es):
Relevant Pages
|