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:
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.
Found what I needed
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.