From 049b2081ec451e5d4a4c990d01167081feca0e03 Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Tue, 15 Sep 2020 23:46:30 +0200 Subject: [PATCH] Update SessionBase.cs Use of Fallback form has been missed in Session loading. Added now. --- TelegramBotBase/SessionBase.cs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/TelegramBotBase/SessionBase.cs b/TelegramBotBase/SessionBase.cs index e0648c9..9cf8da6 100644 --- a/TelegramBotBase/SessionBase.cs +++ b/TelegramBotBase/SessionBase.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; using TelegramBotBase.Args; @@ -132,15 +134,18 @@ namespace TelegramBotBase var form = t.GetConstructor(new Type[] { })?.Invoke(new object[] { }) as FormBase; - //No default constructor + //No default constructor, fallback if (form == null) { - form = Activator.CreateInstance(t) as FormBase; - - if (form == null) - { + if (!statemachine.FallbackStateForm.IsSubclassOf(typeof(FormBase))) continue; - } + + form = statemachine.FallbackStateForm.GetConstructor(new Type[] { })?.Invoke(new object[] { }) as FormBase; + + //Fallback failed, due missing default constructor + if (form == null) + continue; + }