Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version.txt should use file version from assembly custom attributes not FileVersionInfo #4505

Open
r0ss88 opened this issue Nov 27, 2019 · 2 comments

Comments

@r0ss88
Copy link

@r0ss88 r0ss88 commented Nov 27, 2019

The changes made in issue #3132 have introduced a bug due to relying on a physical location for the assembly. If the Microsoft.ML.Core assembly is loaded from memory the assembly.location will be empty. Using FileVersionInfo.GetVersionInfo relies on a physical path - so an argument exception is thrown inside System.IO.Path since the supplied path is empty.

var versionInfo = FileVersionInfo.GetVersionInfo(typeof(RepositoryWriter).Assembly.Location);
using (var ent = rep.CreateEntry(DirTrainingInfo, "Version.txt"))
using (var writer = Utils.OpenWriter(ent.Stream))
writer.WriteLine(versionInfo.ProductVersion);

Instead of using FileVersionInfo.GetVersionInfo the assembly custom attributes should be used, for example:
var productVersion = assembly.CustomAttributes.FirstOrDefault(a => a.AttributeType == typeof(AssemblyFileVersionAttribute)).ConstructorArguments.First();

This will return the same product string version as the FileVersionInfo.GetVersionInfo does.

r0ss88 pushed a commit to r0ss88/machinelearning that referenced this issue Nov 29, 2019
…from FileVersionInfo and replace with using assembly custom attributes (dotnet#4505)
@codemzs

This comment has been minimized.

Copy link
Member

@codemzs codemzs commented Nov 30, 2019

thanks @r0ss88 . This seems like a good find but in what scenarios can we be loading this assembly from memory and it will not be present on disk?

@r0ss88

This comment has been minimized.

Copy link
Author

@r0ss88 r0ss88 commented Dec 2, 2019

thanks @r0ss88 . This seems like a good find but in what scenarios can we be loading this assembly from memory and it will not be present on disk?

Happy to contribute. In my scenario I am working with a system where assemblies can be loaded from disk or stored in a database. Though in this case they are loaded from disk the assembly is read as bytes then loaded - hence location is blank.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.