We help IT Professionals succeed at work.

Retrieving file version causes the file to remain open

freezingHot
freezingHot asked
on
644 Views
Last Modified: 2009-06-13
               string filename = @"\\UNC file name";
                Assembly asm = Assembly.LoadFile(filename);
                int tMajor = asm.GetName().Version.Major;
                int tMinor = asm.GetName().Version.Minor;
                int tBuild = asm.GetName().Version.Build;
                int tRevision = asm.GetName().Version.Revision;

the above method works fine for retrieving the build information; however, it keeps the file open.  

How can i close the file ( there is no dispose or close function on asm ) after I retrieve the version information?  Is there a better way or retrieving the version info?

Thanks for the help.
Comment
Watch Question

Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
as soon as .ReflectionOnlyLoadFrom() is executed, the file name is listed as Open in the file share list on the server.  when the application closes, the file is no longer listed as open.

unfortunately, the ReclectionOlyLoadFrom() is acting the same way.
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
having a heck of a time passing it the filename -

my filename is something like this:

string fileName = @"\\192.168.100.1\publicDrive\app.2007\application.2007.exe";

the domain.Load(fileName); is failing.  It says that it can not find the specified file.  the file does exist.  I tried to change the ApplicationBase in the AppDomainSetup variable, but that didn't help.

is there a better way to obtain version information from a file - it seems like a trivial task.

I appreciate your help.


Thanks.

CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008

Commented:
192.168.100.1 is a private network address, so does it fail if you don't use a UNC path with an IP address, and use a mapped network drive instead?

Bob

Author

Commented:
i receive, "could not load file or assembly or one of its dependencies.  The given assembly name or codebase was invalid. (HRESULT: 0X80131047)"
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008

Commented:
What code were you running when you got the exception (initial code or revised code from comment above)?

Bob

Author

Commented:
that's from the mapped network drive part.

Author

Commented:
i found this which works much better.  it places the initial lock on the file; however, it drops the open lock after the function has completed:

System.Diagnostics.FileVersionInfo fileVersInfo =  System.Diagnostics.FileVersionInfo.GetVersionInfo(filename);
int tMajor = fileVersInfo.FileMajorPart;
int tMinor = fileVersInfo.FileMinorPart;
int tBuild = fileVersInfo.FileBuildPart;
int tRevision = fileVersInfo.FilePrivatePart;

Author

Commented:
i appreciate the help from both of you - thanks again.  I awarded points to both for taking the time to help me out.

have a good one.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.