Skip to content

System.InvalidCastException thrown when parsing some torrent files #39

@FrankChen021

Description

@FrankChen021
var parser = new BencodeParser(); 
var torrent = parser.Parse<Torrent>(torrentFile);

i use above codes to parse torrent files. It works ok for most files, but fails for some while there's an exception thrown from Parse method as below

System.InvalidCastException: Not all elements are of type 'BencodeNET.Objects.BList'.  ---> 
System.InvalidCastException: Unable to cast object of type 'BencodeNET.Objects.BString' to type 'BencodeNET.Objects.BList'.    
at System.Linq.Enumerable.CastIterator[TResult](IEnumerable source)+MoveNext()   
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)   
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)    
at BencodeNET.Objects.BList`1..ctor(IEnumerable`1 objects)   
at BencodeNET.Objects.BList.AsType[T]()    --- End of inner exception stack trace ---    
at BencodeNET.Objects.BList.AsType[T]()    
at BencodeNET.Parsing.TorrentParser.ParseTrackers(BDictionary data, Encoding encoding)    at BencodeNET.Parsing.TorrentParser.CreateTorrent(BDictionary data)   
at BencodeNET.Parsing.TorrentParser.Parse(BencodeStream stream)    
at BencodeNET.Parsing.BencodeParser.Parse[T](Stream stream)   
at BencodeNET.Parsing.BencodeParser.Parse[T](String filePath)    
at

i've tried convert those failed torrent files to magnetic links on some sites( eg: http://www.torrent2magnet.com/) , there's no exception reported by those sites.

the version of BencodeNET i used is version 2.3.0.

the attachment is a torrent file which causes the exception:

Bumblebee 2018 BluRay 1080p AVC Atmos TrueHD7.1 (2).torrent.zip

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions