TgSharp.TL: fix invalid Context type initialization for TLVector

Fixes https://github.com/nblockchain/TgSharp/issues/15
This commit is contained in:
Andres G. Aragoneses 2020-09-13 18:18:28 +08:00
parent 73313ae199
commit 3ea897402c
2 changed files with 16 additions and 2 deletions

View file

@ -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);

View file

@ -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)