You are here

api throwing ObjectDisposedException on CySmartDongleMgr.GetInstance().CloseCommunicator(m_communicator) | Cypress Semiconductor

api throwing ObjectDisposedException on CySmartDongleMgr.GetInstance().CloseCommunicator(m_communicator)

Summary: 9 Replies, Latest post by PRKU on 25 Oct 2017 09:56 PM PDT
Verified Answers: 0
Last post
Log in to post new comments.
Mangesh sarode's picture
User
8 posts

Hi

I am using cypress (C#) api for communicate with Cysmart BLE dongle.

while closing communicator using "CySmartDongleMgr.GetInstance().CloseCommunicator(m_communicator)" method ,  I am getting error  says Unhandled Exception: System.ObjectDisposedException: Safe handle has been closed ". I have tried new DLLs from CySmart 1.2 SP1 release as Anjana (Cypress Employee) has mentioned that

"This was a bug in the dispose implementation of the API.

This is already fixed in CySmart 1.2 SP1 release."

but still I am getting same error. Please provide any solution if it is possible.

e.pratt_1639216's picture
User
638 posts

The error sounds like an invalid access to an object/instance that is already disposed. Since afaik, the cysmart library is closed-to-cypress, then either you will need to catch and ignore that specific error, and just accept that it will keep occurring; Or a cypress employee will need to help you with debugging if it is a new issue.

It could be that you installed the new CySmart 1.2 SP1 release, but are still using the older version in your C# application. Try double-checking that you are using the correct binary/library for your project?

Mangesh sarode's picture
User
8 posts

Hi e.pratt_1639216 ,

Thanks for quick response.

Actually I have double-checked and I am using correct binaries. but still I am getting same error.

The scenario is first I attache dongle to PC then I called dongleMgr.TryGetCySmartDongleCommunicator() and then I detach dongle from system and called CySmartDongleMgr.GetInstance().CloseCommunicator() this time it is throwing UnhandledException.

If I did not detached dongle and then called CySmartDongleMgr.GetInstance().CloseCommunicator() then there is no issue.

Anjana Muralidharan's picture
Cypress Employee
162 posts

Hi Mangesh,

Could you please share the project which you tried?

Thanks,
Anjana

Mangesh sarode's picture
User
8 posts

Hi Anjana,

I am exploring the project which one of your employee has shared.

Please find attached project.

Regards,

Mangesh

Attachments: 
Anjana Muralidharan's picture
Cypress Employee
162 posts

Hi Mangesh,

Can you please try the below approach ?

Add a try catch block which catches the ObjectDisposedException and does nothing (ignore the exception).

Thanks,
Anjana

Mangesh sarode's picture
User
8 posts

Hi Mr. Anjana,

I am already catching that exception but the issue is it is going into catch block but still application is crashing it is not continue execution.

Regards,
Mangesh

Mangesh sarode's picture
User
8 posts

Sorry please ignore previous comment,

Actually I have added try catch but it is not coming in ObjectDisposedException catch block. it is throwing UnhandledException , so I am capturing Unhandled exception by using AppDomain.CurrentDomain.UnhandledException handler. It is coming into UnhandledException handler but still crashing application not able to continue execution.

Regards,

Mangesh

 

 

mady's picture
Cypress Employee
1114 posts

Hi Mangesh,

Sorry for the delay. We tried to reproduce this issue but we did not face any issue.

No matter the dongle is connected or disconnected, the CloseCommunicator is returning success.

I tested the code you attached here.

Steps:

1) Run the scanner.cs (the one you attached). It connects to the dongle and waits for Console.ReadKey().
2) I now remove the dongle from the PC and enter a character to console
3)  scanner.DisconnectDongle(); is called and the CloseCommunicator(m_communicator) returns success.

It returns success, even if do not remove the dongle in step 2.

Meanwhile do you have any more details you can provide us on reproducing the issue?

Regards,
-Madhu

PRKU's picture
Cypress Employee
32 posts

Test Post

Log in to post new comments.