首页 > 解决方案 > Xamarin Forms - Epub:System.AggregateException:发生一个或多个错误

问题描述

我正在将我的 epub 文件 URL 转换为流并保存到本地数据库,如下所示:

Stream stream;
HttpClient client = new HttpClient();
var response = await client.GetAsync(fileUrl);
stream = await response.Content.ReadAsStreamAsync();
epubBook = EpubReader.ReadBook(stream);

//saving to folder
byte[] bytes = await response.Content.ReadAsByteArrayAsync();
string filename = Path.GetFileName(fileUrl);
var folderPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
var filePath = Path.Combine(folderPath, filename);
File.WriteAllBytes(filePath, bytes);

这适用于大多数文件。但一些文件 URL 显示System.AggregateException.

异常详情

System.AggregateException:发生一个或多个错误。(版本号“1.1”无效。第 1 行,位置 16。)---> System.Xml.XmlException:版本号“1.1”无效。第 1 行,位置 16。在 System.Xml.XmlTextReaderImpl.Throw (System.Exception e) [0x00027] in <0757e7484a1349cca3b4558c721885b2>:0 在 System.Xml.XmlTextReaderImpl.Throw (System.String res, System.String arg) [0x00029 ] in <0757e7484a1349cca3b4558c721885b2>:0 at System.Xml.XmlTextReaderImpl.ParseXmlDeclaration (System.Boolean isTextDecl) [0x0061f] in <0757e7484a1349cca3b4558c721885b2>:0 at System.Xml.XmlTextReaderImpl.Read () [0x000c6] in <0757e7484a1349cca3b4558c721885b2>:0 at <89374192b20a41739cf7c5bb822846fe> 中的 System.Xml.Linq.XDocument.Load(System.Xml.XmlReader 阅读器,System.Xml.Linq.LoadOptions 选项)[0x00016]:

存在此问题的示例文件 URL:

https://s3.us-east-1.amazonaws.com/catholic-brain/prod/dc/cbrain-app/files/doc-lib/2020/08/10/12/56/42/068/head/ 9781612781495_EPUB.epub

https://s3.us-east-1.amazonaws.com/catholic-brain/prod/dc/cbrain-app/files/doc-lib/2020/08/10/07/36/06/376/head/ 9781612781358_EPUB.epub

我正在使用EpubReader.Cross Nuget 来解析 epub 文件。

我已经上传了一个示例项目以方便参考。

标签: xamarin.formsstreamepub

解决方案


推荐阅读