Skip to content

Commit

Permalink
TgSharp.TL: fix invalid Context type initialization for TLVector
Browse files Browse the repository at this point in the history
Fixes #15
  • Loading branch information
knocte committed Sep 13, 2020
1 parent 73313ae commit 3ea8974
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/TgSharp.TL/ObjectDeserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class ObjectUtils
public static object DeserializeObject(BinaryReader reader)
{
int Constructor = reader.ReadInt32();

object obj;
Type t = null;
try
Expand All @@ -21,8 +22,9 @@ public static object DeserializeObject(BinaryReader reader)
}
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);
Expand Down
14 changes: 13 additions & 1 deletion src/TgSharp.TL/TLContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,19 @@ static TLContext()
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)
Expand Down

0 comments on commit 3ea8974

Please sign in to comment.