From b43e3ab39a6ab9b954bc3a5dc39cfbc889e0f422 Mon Sep 17 00:00:00 2001 From: Sergey Gut Date: Thu, 6 Jun 2024 02:03:12 +0300 Subject: [PATCH] also need export Telegram types --- Core/Service/CoreManager.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Core/Service/CoreManager.cs b/Core/Service/CoreManager.cs index b082b6b..c5a40b9 100644 --- a/Core/Service/CoreManager.cs +++ b/Core/Service/CoreManager.cs @@ -2,7 +2,9 @@ using Kruzya.TelegramBot.Core.Attributes; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using Newtonsoft.Json; using System; +using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.Threading; @@ -47,7 +49,20 @@ namespace Kruzya.TelegramBot.Core.Service .Where(definedType => definedType.GetAttribute() != null) .ToDictionary(type => type.GetAttribute().Name); - foreach (var pair in allowedSerializationTypes) + // Also need allow any Telegram Bot API type. + var telegramTypes = typeof(Telegram.Bot.Types.Update).Assembly.ExportedTypes + .Where(definedType => definedType.GetAttribute() != null) + .ToDictionary(type => type.FullName); + + var mergedDictionaryTypes = new List> + { + telegramTypes, + allowedSerializationTypes + } + .SelectMany(dict => dict) + .ToDictionary(pair => pair.Key, pair => pair.Value); + + foreach (var pair in mergedDictionaryTypes) { binder.RegisterAllowedType(pair.Key, pair.Value); }