KeyNotFoundException & ArgumentNullException
See original GitHub issueI am using code sample found here: https://github.com/Redth/ZXing.Net.Mobile/blob/master/Samples/Forms/Core/HomePage.cs
MainActivity.cs `
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(bundle);
ZXing.Net.Mobile.Forms.Android.Platform.Init();
global::Xamarin.Forms.Forms.Init(this, bundle);
LoadApplication(new App());
}
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults)
{
global::ZXing.Net.Mobile.Android.PermissionsHandler.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
`
Home.xaml.cs `
public partial class Home : ContentPage
{
ZXingScannerPage scanPage;
Button buttonScanDefaultOverlay;
public Home() : base()
{
buttonScanDefaultOverlay = new Button
{
Text = "Scan with Default Overlay",
AutomationId = "scanWithDefaultOverlay",
};
buttonScanDefaultOverlay.Clicked += async delegate {
scanPage = new ZXingScannerPage();
scanPage.OnScanResult += (result) => {
scanPage.IsScanning = false;
Device.BeginInvokeOnMainThread(() => {
Navigation.PopAsync();
DisplayAlert("Scanned Barcode", result.Text, "OK");
});
};
await Navigation.PushAsync(scanPage);
};
var stack = new StackLayout();
stack.Children.Add(buttonScanDefaultOverlay);
Content = stack;
}
}
`
AndroidManifest.xml
<uses-permission android:name=“android.permission.CAMERA” /> <uses-feature android:name=“android.hardware.camera” /> <uses-feature android:name=“android.hardware.camera.autofocus” /> <uses-permission android:name=“android.permission.FLASHLIGHT” />
AssemblyInfo.cs
[assembly: UsesPermission(Android.Manifest.Permission.Flashlight)]

Upon pressing the button I get thrown the following exceptions:
- Exception of type ‘System.Collections.Generic.KeyNotFoundException’ was thrown. (KeyNotFoundException)
- Value cannot be null. Parameter name: property (ArgumentNullException)
Where am I supposed to handle them?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:7 (1 by maintainers)
Top Results From Across the Web
Why is there no key specified with .NET ...
Throws ArgumentNullException when key is null. Throws KeyNotFoundException when the key does not exist in the collection.
Read more >c# - How to troubleshoot KeyNotFoundException
KeyNotFoundException : The given key was not present in the dictionary. at System. ... ArgumentException: Invalid JSON primitive: System.
Read more >Why am I getting this exception? - C# - Sean Lloyd
ArgumentNullException, An argument that should not be null was passed into a method. ArgumentOutOfRangeException, A non-null argument passed ...
Read more >Exception Class (System)
IndexOf(String, Int32) method to throw an ArgumentNullException exception. ... KeyNotFoundException, The specified key for accessing a member in a ...
Read more >Exploring Different Exception Types in C# and Their Usages
ArgumentException : The ArgumentException is thrown when one of the parameters of a method is invalid or doesn't meet expectations. Example:
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Yep, don’t bother using Live Player.
When I attach my physical device to my PC with a USB cable , instead of using ‘Xamarin Live’, then the error does not occur… So in my opinion: problem solved