System.NotSupportedException: Unable to activate instance of type... Xamarin EMDK SampleProject

Hi everyone,

 

I am currently trying to get the BasicScanningTutorial running on a TC55 device with Xamarin in Visual Studio. I downloaded the sample from HERE. I can debug the application and everything works as expected, but whenever I minimize the app (pressing Android 'Back' or 'Home' button), following error comes up:

 

01-10 00:22:51.074 I/MonoDroid(13455): UNHANDLED EXCEPTION:

01-10 00:22:51.084 D/dd:     (13455): scanner.release: isBTScanner: false

01-10 00:22:51.094 I/MonoDroid(13455): System.NotSupportedException: Unable to activate instance of type Symbol.XamarinEMDK.Barcode.Scanner+IStatusListenerImplementor from native handle 1d200001 ---> System.MissingMethodException: No constructor found for Symbol.XamarinEMDK.Barcode.Scanner+IStatusListenerImplementor::.ctor(System.IntPtr, Android.Runtime.JniHandleOwnership) ---> Java.Interop.JavaLocationException: Exception of type 'Java.Interop.JavaLocationException' was thrown.

01-10 00:22:51.094 I/MonoDroid(13455): Java.Lang.Error: Exception of type 'Java.Lang.Error' was thrown.

01-10 00:22:51.094 I/MonoDroid(13455):   --- End of managed exception stack trace ---

 

It doesn't always happen after the first time, but it is guaranteed to happen after reopening and minimizing it a couple of times. It also sometimes happens that there is no error, but then the scanner won't read barcodes anymore. The scanner is enabled and the laser is showing on hard-button press, but nothing happens when trying to scan a barcode.

I don't really know how to resolve this issue. I followed the instructions on how to set everything up (VS, Xamarin, EMDK), thus everything should be set up correctly. I didn't change any of the sample code from BasicScanningTutorial.

 

So why exactly do I get the exception mentioned above and what can I do to resolve this issue?

 

I appreciate any help!

 

Regards,
Jeremy

Anonymous (not verified)
Hello Jeremy, Sorry for the

Hello Jeremy, Sorry for the delay, I will need to try to duplicate the issue, and possibly get some help from engineering to drive this issue to a resolution.  To aid in that process, could you provide the which the build number of the OS running on your TC55?  Found in  Settings > About Phone.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Jeremy Henkes,2...
Hi,The build number is:

Hi,

The build number is: 150422-SI-1800EN-02.52.02-23257-4.4.3-user

The original error message does not appear anymore (I think due to the recent Xamarin updates), but is replaced with the errors shown in the images below. However, in my opinion it is originating from the same problem.

Following a step by step walkthrough on how to reproduce the error(s):

1. Debug the application 'BasicScanningTutorial' and wait for it to launch.

2. Minimize it by pressing 'Home' button.

3. Navigate to the application and reopen it.

4a. It sometimes happen that the scanner can be set active by pressing the hardware trigger, but the barcode is not being read.

4b. The error messages shown below appear in Visual Studio.

In case the error is not showing up after the first iteration, redo step 2 and 3.

NullReferenceException.PNGOnUnhandledException.PNG

I hope that helps to better understand this issue. If there are any questions left, feel free to ask me and I will provide the necessary information.

Regards,

Jeremy

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Morten Atterman...
Hi Jeremy and BillDid you

Hi Jeremy and Bill

Did you figure out a solution to this problem?

We are seeing the same issue, resulting in a lot of app crashes.

In our app we are enabling and disabling the scanner quite often, to indicate to the user, that the scanner is not available at the moment.

We just upgraded to EMDK 2.1 (2.1.0.5) which does not solve the problem.

Any ideas?

We are using a lock object whenever we access the scanner, in order to prevent it being disabled when we are doing thing to the scanner object. Like the statement below. However, this is not helping.

lock (_scannerLock)

{

     if (_scanner != null && !_scanner.IsReadPending)

     {

               _scanner.Read();

          }

}

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Anonymous (not verified)
Hey Morten, I think it's best

Hey Morten, I think it's best to call read from the Status Event.  You should only call read if the scanner is IDLE,  a read is not pending, and the scanner is enabled

if (state == StatusData.ScannerStates.Idle)

{

if ( !_scanner.IsReadPending && scanner.IsEnabled)

     {

               _scanner.Read();

          }

}

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Morten Atterman...
Hey BillThat is noted, thanks

Hey Bill

That is noted, thanks.

Unfortunately, the real issue happens when we disable and enable the scanner rapidly. Causing the same error as Jeremy described.

Did you find a solution, or where able to recreate the problem Jeremy described?

Best regards

Morten Attermann Holst

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Anonymous (not verified)
Hello Morten, No, I have run

Hello Morten,

No, I have run through the steps noted in the thread but have not been able to duplicate the issue.

Can you provide a simple example that shows this exhibits this issue? I'm curious as to where in your code you disable and enable the scanner rapidly.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Morten Atterman...
Unfortunately I don't have a

Unfortunately I don't have a project that I can sent to you at the moment. I will have a look at creating one.

The "rapid" means, that whenever a user scannes a barcode on a list, we disable the scanner to prevent the user for scanning more items until we have selected the item that corresponds to the item in the list. Also, when the list is populated the scanner is disabled. Or really when an action triggers some kind of an update on the screen.

I see that there are others seeing similar issues.

EMDK for xamarin - Stack Overflow

First I get this error.

EMDKException - 20160928.png

Followed by this.

EMDKException2 - 20160928.png

Best regards

Morten

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Mike Bedford
Hello all, Interestingly

Hello all,

Interestingly enough, I am having the exact same error. So, while Zebra cannot reproduce it, I think it is also safe to say there there is something going on here. At first search, I also came up with a leaky abstraction issue for Xamarin (post on SO here: http://stackoverflow.com/questions/10593022/monodroid-error-when-calling-constructor-of-custom-view-twodscrollview/10603714#10603714

So, based on this post, one of the answers below the description was to at least add the missing constructor so as to at least not throw an exception. Therefore, here is my original constructor and the one I added:

        private MotorolaScanner()

        {

            this.context = Application.Context;

            initEMDKManager();

        }

        //Implemented based on leaky abstraction issue, to prevent intermittent exception.

        private MotorolaScanner(IntPtr a, JniHandleOwnership b) : base(a, b)

        {

        }

However, I still get the issue. Same as posted above but here it is again for reference.

BarcodeError.PNG

Agree it is intermittent but it does cause stability issues and unwanted effects.

Please help!

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Morten Atterman...
Hi againI have been looking a

Hi again

I have been looking a bit further into this issue, and in my search for a solution, I found a test project actually created by Michael Bedford which causes the above mentioned exception.

https://developer.zebra.com/servlet/JiveServlet/download/91276-16690/BasicScanningTutorial_modifiedMultActivites.zip used in the post .

To recreate: (This is not done exactly in the same way each time, but I can always get it to crash in less than one minute.)

Run this project from Visual Studio 2015 in debug mode.

Enable and disable the scanner a couple of times, and go back and forth between the pages.

Notice that the above exception is thrown.

I really hope you will look into this issue, as we are getting really close to release.

Best regards

Morten Attermann Holst

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Mike Bedford
Morten, I had actually gotten

Morten,

I had actually gotten a response in that thread you posted above from Darryn. He stated that he was able to reproduce alot of the issues but only while running in debugger from Visual Studio. He noted that those issues did not seem to happen when running not in debug.

Can you try to validate this? Create a release and run it directly on the handheld and see if some of these errors go away and are indeed related to the VS Debugger?

That might get you by for now. It makes sense to me that the debugger can cause these issues because as you know, during debugging, Visual Studio is basically running the code on the device via ADB. This can cause some slowdowns that might affect things. I might be reaching with that comment, I actually don't know for certain it is the case. But logically, it makes sense to me.

Thanks!

Mike

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Morten Atterman...
Hi MichaelSo, I have done a

Hi Michael

So, I have done a couple of tests using your program (BasicScanningTutorial). When I run the code in debug mode, I have the exception in under a minute, just clicking around the activities and enabling/disabling the scanner every two seconds or so.

When I run in Release mode, I can use the application a while longer, but it still crashes.

​ I hope you can use this information. Let me know if I can help in any way.

Thanks.

Best regards

Morten Attermann Holst

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Anonymous (not verified)
Hello Morten, At this point

Hello Morten, At this point (since you are still having issues beyond debugging), it may be best to contact Zebra Support and open a ticket. 

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Morten Atterman...
Ahh... I see.I thought this

Ahh... I see.

I thought this was the way to point out, and get issues fixed. I will create a ticket.

You requested a test project in which the error could be reproduced, which I have linked to. Where you able to reproduce the bug?

Best regards

Morten Attermann Holst

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


umit Bostanci
Hi,any update on this issue?

Hi,

any update on this issue? I am trying with 2.3 version and having same error

thanks

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Log in to post comments