473,394 Members | 1,709 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Releasing a file

During my program I load an exe file using reflection. My program loads the
file using reflection, checks the assembly version and does an update if the
network version is different from the local version. I have a problem,
however, when I do the first check using reflection to get the network
version, then it locks the file and I can't delete it. How long will the
program maintain a lock on the file using reflection? I am setting the
local application to nothing to release references but it does not release
the file. See Code. Thanks.

John Wright

Public Function CheckVersion() As Boolean

Dim strLocalVersion() As String

Dim strNetworkVersion() As String

Dim asmLocal As Assembly

Dim asmNetwork As Assembly

Try

'First check to make sure the paths are set, if not exit

If Trim(Len(strLocalAsm)) = 0 Or Trim(Len(strNetworkAsm)) = 0 Then

CheckVersion = False

Exit Function

End If

'check to see if the local version is present. If not copy the exe to the
localversion location

If File.Exists(strLocalAsm) = True Then

'Connect to the local and network version and check versions

'asmLocal = Assembly.LoadFile(strLocalAsm)

asmLocal = Assembly.ReflectionOnlyLoadFrom(strLocalAsm)

'asmNetwork = Assembly.LoadFile(strNetworkAsm)

asmNetwork = Assembly.LoadFile(strNetworkAsm)

strLocalVersion = Split(asmLocal.FullName, ",")

strNetworkVersion = Split(asmNetwork.FullName, ",")

'compare the versions

If Trim(strLocalVersion(1).ToString) <> Trim(strNetworkVersion(1).ToString)
Then

'drop the references to the files

asmLocal = Nothing

asmNetwork = Nothing

'update the local file

UpdateVersion()

CheckVersion = True

Else

CheckVersion = True

End If

Else

'the file does not exsist. just copy the network file

asmLocal = Nothing

asmNetwork = Nothing

UpdateVersion()

CheckVersion = True

End If

Catch ex As Exception

asmLocal = Nothing

asmNetwork = Nothing

objError.ReportError(ex, "VersionCheck.CheckVersion", 3)

CheckVersion = False

End Try

End Function

Private Sub UpdateVersion()

'TODO: Check to see if the folder exists first. Create it if not there

Try

strDirectory = Path.GetDirectoryName(strLocalAsm)

strFileName = Path.GetFileNameWithoutExtension(strLocalAsm)

'check to see if the directory exists, if not create the directory first

If System.IO.Directory.Exists(strDirectory) = False Then

Directory.CreateDirectory(strDirectory)

End If

'TODO: Check for usage and force close

file.Copy(strNetworkAsm, strLocalAsm, True) --This line give me a
permission error file in use.

Catch ex As FileNotFoundException

objError.ReportError(ex, "VersionCheck.UpdateVersion", 5, True, True)

Catch ex As System.IO.IOException

'File is in use, rename it and copy over the new version

file.Move(strLocalAsm, strDirectory & "\" & strFileName & ".old")

File.Copy(strNetworkAsm, strLocalAsm, True)

Catch ex As Exception

objError.ReportError(ex, "VersionCheck.UpdateVersion", 4, True, True)

End Try

End Sub
May 19 '06 #1
1 2230
On Fri, 19 May 2006 15:35:38 -0600, "John Wright"
<ri**********@notmail.com> wrote:
During my program I load an exe file using reflection. My program loads the
file using reflection, checks the assembly version and does an update if the
network version is different from the local version. I have a problem,
however, when I do the first check using reflection to get the network
version, then it locks the file and I can't delete it. How long will the
program maintain a lock on the file using reflection? I am setting the
local application to nothing to release references but it does not release
the file. See Code. Thanks.

John Wright


You need to load the assembly in a new application domain. It will
then make a copy (if you set ShadowCopyFiles to true) of the original
file and use that instead of locking the original file. If you're done
you can unload the application domain.

See
http://msdn.microsoft.com/library/de...rp05162002.asp

--
Ludwig Stuyck
http://www.coders-lab.be
May 20 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: lebo | last post by:
Hi I'm trying to understand how Python handles memory usage and dynamic object loading and unloading. Problem to solve? Build a very low memory footprint (non-GUI) Python application for...
31
by: poisondart | last post by:
Hi, I'm not sure if this is the right group to post this. If not, then I would appreciate if somebody could point me to the correct group. This is my first time releasing software to the...
18
by: lylefair | last post by:
Can you post code, or a reference to a md? or ad? file on a website, where object variables are not released when they go out of scope and cause a problem, (but causing a problem is extraneous to...
7
by: trialproduct2004 | last post by:
Hi all I am having application in c# where i am loading one table of database into dataset. My table is of large size. so whenever i am loading that into dataset my memory size is getting...
2
by: McGeeky | last post by:
Are there any best practices on releasing updates of an ASP.Net application to a virtual directory in a production environment? E.g. is it okay to simply copy over changes to ASP.Net pages in to...
0
by: Naved Ahmed | last post by:
In one of my project, I called ASP web service to convert some type of files. After conversion, web service is deleting that file. Still that file is shown by the windows Explorer (Even after...
2
by: B.N.Prabhu | last post by:
In my web application(C#) . I am adding one excel sheet and then save and closing that excel file. In the finally bloack i gave Marshal.ReleaseComObject(clsExcel); But when i go and see in the...
1
by: Patrick Finnegan | last post by:
Running DB2 9.1 on Redhat Linux 4.1. Storage management indicates that the pages stored in a file based SMS container occupy 7 gig of the total space allocated which is 50gig. I wrote a script...
3
by: ssylee | last post by:
For example, I have a BITMAPINFO* and a BYTE* object to release the resources. Would the most bulletproof way of doing so involve checking to see if they are null, then if they are not, invoke a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.