1

In my efforts to create a progress indicator for uploading videos using HttpClient (SendAsync) in Xamarin Forms, I now have to ask for assistance.

The upload itself works fine, and all other API calls, but when I try to create a custom HttpContent to track the progress of the upload the project won't even build any more.

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)

Using StreamContent or ByteArrayContent instead the project builds, but I can't get it working to track the progress.

A snippet of code (this is minimal example):

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;
    }
}

I use this by transforming my byte's to a stream, hopefully correctly:

//... building httpMessage.
httpMessage.Content = new ProgressableContent(await byteArrayContent.ReadAsStreamAsync());
//...
var response = await _httpClient.SendAsync(httpMessage, Cancellation.Token);
//...

The question(s): Am I somehow causing the error? Is there a "better" way to do this?

Tagged this with Xamarin.iOS also since monotouch is complaining.

Mackan
  • 6,200
  • 2
  • 25
  • 45
  • 1
    Which Version of `Xamarin.iOS` are you using? Does disabling incremental build help? Checkout this and the linked issues : https://bugzilla.xamarin.com/show_bug.cgi?id=43689 – SushiHangover Nov 11 '16 at 13:02
  • @SushiHangover Xamarin.iOS ver. 10.2.0.4 (Xamarin Indie), incremental build is not enabled. – Mackan Nov 11 '16 at 13:12

1 Answers1

2

Double-click on the error from XS and it should bring you to a web page that provide more description about the issue. E.g.

MT3001 Could not AOT the assembly '*'

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).

The main thing about 3001 is that the AOT compiler did not produce an output binary. There can be several reasons for this. Generally the process crashed and the build logs will give a bit more details why.

Even more important is to attach a self-contained test case to the bug report. Something else, beside the code you pasted, can be playing an important part that led to the crash (and it could be impossible to duplicate or guess what that piece could be). That also gives us a better chance to suggest a workaround to the issue.

poupou
  • 43,413
  • 6
  • 77
  • 174
  • I did follow the link first thing, but I got the feeling it was a very "generic" answer. The reason I posted here was to find out if this was a known limitation of the http library, or if my code was somehow to blame. I'll try and report it as a bug, and hopefully my question can generate some alternative methods. Thanks. – Mackan Nov 11 '16 at 13:50
  • Yes, it's a fairly generic answer because it's a generic error code (something went wrong when AOT'ing). What you posted is only the tip of the iceberg (the error) and no one (even us at xamarin) can provide a more accurate answer without what I asked above. Now `MT3001` are **always** bugs because (even if there's an issue in your code) we should be able to report a better, accurate, error. – poupou Nov 11 '16 at 14:57
  • I understand. Just a small FYI that I just noticed: The project builds and runs fine on the simulator (v10.1), but not on my phone (v10.1.1). I'll try and get that self-contained test case done and report it through the right channels during the weekend. – Mackan Nov 11 '16 at 19:41