Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullReferenceException when trying to login on macOS and iOS (MAUI) #586

Open
8 of 24 tasks
IcySnex opened this issue Apr 1, 2023 · 4 comments
Open
8 of 24 tasks

Comments

@IcySnex
Copy link

IcySnex commented Apr 1, 2023

I've:

Issue category

  • Bug
  • Feature Request
  • Missing Feature
  • Question
  • Not sure

Language

  • C#
  • VB.NET

Usage

  • Windows Form/Console app
  • WPF app
  • Asp .NET MVC
  • Asp .NET Core
  • Universal Windows Platform [UWP]
  • Xamarin or Xamarin Forms
  • Mono
  • MAUI

Operating System

  • Windows
  • Windows Server
  • Linux
  • Mac OS
  • iOS

Debug logs

macOS and iOS:
2023-04-01 14:10:27.507 MyApp[1867:31285] Exception: System.NullReferenceException: Object reference not set to an instance of an object.
at InstagramApiSharp.API.InstaApi.LoginAsync(Boolean isNewLogin)
2023-04-01 14:10:27.509 MyApp[1867:31285] Stacktrace: at InstagramApiSharp.API.InstaApi.LoginAsync(Boolean isNewLogin)

Describe your issue

This API wrapper is not correctly working on macOS or iOS while using MAUI.
Whenever trying to login with an Instagram account the API throws an exception: "Object reference not set to an instance of an object".
Tested the same application on Xamarin and it works.
This is the code I am currently using:

EntryInput.Text += "Starting...\n";
IInstaApi Api = InstaApiBuilder.CreateBuilder()
    .SetUser(UserSessionData
        .ForUsername("USER_NAME")
        .WithPassword("USER_PASSWORD"))
    .UseLogger(new DebugLogger(LogLevel.Exceptions))
    .Build();
EntryInput.Text += "Created API instance\n";

EntryInput.Text += "Loging in...\n";
var logInResult = await Api.LoginAsync();
EntryInput.Text += $"Fínished loging in: {logInResult.Info.Message}\n";

if (!logInResult.Succeeded)
{
    EntryInput.Text += $"Failed loging in: {logInResult.Info.Exception.Message}\n";
    return;
}

EntryInput.Text += $"Getting current user...\n";
var user = await Api.GetCurrentUserAsync();
EntryInput.Text += $"Got current user: {user.Info.Message}\n";

if (!user.Succeeded)
{
    EntryInput.Text += $"Failed getting user: {user.Info.Exception.Message}\n";
    return;
}

EntryInput.Text += $"User: {user.Value.UserName}\n";

As a quick note, this code on MAUI is fully working on Windows and Android. I dont know if this is a problem with my project setup but I am just using an empty template.

@ramtinak
Copy link
Owner

ramtinak commented Apr 9, 2023

Hey,
I think you have to update the csproj to net6.0 or 7.0, it might help you, because for now it's just netstandard2.0.

Also check for Bouncy Castle library or other libraries as well.

I don't have macos nor ios, so can't help you.

P.s: i accidently closed this, sorry.

@ramtinak ramtinak closed this as completed Apr 9, 2023
@ramtinak ramtinak reopened this Apr 9, 2023
@IcySnex
Copy link
Author

IcySnex commented Apr 10, 2023

Normally netstandard2.0 packages support all net versions and frameworks including net6.0 and net7.0 and I mean it works on Windows and Android with MAUI.
I think MAUI on iOS and macOS currently doesn't support on of the used dependencies by the wrapper.
I can't really debug the wrapper to find the exact issue because I am using macOS in a virtual machine and the performance is AWFUL. Im just using it to build .ipa files for iOS.

I really wanted to try this new MAUI thing everyone is hyped about for the app I'm currently developing but I have already switched to Xamarin because of this issue and Xamarin is fine.

Also Two-Factor Authorization Login is not correctly working. It keeps saying "Check security code" even tho it is correct. Tested with 2FA-App and 2FA-SmS options enabled on the Instagram Account. I used the sample project on Windows.

@MCvel
Copy link

MCvel commented May 19, 2023

I have the same issue with Macos and iOS, does anybody found any workaround?

@IcySnex
Copy link
Author

IcySnex commented May 21, 2023

I did not find any workaround. Only thing you can do is switch API wrappers (which is very hard since there arent really any updated usable wrappers) or use Xamarin instead of MAUI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants