Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unhandled NullReferenceException when closing FbRemoteEvent [DNET541] #518

Closed
firebird-automations opened this issue Jan 28, 2014 · 3 comments

Comments

@firebird-automations
Copy link

Submitted by: G. Krug (krugg)

I have opened an event registration like shown in example at http://www.firebirdsql.org/en/net-examples-of-use/ .
CreateConnection creates a new unpooled connection which is only used for this event (beside other connections with Pooling=true) :

FbRemoteEventEventHandler handler = new FbRemoteEventEventHandler(this.Update_Event);

FbConnection conn = CreateConnection();
FbRemoteEvent rv = new FbRemoteEvent(conn, dbEventNames);
rv.RemoteEventCounts += new FbRemoteEventEventHandler(handler);
rv.QueueEvents();

private void Update_Event(object sender, FbRemoteEventEventArgs e)
{
// do something
}

The registered event(s) are working fine then. If I want to stop event processing with

fbEvent.RemoteEventCounts -= handler;
// In most cases an unhandled NullReferenceException is thrown, we can not catch it here
try
{
fbEvent.CancelEvents();
}
catch (NullReferenceException nre)
{
// ignore, but log to debug output
}
if (conn .State != ConnectionState.Closed)
{
conn .Close();
}
conn.Dispose();

// hereafter
an unhandled exception is thrown as follows:

Exception: System.NullReferenceException: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
bei FirebirdSql.Data.Common.RemoteEvent.EventCounts(Byte[] buffer) in c:\Users\Jiri\Documents\devel\NETProvider\working\NETProvider\source\FirebirdSql\Data\Common\RemoteEvent.cs:Zeile 179.
bei FirebirdSql.Data.Client.Managed.Version10.GdsEventManager.<>c__DisplayClassa.<ThreadHandler>b__7(Object param0) in c:\Users\Jiri\Documents\devel\NETProvider\working\NETProvider\source\FirebirdSql\Data\Client\Managed\Version10\GdsEventManager.cs:Zeile 201.
bei System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
bei MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)

When stepping through the code inside my application there is a method in RemoteEvent.cs which is called after cancelling events, closing and disposing connection of that event (see code above):

	public void EventCounts\(byte\[\] buffer\)
	\{
		int pos = 1;
		Charset charset = this\.db\.Charset;

....

and this Charset is already null which will lead to the reported exception. As it is thrown asynchronously on the internal worker thread the exception gets not catched by the main thread.
Both parts of code are getting called from main thread in an WPF application.
This problem is not reproducible with 4.0.0.0 but I had to update to the newest version due to other bugs in there.

If there is any way to resolve this immediately, please post here,

Thank you in advance.

@firebird-automations
Copy link
Author

Commented by: G. Krug (krugg)

I have found a workaround to get events working without exceptions or missing event notifications.

Therefore I have to use a separate connection *without* pooling and do *not* close this connection at all. Even when the program is closing the connection must stay open (do not call Close() at any time) as long as it can and is possibly getting disposed at last.
Otherwise it seems the connection is returned to the pool after establishing the event connection but can't be used for other statements to execute as there are many exceptions (bad transaction state, broken blob field pointer, null-refs, etc.) thrown then.

This behaviour is reported in some other developer blogs and (russian) documentation I have finally found. There is no place one can find this information in one place I think.

@firebird-automations
Copy link
Author

Commented by: @cincuranet

I'm closing it as "Won't Fix", as the correct usage is provided in comment.

@firebird-automations
Copy link
Author

Modified by: @cincuranet

status: Open [ 1 ] => Closed [ 6 ]

resolution: Won't Fix [ 2 ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants