Uros
Uros

Reputation: 2150

TypeLoadException: Could not load type from assembly in Xamarin

I have Xamarin Forms PCL application and I am trying to inherit from HttpContent in attempt to follow this reference. I would like to implement progress bar for image upload. Here is my implementation which contains minimum code to implement HttpContent:

public class ProgressableStreamContent : HttpContent
{
    public ProgressableStreamContent()
    { }

    protected override Task SerializeToStreamAsync(Stream stream, TransportContext context)
    {
        return Task.Run(async () =>
        {
        });
    }

    protected override bool TryComputeLength(out long length)
    {
        length = 0;
        return true;
    }
}

and I have procedure that is using this ProgressableStreamContent:

public async void UseProgressableStreamContent()
{
    var progressableContent = new ProgressableStreamContent();
}

Problem is that this code produces exception:

UNHANDLED EXCEPTION: System.TypeLoadException: Could not load type 'MyApp.Classes.ProgressableStreamContent' from assembly 'MyApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.

When I comment out line "var progressableContent = new ProgressableStreamContent();" - everything works good.

When I comment out inheritance ": HttpContent" (and override keywords) - everything works good.

Should I install some package? What else could be a problem?

Upvotes: 1

Views: 1777

Answers (1)

Uros
Uros

Reputation: 2150

I resolved issue by changing profile from 259 to 7. Changing profile includes deleting all NuGet packages and installing them again after profile change.

Upvotes: 1

Related Questions