无法构建自定义 HttpContent - 无法 AOT 程序集 (mtouch)
Custom HttpContent won't build - Could not AOT the assembly (mtouch)
我正在努力为使用 Xamarin Forms 中的 HttpClient (SendAsync) 上传视频创建进度指示器,我现在不得不寻求帮助。
上传本身和所有其他 API 调用工作正常,但是当我尝试创建自定义 HttpContent
来跟踪上传进度时,项目甚至不再构建.
Error MT3001: Could not AOT the assembly
'[...].iOS/obj/iPhone/Debug/build-iphone7.2-10.1.1/mtouch-cache/Build/theproject.dll'
(MT3001) (theproject.iOS)
使用 StreamContent 或 ByteArrayContent 代替项目构建,但我无法让它工作以跟踪进度。
一段代码(这是最小的例子):
public class ProgressableContent : HttpContent
{
private const int defaultBufferSize = 4096;
private Stream content;
private int progress;
public ProgressableContent(Stream content)
{
this.content = content;
}
protected override Task SerializeToStreamAsync(Stream stream, TransportContext context)
{
return Task.Run(async () =>
{
var buffer = new byte[defaultBufferSize];
var size = content.Length;
var uploaded = 0;
using (content) while (true)
{
var length = content.Read(buffer, 0, buffer.Length);
if (length <= 0) break;
uploaded += length;
progress = (int)((float)uploaded / size * 100);
await stream.WriteAsync(buffer, 0, length);
}
});
}
protected override bool TryComputeLength(out long length)
{
length = content.Length;
return true;
}
}
我通过将我的字节转换为流来使用它,希望是正确的:
//... building httpMessage.
httpMessage.Content = new ProgressableContent(await byteArrayContent.ReadAsStreamAsync());
//...
var response = await _httpClient.SendAsync(httpMessage, Cancellation.Token);
//...
问题:
我是否以某种方式导致错误?有 "better" 的方法吗?
还用 Xamarin.iOS 标记了这个,因为 monotouch 正在抱怨。
双击来自 XS 的错误,它应该会将您带到一个网页,其中提供了有关该问题的更多描述。例如
MT3001 无法 AOT 程序集 '*'
This generally indicates a bug in the AOT compiler. Please file a bug
http://bugzilla.xamarin.com with a project that can be used to
reproduce the error.
Sometimes it's possible to work around this by disabling incremental
builds in the project's iOS Build option (but it's still a bug, so
please report it anyways).
关于 3001
的主要问题是 AOT 编译器没有生成 output 二进制文件。这可能有几个原因。通常,进程崩溃,构建日志会提供更多详细信息。
更重要的是在错误报告中附加一个独立的测试用例。除了您粘贴的代码之外,还有其他因素可能在导致崩溃中发挥重要作用(并且可能无法复制或猜测那部分可能是什么)。这也让我们有更好的机会提出问题的解决方法。
我正在努力为使用 Xamarin Forms 中的 HttpClient (SendAsync) 上传视频创建进度指示器,我现在不得不寻求帮助。
上传本身和所有其他 API 调用工作正常,但是当我尝试创建自定义 HttpContent
来跟踪上传进度时,项目甚至不再构建.
Error MT3001: Could not AOT the assembly '[...].iOS/obj/iPhone/Debug/build-iphone7.2-10.1.1/mtouch-cache/Build/theproject.dll' (MT3001) (theproject.iOS)
使用 StreamContent 或 ByteArrayContent 代替项目构建,但我无法让它工作以跟踪进度。
一段代码(这是最小的例子):
public class ProgressableContent : HttpContent
{
private const int defaultBufferSize = 4096;
private Stream content;
private int progress;
public ProgressableContent(Stream content)
{
this.content = content;
}
protected override Task SerializeToStreamAsync(Stream stream, TransportContext context)
{
return Task.Run(async () =>
{
var buffer = new byte[defaultBufferSize];
var size = content.Length;
var uploaded = 0;
using (content) while (true)
{
var length = content.Read(buffer, 0, buffer.Length);
if (length <= 0) break;
uploaded += length;
progress = (int)((float)uploaded / size * 100);
await stream.WriteAsync(buffer, 0, length);
}
});
}
protected override bool TryComputeLength(out long length)
{
length = content.Length;
return true;
}
}
我通过将我的字节转换为流来使用它,希望是正确的:
//... building httpMessage.
httpMessage.Content = new ProgressableContent(await byteArrayContent.ReadAsStreamAsync());
//...
var response = await _httpClient.SendAsync(httpMessage, Cancellation.Token);
//...
问题: 我是否以某种方式导致错误?有 "better" 的方法吗?
还用 Xamarin.iOS 标记了这个,因为 monotouch 正在抱怨。
双击来自 XS 的错误,它应该会将您带到一个网页,其中提供了有关该问题的更多描述。例如
MT3001 无法 AOT 程序集 '*'
This generally indicates a bug in the AOT compiler. Please file a bug http://bugzilla.xamarin.com with a project that can be used to reproduce the error.
Sometimes it's possible to work around this by disabling incremental builds in the project's iOS Build option (but it's still a bug, so please report it anyways).
关于 3001
的主要问题是 AOT 编译器没有生成 output 二进制文件。这可能有几个原因。通常,进程崩溃,构建日志会提供更多详细信息。
更重要的是在错误报告中附加一个独立的测试用例。除了您粘贴的代码之外,还有其他因素可能在导致崩溃中发挥重要作用(并且可能无法复制或猜测那部分可能是什么)。这也让我们有更好的机会提出问题的解决方法。