From b58dcd7396f885690709329b84b523bcffb4e8b9 Mon Sep 17 00:00:00 2001 From: Christoph Wille Date: Mon, 29 Apr 2024 16:05:22 +0200 Subject: [PATCH] Make AboutPage AOT-friendlier --- ILSpy/AboutPage.cs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/ILSpy/AboutPage.cs b/ILSpy/AboutPage.cs index 1dcef578a..b796fa362 100644 --- a/ILSpy/AboutPage.cs +++ b/ILSpy/AboutPage.cs @@ -54,7 +54,7 @@ namespace ICSharpCode.ILSpy }; output.WriteLine(Resources.ILSpyVersion + DecompilerVersionInfo.FullVersion); - string prodVersion = System.Diagnostics.FileVersionInfo.GetVersionInfo(typeof(Uri).Assembly.Location).ProductVersion; + string prodVersion = GetDotnetProductVersion(); output.WriteLine(Resources.NETFrameworkVersion + prodVersion); output.AddUIElement( @@ -104,6 +104,27 @@ namespace ICSharpCode.ILSpy textView.ShowText(output); } + private static string GetDotnetProductVersion() + { + // In case of AOT .Location is null, we need a fallback for that + string assemblyLocation = typeof(Uri).Assembly.Location; + + if (!String.IsNullOrWhiteSpace(assemblyLocation)) + { + return System.Diagnostics.FileVersionInfo.GetVersionInfo(assemblyLocation).ProductVersion; + } + else + { + var version = typeof(Object).Assembly.GetName().Version; + if (version != null) + { + return version.ToString(); + } + } + + return "UNKNOWN"; + } + sealed class MyLinkElementGenerator : LinkElementGenerator { readonly Uri uri;