.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
Easy Web
Imran Ghani
Post New Web Links

C# SerialPort System.ObjectDisposedException, safe handle has been closed in System.DLL

Posted By:      Posted Date: October 05, 2010    Points: 0   Category :.NET Framework
 

I have an application in which at start up I need to do a port discovery process to determine whether instruments are attached to the end of any number of PC com ports. These com ports could be Bluetooth enumerated or, using FTDI USB to serial line convertor drivers, a USB connection. At start up I determine which ports are being used for this session by interogating all the ports stored in a list. I do this by opeing the port and then using a synchronous write and read (using timeouts of 500ms). I put try and catch around the port open to capture the case where the port has been disconnected (USB) or is not currently accessible (Bluetooth) and create a list of instrument objects each of which will have its own serial port object. Before going into normal mode I close the ports. So in essence this is

foreach(string portname in portstouselist)

    if open port success

        if writeline(Instrument?) success

            if Readline success

                 add instrument found and associated port to list

       close port

Normal running operates something like a data logger so I open each of the ports to which I have an instrument connected and start an asynchronous read with an associated data received event handler and infinite time out.

It is possible that the user connections could change during the application run.


View Complete Post


More Related Resource Links

System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a rec

  
Hello Guys,         I am getting following exception while web service (ASMX) is returning the response. <!-- [if gte mso 10]> <mce:style> System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive.     <!-- [if gte mso 10]> <mce:style>                                                     InnterException (System.IO.Exception): "Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host."       I think either the Asp.net web server is closing the connection or the response is too long.   Following is my simple code.    1)   namespace JFA.IndiePay.BusinessAccess { public class VerTexProcessor { public DataSet ProcessVerTexForBatch(DataSet dsInputRequest) { DataSet dsResponse = new DataSet(); //Call vertex web service here. VertexService.Service texCalculator = new VertexService.Service(); texCalculator.Timeout = 500000;

ImageList and a system image list handle

  
How can I have an ImageList use an image list handle of a systems image list, such as one that can be returned from SHGetFileInfo ? My image list is associated with a ListView control and this could be easily done in Win32 through the LVM_SETIMAGELIST message with an image list handle but I see no easy way of doing this with the .Net System.Windows.Forms.ImageList component.

Query Plan handle is not matching in the query related system DMV's

  

Ent : SQL Server 2008 SP17

OS  : Windows Server 2008 Ent.Edt

While troubleshooting a performance issue for a Query (SP) I came across this weired thing that the Query Plan handle is not matching across all the Query related system DMV’s.

 

Senario with a simple query

For each executing Query a plan handle is generated in sys.dm_exec_connections (Column most_recent_sql_handle).Based on the sql_handle the q

...The underlying connection was closed: The connection was closed unexpectedly. at System.Net.Web

  

I have a WCF service with the following lines of code:

WebClient Client = new WebClient();

Stream strm = Client.OpenRead(fPath); < -- Exception Occurs exactly here

Everything works great when I am hosting the service via the ASP.NET Development server, but when I publish the service to IIS, the following runtime error is thrown:

The underlying connection was closed: The connection was closed unexpectedly.\r\n   at System.Net.WebClient.OpenRead(Uri address)

As stated, the program opens the file without any problems when the service is hosted in the ASP.NET development server.  When hosted in IIS, an exception is thrown at the location specified above.  I thought that it might be an issue of security, so I went berserk in permission granting.  I sort of ruled that out at this point as every group has full access and the exception is still being thrown.

Any assistance on this would be greatly appreciated...


Is Dispatcher.BeginInvoke really NOT thread safe, while the old System.Windows.Forms.Control.BeginIn

  

Hello.

 

System.Windows.Forms.Control.BeginInvoke is documented as thread safe (in fact, BeginInvoke , EndInvoke , Invoke , InvokeRequired , and CreateGraphics are).

Great!

 

But in WPF, Dispatcher.BeginInvoke is not documented as thread safe. Which would appear to me as a regression (and not really convenient, to be honest).

Was it only forgotten in MSDN documentation, or should I really use external locking to prevent the dispatcher to get lost in its messages and priorities?

 

 

Thanks. ;)


using objectdatasource with entity model leads to System.ObjectDisposedException

  

hi every body.

i my web application i used entity data model and imported some select stored procedures as functions (Add Function Import). so i used objectdatasource to call this functions and set their parameters to retrieve data. but when i run application the following exception shows:

The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ObjectDisposedException: The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

System.Net.WebException Message=The underlying connection was closed: The connection was clos

  

Hi,

I have a work flow developed in vs2010 WF4 exposed as service. I am consuming this service in a test web application, whenever service returns i get the following exception:

System.Net.WebException       Message=The underlying connection was closed: The connection was closed unexpectedly.

If i return a string it works fine, whenever i deserialize my result into an object and return that object i get the above mentioned error.

 

Regards,

Hassam


System.Net.WebException Message=The underlying connection was closed: The connection was clos

  

Hi,

I have a work flow developed in vs2010 WF4 exposed as service. I am consuming this service in a test web application, whenever service returns i get the following exception:

System.Net.WebException       Message=The underlying connection was closed: The connection was closed unexpectedly.

If i return a string it works fine, whenever i deserialize my result into an object and return that object i get the above mentioned error.

 

Regards,

Hassam


System.ObjectDisposedException: Cannot access a disposed object.Object name: 'MQCacheableInfo'.

  

Hi,

I am using MSMQ concept in my .Net windows service application. So, i got below mentioned error and messages are moved to UnHandled queue. If i process manually then message has been processed well. So, this issue we got quite common on my production environment. I would like to know whether can we fix this issue.

Exception Message:

2010-10-05 01:37:03,687 [Handler.1] WARN  HandlerService.CWorkerThread - Couldn't process message

System.ObjectDisposedException: Cannot access a disposed object.Object name: 'MQCacheableInfo'.

   at System.Messaging.MessageQueue.MQCacheableInfo.get_WriteHandle()

   at System.Messaging.MessageQueue.StaleSafeSendMessage(MQPROPS properties, IntPtr transaction)

get the handle of System.Web.UI.WebControls.TextBox

  

Hello,

I am trying to make a textbox re-size to fit the text provided. I found a solution in C#:

Graphics g = Graphics.FromHwnd(textBox1.Handle);
SizeF f = g.MeasureString("String to fit", textBox1.Font);
textBox1.Width = (int)(f.Width);
// textBox1.Height = (int)(f.Height); // if required...
textBox1.Text = "String to fit";

I'm using VB.net and the Textbox1.handle is not present in VB.net. The project is running on .NET Framework 1.1

Is there another way to get the handle of the TextBox?


Thanks in advance!

Regards,

Heisa



SerialPort.Open Insufficient system resource exist to complet the requested service

  

Hi,

SerialPort.Open call in my application crashes intermittently on only one laptop of all machines with the following exception.

Error. Insufficient system resources exist to complete the requested service.

at System.IO.InternalResources.WinIOError(Int32 errorCode,...)

at System.IO.PortsSerialStream..ctor(String portName,...)

at System.IO.Ports.SerialPort.Open()

 

I am clueless how to debug into this issue, as this happens only on one of the laptops and that too intermittently.

I doubt it is a corrupt kernel issue or ??!!!

Can anyone point me to a direction that can help me resolve this issue or reveal a hidden bug.

-Alex

 


Alex

System.Net.WebException: The underlying connection was closed: The server committed a protocol viola

  
I need to send files using FTP with SSL enabled.  Unfortunately a "protocol violation" WebException is thrown whenever GetRequestStream is execute.  Please see a sample program below.

I've reviewed the post "Unable to use FTPWebRequest over SSL" but do not find a solution there.

I can use WinSCP to the same FTP site without problem so I'm working on the assumption that I my .NET logic is incorrect.

Any help appreciated.

// .NET 2.0
using System;
using System.Collections.Generic;
using System.Text;

using System.Net;
using System.Security.Cryptography.X509Certificates;
using System.Security.Policy;
using System.Net.Security;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            System.Diagnostics.TextWriterTraceListener listener = new System.Diagnostics.TextWriterTraceListener(@"C:\Documents and Settings\jhotchk\Desktop\NetworkTrace.Log");
            System.Diagnostics.Trace.Listeners.Add(listener);
  &n

System Development Life Cycle

  
The Systems Development Life Cycle (SDLC) is a conceptual model used in project management that describes the stages involved in an information system development project from an initial feasibility study through maintenance of the completed application. Various SDLC methodologies have been developed to guide the processes involved including the waterfall model (the original SDLC method), rapid application development (RAD), joint application development (JAD), the fountain model and the spiral model. Mostly, several models are combined into some sort of hybrid methodology

The Agile System Development Life Cycle (SDLC)

  
The goal of this article is to describe the agile system development life cycle (SDLC), putting it in context from what you may have heard about within the agile community and more importantly within the context of your overall IT efforts.

Performance Tests: Precise Run Time Measurements with System.Diagnostics.Stopwatch

  
Everybody who does performance optimization stumbles sooner or later over the Stopwatch class in the System.Diagnostics namespace. And everybody has noticed that the measurements of the same function on the same computer can differ 25% -30% in run time. This article shows how single threaded test programs must be designed to get an accuracy of 0.1% - 0.2% out of the Stopwatch class. With this accuracy, algorithms can be tested and compared.

System.Security.SecurityException:

  

hello i have the following problem

i have upload my content to hosting server but i get the following error

Security Exception

Description: The application attempted to perform an operation not allowed by the security policy.  To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.

Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[SecurityException: Request for the permission of typ

Problem upgrading to MVC3 - System.Web.Routing

  

Hi,

I'm trying to upgrade to .NET 4 and MVC 3.

When trying to compile my project, I get the error:

Error 1 The type or namespace name 'Routing' does not exist in the namespace 'System.Web' (are you missing an assembly reference?) C:\Users\spencer\Desktop\weblauncher\Common\MVCConfig.cs 4 18 Common

The type or namespace name 'Routing' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)

I do have the System.Web.Routing in my references for the project.

BUT - when I try to view System.Web.Routing in the OBJECT BROWSER, nothing is inside!  The System.Web.Routing namespace is not in there - the entire thing is empty!  Could it that the dll is corrupted?  I tried to reinstall the .NET 4 and MVC 3 stuff, but its still empty!

The dll is coming from here:

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Web.Routing.dll

and the runti

Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend