From 2b86a79f7008c4f4fef49cec144c95d5e3bde23f Mon Sep 17 00:00:00 2001 From: Proddy Date: Sun, 4 Sep 2022 07:46:50 +0100 Subject: [PATCH] Fix a bug in EmbedBuilder.Length when there is an EmbedField with no Value (#2345) * Update EmbedBuilder.cs Fixes a bug where 'EmbedBuilder.Length' will throw an exception of type 'System.NullReferenceException' when a field doesn't have a value. * Update EmbedBuilder.cs Fixed an incorrect assuption that `Value` was a `string?` * Update EmbedBuilder.cs Fixed one more null check * Update EmbedBuilder.cs Co-authored-by: Quin Lynch <49576606+quinchs@users.noreply.github.com> --- src/Discord.Net.Core/Entities/Messages/EmbedBuilder.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Discord.Net.Core/Entities/Messages/EmbedBuilder.cs b/src/Discord.Net.Core/Entities/Messages/EmbedBuilder.cs index db38b9fb7..9b2a6adb9 100644 --- a/src/Discord.Net.Core/Entities/Messages/EmbedBuilder.cs +++ b/src/Discord.Net.Core/Entities/Messages/EmbedBuilder.cs @@ -150,7 +150,7 @@ namespace Discord int authorLength = Author?.Name?.Length ?? 0; int descriptionLength = Description?.Length ?? 0; int footerLength = Footer?.Text?.Length ?? 0; - int fieldSum = Fields.Sum(f => f.Name.Length + f.Value.ToString().Length); + int fieldSum = Fields.Sum(f => f.Name.Length + (f.Value?.ToString()?.Length ?? 0)); return titleLength + authorLength + descriptionLength + footerLength + fieldSum; }