473,795 Members | 3,002 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

System.Unauthor izedAccessExcep tion error

JDS
I am getting the following error in my application:

System.Unauthor izedAccessExcep tion was unhandled
Message="Access to the port is denied."
Source="System"
StackTrace:
at System.IO.Ports .InternalResour ces.WinIOError( Int32
errorCode, String str)
at System.IO.Ports .SerialStream.D ispose(Boolean disposing)
at System.IO.Ports .SerialStream.F inalize()

The application uses a form to get (weight) data from an external
device on a USB connection mapped to a serial port. In normal
operation the form may be opened (ShowDialog) and closed several
times.

The sequence of events is as follows:
- device is disconnected whilst communicating (an error occurs then
but is handled in code)
- form closed
- device reconnected (i.e. USB physically plugged back in)
- form reopened and behaves normally (initially)
...
- error occurs (as above) but the timing is random, i.e. sometimes
soon after reconnection, sometimes whilst communicating with form
open, sometimes not; sometimes on first time form opened, sometimes
after several attempts

The form uses System.IO.Ports .SerialPort; the relevant code is as
follows (Try-Catch error handling removed):

'******* Selected form code *********
Public Shared WithEvents mPort As SerialPort
Private Shared m_FormDefInstan ce As frmWeigh

#Region "Form handling"
Public Shared Property DefInstance() As frmWeigh
...
Set(ByVal value As frmWeigh)
m_FormDefInstan ce = value
End Set
End Property

Private Sub frmWeigh_Load(B yVal sender As Object, ByVal e As
System.EventArg s) Handles Me.Load
...
DefInstance = Me
...
OpenPort()
...
End Sub

Private Sub frmWeigh_FormCl osing(ByVal sender As Object, ByVal e
As System.Windows. Forms.FormClosi ngEventArgs) Handles Me.FormClosing
...
If Not IsNothing(mPort ) Then
If mPort.IsOpen Then
mPort.Close()
End If
mPort = Nothing
End If
If Not IsNothing(m_For mDefInstance) Then
m_FormDefInstan ce = Nothing
End If
End Sub
#End Region

#Region "SerialPort "
Private Sub OpenPort()
...
mPort = New SerialPort()
mPort.Open()
mPort.DiscardIn Buffer()
Me.Timer1.Enabl ed = True
Me.Timer1.Start ()
...
End Sub
#End Region

#Region "Timer"
Private Sub Timer1_Tick(ByV al sender As Object, ByVal e As
System.EventArg s) Handles Timer1.Tick
...
'Code to check status and send command to request data
...
End Sub
#End Region

#Region "Data handling"
Private Shared Sub mPort_DataRecei ved(ByVal sender As Object,
ByVal e As System.IO.Ports .SerialDataRece ivedEventArgs) Handles
mPort.DataRecei ved
Try
Dim Buffer As String = mPort.ReadExist ing()
DefInstance.Beg inInvoke(New DisplayData(Add ressOf
Display), New Object() {Buffer})
End Sub

Public Delegate Sub DisplayData(ByV al Buffer As String)

Private Shared Sub Display(ByVal Buffer As String)
...
'Data processing code
...
End Sub
#End Region
'******* End of form code *********

From the calling code on error:
frmWeigh = Nothing
frmWeigh.Dispos e

I have a feeling that it is because I am not destroying objects
correctly but I am not sure exactly what I am missing. Any help
greatly appreciated.
Jan 13 '08 #1
1 6675
I'm having exactly the same error. Issue is reproducable if unplug and replug USB cable and stop my application (crash happens during application rundown).

It appears to be a subtle interaction between FTDI's drivers and Microsoft's SerialPort object.

Can you check to see if you are using FTDI device drivers to give you the virtual COM port? Support at FTDIchip.com told me the stuff below. Haven't tried because don't know where to put their code. I suppose I'd have to override the Dispose method for the Serial Port object and do something there.

How did you fix your problem?
vvvvvvvvvvvvvvv vvvvvvvvvvvvvvv vvvvvvvvv
You could use D2XX APIs to check the device presence and if it is not present close the USB handle or reload the device.

Code snippets are given in D2XX programmer's guide.

Please refer following APIs

FT_OpenEx and FT_Relaod. If FT_OpenEx return False you may call FT_Reload and try opening the handle again.

http://www.ftdichip.co m/Documents/ProgramGuides/D2XX_Programmer 's_Guide(FT_000 071).pdf
^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^

Nov 13 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
5471
by: Burton Roberts | last post by:
This is also posted in the security newsgroup. Sorry for cross-posting, but I'm desperate. I have a Winforms application in VB.NET with a SQL Server (MSDE) backend. In the root application directory I have an XML file, LicXML.XML which holds licensing info for the app. On one group of machines where the users have restricted privileges, the deserialization of this file trips an error as follows (excuse mispellings from my client):
1
4872
by: Krazitchek | last post by:
Hi, i check all directories on a disk but an error occurs when i try to enter in the "System Volume Information" directory. Is there a way to "jump" this directory without to check the name of the current directory to verify it's not "System Volume Information" ? Or, how to catch this error and continue the process when the error occurs ?
0
2477
by: Efi | last post by:
Hi, We have a simple 3 tier application which its core application is VC++ 6.0 ATL COM running as a server application in the COM+. An asp pipe is in charge of handling the requests and passes it to the COM for processing. We are now trying to migrate the asp pipe to Asp.Net. When running the above configuration with Asp.Net on IIS 5.0 (W2K) we have no problems but when trying the do it on IIS 6.0 (W2K3) we are getting the following...
0
1793
by: masago | last post by:
Hi....how are you ?? they can help me to solve this problem ?? Access to the path = "c:\windows\microsoft.net\framework\v1.1.4322\Temporary ASP.NET = Files\reports\06639073\bbab30a7" is denied.=20 Description: An unhandled exception occurred during the execution of the =
4
1495
by: 101 | last post by:
I get a security error when trying to write out to an XMLSchema file "myDs.WriteXmlSchema(strXMLSchemaFile)". I am running XP SP2, No Domain, MS file and print sharing uninstalled. I was able to get past this by making ASPNET part of the Administrators group. I tried the Power User group (as well as others) to no avail. I also had to install MS file and print sharing in order to even add ASPNET as a member of the Administrator group (or...
4
28960
by: Anbu | last post by:
Hi all, I have developed an application in VS .NET 2003 (framework 1.1) on a XP platform. It is working fine in that PC. Now, I setup new PC with same configuration for another develper. Whenever I execute the application it gives, Unauthorize Exception error and it's not execting the application property. The Error message is as follows,
0
2332
by: nime | last post by:
I've got a problem. I cannot debug my app. which one contains WebBrowser control. I found a resolution but it's for an ASP related problem. I couldn't find a correct "user" to give permisson then I've added Everyone and refreshed policies (gpupdate /force), restarted VB IDE but still got the problem. What is the "worker process" for VB IDE? CODE:
5
5079
by: Max | last post by:
hi i have file browser control to select any file and a button to upload file on my web page now when i select any file. now on click of upload button i have check that file exist or no if system.IO.File.Exist(file path) then .... end if now when ever i choose file system.IO.File.Exist(file path) return
2
14379
by: job | last post by:
In a sharepoint setup using smartpart to load our user controls using enterprise blocks (data) we are getting some strange errors (logged to the event log). We dont get the error all the time. When we get the error CPU goes 100% We have been through all we can think of, but have not been able to locate the source to the error. Any suggestions?
0
10439
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10215
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10165
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9043
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7541
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3727
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.