diff --git a/src/TgSharp.TL/ObjectDeserializer.cs b/src/TgSharp.TL/ObjectDeserializer.cs index 08d7b2b..564a927 100644 --- a/src/TgSharp.TL/ObjectDeserializer.cs +++ b/src/TgSharp.TL/ObjectDeserializer.cs @@ -12,6 +12,7 @@ namespace TgSharp.TL public static object DeserializeObject(BinaryReader reader) { int Constructor = reader.ReadInt32(); + object obj; Type t = null; try @@ -21,8 +22,9 @@ namespace TgSharp.TL } catch (Exception ex) { - throw new InvalidDataException("Constructor Invalid Or Context.Init Not Called !", ex); + throw new InvalidDataException("Invalid constructor, or invalid TLContext static initialization", ex); } + if (t.IsSubclassOf(typeof(TLMethod))) { ((TLMethod)obj).DeserializeResponse(reader); diff --git a/src/TgSharp.TL/TLContext.cs b/src/TgSharp.TL/TLContext.cs index 2d04707..b0c3c86 100644 --- a/src/TgSharp.TL/TLContext.cs +++ b/src/TgSharp.TL/TLContext.cs @@ -19,7 +19,19 @@ namespace TgSharp.TL where t.IsSubclassOf(typeof(TLObject)) where t.GetCustomAttribute(typeof(TLObjectAttribute)) != null select t).ToDictionary(x => ((TLObjectAttribute)x.GetCustomAttribute(typeof(TLObjectAttribute))).Constructor, x => x); - Types.Add(481674261, typeof(TLVector<>)); + + + var vectorTypeId = 481674261; + var genericVectorType = typeof (TLVector<>); + + Type type; + if (Types.TryGetValue(vectorTypeId, out type)) { + if (type != genericVectorType && type != typeof(TLVector)) { + throw new InvalidOperationException ($"Type {vectorTypeId} should have been a TLVector type but was {type}"); + } + } else { + Types [vectorTypeId] = genericVectorType; + } } public static Type getType(int Constructor)