Skip to content

Commit 3ea8974

Browse files
committed
TgSharp.TL: fix invalid Context type initialization for TLVector
Fixes #15
1 parent 73313ae commit 3ea8974

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

src/TgSharp.TL/ObjectDeserializer.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public class ObjectUtils
1212
public static object DeserializeObject(BinaryReader reader)
1313
{
1414
int Constructor = reader.ReadInt32();
15+
1516
object obj;
1617
Type t = null;
1718
try
@@ -21,8 +22,9 @@ public static object DeserializeObject(BinaryReader reader)
2122
}
2223
catch (Exception ex)
2324
{
24-
throw new InvalidDataException("Constructor Invalid Or Context.Init Not Called !", ex);
25+
throw new InvalidDataException("Invalid constructor, or invalid TLContext static initialization", ex);
2526
}
27+
2628
if (t.IsSubclassOf(typeof(TLMethod)))
2729
{
2830
((TLMethod)obj).DeserializeResponse(reader);

src/TgSharp.TL/TLContext.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,19 @@ static TLContext()
1919
where t.IsSubclassOf(typeof(TLObject))
2020
where t.GetCustomAttribute(typeof(TLObjectAttribute)) != null
2121
select t).ToDictionary(x => ((TLObjectAttribute)x.GetCustomAttribute(typeof(TLObjectAttribute))).Constructor, x => x);
22-
Types.Add(481674261, typeof(TLVector<>));
22+
23+
24+
var vectorTypeId = 481674261;
25+
var genericVectorType = typeof (TLVector<>);
26+
27+
Type type;
28+
if (Types.TryGetValue(vectorTypeId, out type)) {
29+
if (type != genericVectorType && type != typeof(TLVector)) {
30+
throw new InvalidOperationException ($"Type {vectorTypeId} should have been a TLVector type but was {type}");
31+
}
32+
} else {
33+
Types [vectorTypeId] = genericVectorType;
34+
}
2335
}
2436

2537
public static Type getType(int Constructor)

0 commit comments

Comments
 (0)