Xamarin.Forms application throws NullReferenceException only in iOS - xamarin

I'm creating a Xamarin.Forms Portable application that runs fine in Android but always crashes in iOS.
I get this error:
System.NullReferenceException: Object reference not set to an instance of an object at App.ListJson+<GetPodcasts>d__2.MoveNext () [0x0004e]
It occurs at this piece of code, on the second line:
var httpClient = new HttpClient();
var json = await httpClient.GetStringAsync(REDACTEDSTRING).ConfigureAwait(false);
I've tried fiddling with the HttpClient implementation settings for the iOS project but still get the same error.

The answer found here solved my problem.
To reiterate it here:
Installing the Microsoft.Net.Http NuGet package into the base project will fix the issue.

Related

Xamarin 5 UWP - Issue with DisplayAlert

Me and my team have just migrated our cross-platform XF 4 project to XF5.
The only issue that we have encountered thus far is the following:
Our UWP App was throwing an unhandled App.Xaml exception when navigating to a different page for no apparent reason and after some search, installing the nugget Microsoft.UI.Xaml explicitly fixed that issue, even though that nugget package is supposed to be installed along with XF5 nugget.
But right now a new issue has emerged. When calling the await Application.Current.MainPage.**DisplayAlert**(szTitle, szMessage, btnOk, btnCancel); from the UI thread the alert gets displayed properly but when I click on one of its buttons Ι get an unhandled exception
"No installed components were detected. The property path '(controls:AnimatedIcon.State)' could not be resolved for a Setter." where controls is defined as xmlns:controls="using:Microsoft.UI.Xaml.Controls"
Could you please help me find out what is going wrong?
As far as I know the DisplayAlert() is handled by Xamarin.Forms.

Using Xamarin Essentials in Xamarin UI Test project

I am trying to open Browser with a link inside my test method (application is launched prior to that). I installed Xamarin essentials Nuget, and per my current understanding I am not able to use this package outside xamarin project. I found some solutions (see below, using Mock object) but this does not seem to work.
var mockLaunch = new Mock();
IBrowser open = mockLaunch.Object;
open.OpenAsync("https://i389l.app.link/JFsYo6d1Y37", BrowserLaunchMode.SystemPreferred);
Does anyone have solution how to open browser (using real Android device) inside my test method? Thank you.

In which package can I find Xamarin IDevice

I am writing a Xamarin Forms PCL application (both iOS and Android)
I have to pick an image from phone gallery.
I have read some documentation about this plugin:
Labs.Platform.Services.Media.MediaPicker
In my Common project, i have to put this code:
var device = Resolver.Resolve<IDevice>();
picker = DependencyService.Get<IMediaPicker>() ?? device.MediaPicker;
But I have an error on the first line: IDevice and Resolver Objects are not know. I think I am missing a reference or a using clause.
Thanks
You need to install the following Nuget package in all of your projects in the solution (i.e. PCL core project, iOS project, and the Android Project, and UWP project if using it):
https://www.nuget.org/packages/XLabs.Forms/
And you will need to add the following using statements:
using XLabs.Ioc;
using XLabs.Platform.Device;
using XLabs.Platform.Services.Media;

Xamarin iOS Crash - Only when Apple reviews

I want to start off saying that I have reviewed the many posts about iOS app crashing only for Apple Review Team and I did not find a solution and also did find one with my crash log information.
This is a Xamarin.Forms project. I have a PCL with Droid and iOS projects. My Droid project works great. I have no issues there. My iOS project is where I am having issues. I can debug this without any hiccups. I have tested this on the various simulators via XCode and also multiple real devices. I constantly get my app rejected by Apple saying the app crashes when it does a certain action. I have tried numerous times to duplicate the crash but I cannot.
I have symbolicated the crash log from Apple and it can be viewed with this link. I do not see anywhere in the crash log that shows my code and what I did wrong. I think it has something to do with me doing async/await stuff but I cannot confirm this.
If it helps, I am using version 2.2.0.31 of Xamarin.
I am new to Apple crash logs and I find them very hard to decipher. Can someone please assist with helping figure out what I am doing wrong.
UPDATE
Included is the code that was requested.
iOS project -- Main.cs
public class Application
{
// This is the main entry point of the application.
static void Main(string[] args)
{
// if you want to use a different Application Delegate class from "AppDelegate"
// you can specify it here.
UIApplication.Main(args, null, "AppDelegate");
}
}
iOS project -- AppDelegate.cs
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.Init();
App.ScreenWidth = (int)UIScreen.MainScreen.Bounds.Width;
App.ScreenHeight = (int)UIScreen.MainScreen.Bounds.Height;
UINavigationBar.Appearance.TintColor = UIColor.FromRGB(40, 51, 65);
FormsMaps.Init();
AdvancedTimerImplementation.Init();
CachedImageRenderer.Init();
LoadApplication(new App());
return base.FinishedLaunching(app, options);
}
Shared project -- App.cs
public App()
{
//do the initial setup
var nav = new NavigationService();
if (!SimpleIoc.Default.IsRegistered<INavigationServiceEx>())
SimpleIoc.Default.Register<INavigationServiceEx>(() => nav);
var apiMgr = new ApiManager();
if (!SimpleIoc.Default.IsRegistered<ApiManager>())
SimpleIoc.Default.Register<ApiManager>(() => apiMgr);
var storageMgr = new StorageManager();
if (!SimpleIoc.Default.IsRegistered<StorageManager>())
SimpleIoc.Default.Register<StorageManager>(() => storageMgr);
var externalMaps = DependencyService.Get<IExternalMaps>();
if (!SimpleIoc.Default.IsRegistered<IExternalMaps>())
SimpleIoc.Default.Register<IExternalMaps>(() => externalMaps);
var mediaService = DependencyService.Get<IMedia>();
mediaService.Initialize();
if (!SimpleIoc.Default.IsRegistered<IMedia>())
SimpleIoc.Default.Register<IMedia>(() => mediaService);
var geolocationService = DependencyService.Get<IGeolocator>();
if (!SimpleIoc.Default.IsRegistered<IGeolocator>())
SimpleIoc.Default.Register<IGeolocator>(() => geolocationService);
nav.Configure(ViewModelLocator.StartupPage, typeof(StartupView));
nav.Configure(ViewModelLocator.LoginPage, typeof(LoginView));
nav.Configure(ViewModelLocator.RegisterPage, typeof(RegisterView));
nav.Configure(ViewModelLocator.QouponsPage, typeof(QouponsView));
nav.Configure(ViewModelLocator.UserProfilePage, typeof(UserProfileView));
nav.Configure(ViewModelLocator.EditUserProfilePage, typeof(EditUserProfileView));
nav.Configure(ViewModelLocator.CompanyPage, typeof(CompanyView));
nav.Configure(ViewModelLocator.RedeemPage, typeof(RedeemView));
nav.Configure(ViewModelLocator.SettingsPage, typeof(SettingsView));
nav.Configure(ViewModelLocator.HelpPage, typeof(HelpView));
var startupView = new StartupView();
var startupPage = new NavigationPage(startupView);
startupPage.BarBackgroundColor = Color.FromHex("#FF8A07");
nav.Initialize(startupPage);
startupView.Start();
MainPage = startupPage;
}
Something in your async code threw an exception, and there doesn't seem to be an exception handler for that exception (an exception without an exception handler will crash the process).
This is from your main thread where it shows the async runtime logic throwing the exception on the main thread:
13 QneoiOS 0x000000010023039c System_Runtime_ExceptionServices_ExceptionDispatchInfo_Throw + 44
14 QneoiOS 0x000000010022eea0 System_Runtime_CompilerServices_AsyncMethodBuilderCore__ThrowAsyncm__0_object + 80
15 QneoiOS 0x0000000100b3b798 UIKit_UIKitSynchronizationContext__Postc__AnonStorey0__m__0 (UIKitSynchronizationContext.cs:24)
16 QneoiOS 0x0000000100b55fd4 Foundation_NSAsyncActionDispatcher_Apply (NSAction.cs:163)
You need more details about this exception, the crash report doesn't contain enough information to diagnose further.
My suggestion would be to add a crash-reporting solution (such as Xamarin Insights), resubmit, and then you should get information about the exception in Xamarin Insights when the crash occurs during Apple's review.
I had a similar problem. Moved to Xamarin in Microsoft Studio and it worked on devices & simulator in debug and on simulator in release mode but was crashing in testflight and review. My solution was two things: I changed the linker setting to Link SDKs rather than Link All. I revoked by release certificate and recreated that with a new distribution provisioning profile. This fixed the problem for me. Hope it helps someone else.

Cordova platform add wp7 fail : Object #<Object> has no method 'config_xml'

I actually try to create a WP7 application with Apache Cordova, so I follow their documentation
I installed the WP7 SDK, added .NET Framework in my Path,
fix this bug.
And now when I try to run "cordova platform add wp7" I've this error message :
Checking wp7 requirements...
Creating WP7 project...
[TypeError: Object #<Object> has no method 'config_xml']
with -d option I get this :
TypeError: Object #<Object> has no method 'config_xml'
at C:\Users\Julien\AppData\Roaming\npm\node_modules\cordova\src\prepare.js:80:45
I use the basic project show in the Cordova doc to test it (HelloWorld).
Some idea to fix it ? because I searched but didn't found any solution...
Ask me if you need more infos on my configs.
I had the same issue with WP7 platform and everything seems updated (cordova -v => 3.2.0-0.3.0).
As a workaround, i add the following function to the %APPDATA%\npm\node_modules\cordova\src\metadata\wp7_parser.js:
config_xml:function() {
return this.config_path;
},
Projects compiling and running with no error so far.
I submitted this bug on the Cordova JIRA platform :
https://issues.apache.org/jira/browse/CB-5499
It will be solved in the 3.3.0 version of cordova.

Resources