question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

KeyNotFoundException & ArgumentNullException

See original GitHub issue

I 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)]

screenshot_20180502-103523

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:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
MrJerBcommented, Jun 8, 2018

Yep, don’t bother using Live Player.

2reactions
maatj05commented, Jun 8, 2018

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found