xamarin android Google maps exception when closing page with map - xamarin.android

I have exception in xamarin forms – in android – when closing a custom map.
I am rendering it in android and once every 5~ times I get exception when closing the page with the google maps
The exception is as follows:
UNHANDLED EXCEPTION: System.NotSupportedException: Unable to activate instance of type Xamarin.Forms.Maps.Android.MapRenderer from native handle b250001d ---> System.MissingMethodException: No constructor found for Xamarin.Forms.Maps.Android.MapRenderer::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership) ---> Java.Interop.JavaLocationException: Exception of type 'Java.Interop.JavaLocationException' was thrown
I saw a post in stack overflow:
Error when navigating away from a page with a map on Android, while the on-screen keyboard is visible
and I tried to create a constructor like this:
public CustomMapRenderer(IntPtr javaReference, JniHandleOwnership jniHandleOwnership)
: base(javaReference, jniHandleOwnership) { }
But I get compilation error:
'MapRenderer' does not contain a constructor that takes 2 arguments
What is this error ??

Related

NativeScript iOS Delegate Transpilation error (Can't find variable: __metadata)

I'm attempting to implement an iOS delegate in a NativeScript plugin and am getting an error:
Terminating app due to uncaught exception 'NativeScript encountered a fatal error: ReferenceError: Can't find variable: __metadata
My original code is:
#ObjCClass(SQRDCheckoutControllerDelegate)
export class SquareReader extends NSObject implements SQRDCheckoutControllerDelegate {
/*
iOS delegate implementation here
(source https://docs.connect.squareup.com/payments/readersdk/setup-ios)
*/
}
And that's getting transpiled in js down to:
SquareReader = __decorate([
ObjCClass(exports.SQRDCheckoutControllerDelegate),
__metadata("design:paramtypes", [])
], SquareReader);
If I just remove the __metadata line, I get a different error:
Terminating app due to uncaught exception 'NativeScript encountered a fatal error: Error: Protocol "undefined" is not a protocol object.
Any ideas? I've seen other examples like nativescript-image-swipe where the code is being transpiled w/o the __metadata method leading me to think something might be wrong with the transpilation
I solved this by cleaning up my typings. I just re-ran the command to generate typings: TNS_TYPESCRIPT_DECLARATIONS_PATH="$(pwd)/typings" tns build ios and put them in my /src directory for my plugin. Once my typings were correct the project ran as expected and the Delegate worked

How can I save the fatalError message to the iOS crash log?

I have an iOS application written in Swift 2 in Xcode 8.2.1, that's built for iOS 10.2.
I've had a number of crash reports from TestFlight and despite symbolication, none of the crash logs show any program state besides the stack-traces (no argument values, no locals, no heap objects, etc).
...but inside those functions I can see code which is likely to fail (e.g. a forced unwrap) but the crash log isn't telling me where or why it's failing.
When debugging in Xcode, I can use fatalError(message: String) where I can put my own message like "functionFoo returned nil" or "variable bar == \"" + bar + "\"", except when deployed using TestFlight or the App Store the fatalError will be hit and the program terminates, but the message value is not saved to the crash log, making it pointless.
In other environments, like C#/.NET and Java I can simply throw new SomeExceptionType("my message") and all information is available in whatever global catch(Exception) handler I have.
How can I achieve the same goal in iOS / Swift?
Swift does support error handling. You can create your own error type by confirming to Error protocol or use existing error types and then throw an error by invoking throw error.
But Swift forces you add error handling to any code that can throw an error. There are multiple way you can handle error in swift.
Apply throws keyword to your function, this indicates that the function can throw an error when invoked and the error should be handled by the caller.
func canThrowErrors() throws -> String
When invoking methods with throws keyword you have to add try keyword at the beginning of the invocation. All these try invocations should be handled either by applying throws to method to just propagate the errors or wrapping inside a do-catch block:
do {
try canThrowErrors()
try canThrowOtherErrors()
} catch is SpecificError {
// handling only specific error type
} catch let error as SpecificError {
// catches only specific error for type
} catch {
// catches all errors
}
Additionally you can use try? and try! for throwing function invocation to disable error propagation and retrieve optional result that returns nil in case of error and runtime assertions respectively.
By forcing you to handle all the errors at compile time swift avoids any undefined runtime behavior and debugging nightmare.
I would suggest to use fatalError or any other runtime assertion only if scenarios when there is no way to recover from a state without crashing the app. Unfortunately, there is no way to handle errors from fatalError as its use is only reserved for such scenarios only. Also, in your crashlog you will only get the line number that caused the crash to get additional info for the cause of crash I would suggest to use custom logging or analytics.

Not Supported Exception with xamarin.forms

System.NotSupportedException: Unable to activate instance of type PageRenderer from native handle . ---> System.MissingMethodException: No constructor found for PageRenderer::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership) ---> Java.Interop.JavaLocationException: Exception of type 'Java.Interop.JavaLocationException' was thrown.
It happens when application is running and I change system font size and then push application icon again. (android project)
I have PageRenderer where I have googleMap.
Solved! I added public constructor with Intptr and Jniownership and added view initialization in this constructor and working perfectly

Why does navigating to the Internet from a HyperlinkButton cause my app to crash?

I'm trying to display a privacy statement from a settings flyout using a HyperlinkButton; after clicking the hyperlink, though, I get a crash with two dialogs. The one on top says:
~~~~~~~~~~~~~~~~~~~~~~~~
Warning
A debugger is attached to <ProjectName> but not configured to debug this
unhandled exception. To debug this exception, detach the current debugger.
~~~~~~~~~~~~~~~~~~~~~~~~
...and below that the second dialog opines:
~~~~~~~~~~~~~~~~~~~~~~~~
Visual Studio Just-In-Time Debugger
An unhandled win32 exception occurred in <ProjectName> [10704].
Possible Debuggers:
New instance of Microsoft Visual Studio 2012
Yes No
~~~~~~~~~~~~~~~~~~~~~~~~
When I selected "No" to start that new instance, I was transferred away from the Emulator back to my debugging session - actually, the debugging session was terminated - it was as if I had Shift+F5'd.
My XAML is:
<HyperlinkButton Grid.Row="4" Grid.ColumnSpan="2" Content="Duckbilled Platypi Privacy Statement" NavigateUri="http://montereyscenics.posterous.com"/>
UPDATE
So since the link worked fine in the AppSettings sample, I added an OnTapped event (admittedly, this is different than the OnClicked shown there) to the Hyperlink so that it now looks like this:
<HyperlinkButton Grid.Row="4" Grid.ColumnSpan="2" Content="Time and Space Lines Privacy Statement" NavigateUri="http://montereyscenics.com/" Tapped="PrivacyHyperlink_OnTapped"/>
...and the handler:
async void PrivacyHyperlink_OnTapped(object sender, TappedRoutedEventArgs e)
{
await Windows.System.Launcher.LaunchUriAsync(new Uri(((HyperlinkButton)sender).Tag.ToString()));
}
It worked for a second - it immediately opened the page. But then it crashed on the "await" line (the only line) in the handler, with this missive:
"*System.NullReferenceException was unhandled by user code
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=MetroSandboxPlaypen
StackTrace:
at MetroSandboxPlaypen.TandSLsSettings.d__0.MoveNext() in...*"

Find the root cause of a first chance exception [duplicate]

I have a project that runs perfect under windows xp.
Now I have tried to run it under Windows 7 and got there a lot of exceptions under Immediate window.
A first chance exception of type 'System.ArgumentNullException' occurred in Microsoft.VisualBasic.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in LP_Wizard.exe
A first chance exception of type 'System.ArgumentException' occurred in LP_Wizard.exe
A first chance exception of type 'System.NullReferenceException' occurred in LP_Wizard.exe
A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll
A first chance exception of type 'System.ArgumentNullException' occurred in Microsoft.VisualBasic.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in LP_Wizard.exe
A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll
A first chance exception of type 'System.ArgumentNullException' occurred in Microsoft.VisualBasic.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in LP_Wizard.exe
A first chance exception of type 'System.ArgumentNullException' occurred in Microsoft.VisualBasic.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in LP_Wizard.exe
Any idea what wrong with that Microsoft.VisualBasic.dll in windows 7 and how i correct that problem ?
Thanks a lot for help .
If you want to pinpoint where the exceptions are occurring, you can select the Debug->Exceptions menu item, and in the dialog that appears, check the first checkbox for "Common Language Runtime Exceptions". This will make the debugger break as soon as an exception occurs instead of only breaking on unhandled exceptions.
This is also one reason why it is generally a bad idea to catch generic exceptions unless you are clearly logging the information caught.
What is happening is the debugger can "see" exceptions as soon as they are raised (hence the "first chance") before any catch block is hit. Any exception which is not handled by a catch block is considered a "second chance" exception and will break normally.
If these exceptions aren't stopping the running of your application because they are unhandled then you are probably OK. Most of the time the exception is handled by code and this isn't a problem. The output is simply Visual Studio letting you know the exceptions were raised.
See the "Avoiding first chance exception messages when the exception is safely handled" question for some methods to reduce this if there are too many to ignore.
Are your in the debugger? Are these exceptions your program is handling? If so you need to find a setting that tells VB to supress warning you of handled exceptions. Maybey this was set when installed on XP but not when you installed on W7. See if this helps:
http://www.helixoft.com/blog/archives/24

Resources