From a8743aa5c7d0b5f3a3efd0670be7e89da96de6f8 Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Sun, 28 Jan 2024 14:20:31 +0700 Subject: Tolerate missing assembly attributes - mainly for third party builds that neglect to add the attributes - see https://github.com/bcgit/bc-csharp/issues/495 --- crypto/src/bcpg/ArmoredOutputStream.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/crypto/src/bcpg/ArmoredOutputStream.cs b/crypto/src/bcpg/ArmoredOutputStream.cs index 37dcf2340..03d4a1a91 100644 --- a/crypto/src/bcpg/ArmoredOutputStream.cs +++ b/crypto/src/bcpg/ArmoredOutputStream.cs @@ -133,9 +133,14 @@ namespace Org.BouncyCastle.Bcpg private static string CreateVersion() { var assembly = Assembly.GetExecutingAssembly(); - var title = assembly.GetCustomAttribute().Title; - var version = assembly.GetCustomAttribute().InformationalVersion; - return title + " v" + version; + + var titleAttr = assembly.GetCustomAttribute(); + var versionAttr = assembly.GetCustomAttribute(); + + if (titleAttr == null || versionAttr == null) + return "BouncyCastle (unknown version)"; + + return titleAttr.Title + " v" + versionAttr.InformationalVersion; } private static readonly string Version = CreateVersion(); -- cgit 1.4.1