The following is a basic example of how this system works:
C:\MyApp\Application1.exe
C:\MyApp\MyMonitor.exe
In SQL Server, we keep an EXE (Application1.exe) file stored as
binary.
I read this out of SQL Server into a byte[] array (through
MyMonitor.exe) and then pass to a function for Version.
Here's the kicker.. As soon as the function loads the binary image
retreieved from SQL Server, it *locks* the local "Application1.exe"
running out of the same directory.
I'm puzzled by 2 things:
1) why does the local Application1.exe get locked when I'm loading a
secondary app domain with a byte array from SQL?
2) Let's say technically it's a bug, and it's using the
"Application1.exe" from the local folder--then why is it not released
when I unload the secondary application domain?
When I terminate "MyMonitor.exe" I can then copy a newer build over
the existing "Application1.exe" file. If I comment out the section
that deals with loading the Byte[] array, I can copy a newer build
over the existing file. However, my design is flawed in some way or
this is a bug.
Any help appreciated.
Here's the GetAssemblyVersion Function:
pprivate string GetAssemblyVersion(byte[] inBytes)
{
string strVersion = "";
try
{
AppDomain secDomain = AppDomain.CreateDomain("SecondaryDomain",
null, null);
int iStart = 0;
int iStop = 0;
secDomain.Load(inBytes);
Assembly[] oList = secDomain.GetAssemblies();
iStart = oList[0].FullName.IndexOf("Version") + 8;
iStop = oList[0].FullName.IndexOf(",", iStart);
strVersion = oList[0].FullName.Substring(iStart, (iStop - iStart));
AppDomain.Unload(secDomain);
}
catch (Exception e1)
{
MessageBox.Show("Error encountered Reading Assembly Info: " +
e1.ToString());
}
return strVersion;
}