问题
I´m getting the exception when I try to open my page:
An unhandled exception occurred and the process was terminated.
Application ID: /LM/W3SVC/6/ROOT/ROXY/es
Process ID: 2972
Exception: System.InvalidOperationException
Message: Handle is not initialized.
StackTrace:
at System.WeakReference.set_Target(Object value)
at System.Data.ProviderBase.DbConnectionInternal.CloseConnection(DbConnection owningObject, DbConnectionFactory connectionFactory)
at System.Data.Odbc.OdbcConnection.Close()
at DsNet.CUIHandler.CloseConn()
at DsNet.CUIHandler.Finalize()
An in the page I get the error:
Message: Exception has been thrown by the target of an invocation.
Any idea?
Thanks in advance
回答1:
The bug in the page sounds unrelated, and should be investigated by catching and logging it. If you do end up catching a TargetInvocationException, then you can get the actual exception via the .InnerException.
Re the other issue: what is DsNet? Is that your code? or a library you are using? Either way, it sounds like it has a bug in the finalizer (touching managed objects is a really bad idea in a finalizer). I expect you may be able to make this less grumpy by using using around whetever is DsNet, so that it gets disposed in regular code, rather than finalized in the GC sweep. The only "hit" I'm getting in google for DsNet.CUIHandler is this question - so I'm guessing that is your code. If so: don't touch other managed objects in a finalizer.
来源:https://stackoverflow.com/questions/15327885/im-getting-exception-has-been-thrown-by-the-target-of-an-invocation