Loading an assembly locks the file

I am implementing a .DLL loader/updater for a piece of software that we have out on multiple client machines. We need to check the version of files on the machine and then pass that to SQL in order to determine if the files are the latest version - we have a folder structure like this:

-- Application

--- Files

---- SubFolder

----- Loader.exe

The loader .exe gets a List(of FileInfo) from the application folder. There are various assemblies in this folder and to get the version of the assemblies in order to check, I am using Assembly.LoadFile(x.FullName).GetName().Version and by using this, if a file requires an update or access later on the loader.exe has the file in use. I am getting the information into a datatable which I am then passing to a stored procedure in SQL.

Dim dt As New DataTable("ModuleTableVariable")
dt.Columns.Add("ModuleName")
dt.Columns.Add("ModuleVersion")
Dim rows As List(Of DataRow) = fileList.Select(Function(x)
                                                 Dim row = dt.NewRow()
                                                 row("ModuleName") = x.Name
                                                 If x.Extension = ".dll" Or x.Extension = ".exe" Then
                                                   row("ModuleVersion") = Assembly.LoadFile(x.FullName).GetName().Version
                                                 Else
                                                   row("ModuleVersion") = x.CreationTime
                                                 End If
                                                 Return row
                                               End Function).ToList()

So obviously the section which I am refering to the assembly version is where I need to change or implemnent some sort of using statement which will dispose the access to the file in question, any thoughts?

Note: I will accept answers in C# too if you show a suitable using statement or solution, doesn't have to be the full LINQ.

Answers


Found what I needed

AssemblyName.GetAssemblyName("filename.exe").Version 

Using this doesn't load the entire assembly only the information I need which means that it doesn't lock the file. Thanks for everybody's suggestions.


Need Your Help

3des encryption in iPhone padding issue

iphone ios encryption 3des

I have a problem using 3DES encryption in my iPhone app. I have 9 byte message to be encrypted. When I use kCCOptionECBMode, the first 8 byte block is encrypted correctly (I have a sample result pr...

GIT and having multiple configuration files on Heroku

git heroku

I have a development and production environments on Heroku, Both Apps use ClearDB but require unique credentials (i.e. 2 apps --> 2 DBs --> 2 unique credentials). We use a centralized Github repo to

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.