From 403969356f2ee8c52495ff41f440c2c5e7c78a57 Mon Sep 17 00:00:00 2001 From: Wizou <11647984+wiz0u@users.noreply.github.com> Date: Mon, 7 Feb 2022 22:06:10 +0100 Subject: [PATCH] Fix InvalidCast when reading an enum vector --- src/TL.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/TL.cs b/src/TL.cs index b7395bc..1d99702 100644 --- a/src/TL.cs +++ b/src/TL.cs @@ -201,8 +201,12 @@ namespace TL { int count = reader.ReadInt32(); Array array = (Array)Activator.CreateInstance(type, count); - for (int i = 0; i < count; i++) - array.SetValue(reader.ReadTLValue(elementType), i); + if (elementType.IsEnum) + for (int i = 0; i < count; i++) + array.SetValue(Enum.ToObject(elementType, reader.ReadTLValue(elementType)), i); + else + for (int i = 0; i < count; i++) + array.SetValue(reader.ReadTLValue(elementType), i); return array; } else if (ctorNb < 1024 && !elementType.IsAbstract && elementType.GetCustomAttribute() is TLDefAttribute attr)