I have a SFX(self-extracting executable) file in windows (Created with zip tools like 7z, WinRar, ....) with the following details:

I want to get CopyRight text in C#, So I wrote the following code:
var fileVersionInfo = FileVersionInfo.GetVersionInfo(filePath);
Console.Write(fileVersionInfo.LegalCopyright)
fileVersionInfo.LegalCopyright is always empty!
What's the problem?
Edit:
My original Code:
var fileVersionInfo = FileVersionInfo.GetVersionInfo(filePath1);
var properties = typeof(FileVersionInfo).GetProperties(BindingFlags.Public | BindingFlags.Instance);
foreach (var propertyInfo in properties)
{
var value = propertyInfo.GetValue(fileVersionInfo);
Console.WriteLine("{0} = {1}", propertyInfo.Name, value);
}
Console.ReadKey();
The result:

(My reputation is too low to make a comment, so i post it here)
I have just tested the following code, and it works normally for me.
var fileVersionInfo = FileVersionInfo.GetVersionInfo(@"C:\Users\usr\Desktop\Game\steamIntegration\steam_api.dll");
Console.Write(fileVersionInfo.LegalCopyright);
Console.ReadLine();
Maybe your permissions are not sufficient enough for that file. Add a *.manifest to your project change the requestedExecutionLevel to:
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
Maybe that solves your problem.
The behavior you observe is due to a shortcoming in the implementation of the private function GetVersionInfoForCodePage in line 411 of the Microsoft.NET framework class FileVersionInfo, currently in version 4.6.2 and likely much earlier:
// fileVersion is chosen based on best guess. Other fields can be used if appropriate.
return (fileVersion != string.Empty);
This citation from reference source (comment theirs) means that the function will give up an otherwise correctly guessed codepage-specific version info, if its fileVersion member is empty (that of the block, not that in the header, which adds to the confusion).
This is the case with your exe file:

When we patch the framework to use this instead...
return (productVersion != string.Empty);
...it works as expected (tested in both console and Windows application):

So two options:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With