none
first chance exception of type 'System.IO.IOException'

    Pregunta

  • Surely this shouldn't be happening!  The following code creates a connection, DataAdapter & DataSet, then fills the DataSet.  the myDataAdapter.Fill creates a 'first chance exception', whatever that is

    Imports System.Data.SqlServerCe
    Public Class Form1
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

            Dim myConn As New SqlCeConnection("Data Source = \my documents\MASDB.sdf")
            myConn.Open()
            Dim myDataAdapter As SqlCeDataAdapter = New SqlCeDataAdapter("Select * FROM AppSettings", myConn)
            Dim myData As System.Data.DataSet = New System.Data.DataSet
            myDataAdapter.Fill(myData)
           
        End Sub
    End Class

    A first chance exception of type 'System.IO.IOException' occurred in mscorlib.dll

    I seem to get a few first chance exceptions, but ignore them, as
    a) I have no idea what they are, neither does MSDN
    b) I have no idea how to fix it

    However, it does seem to cause a problem later in my code, so I want rid of it, any ideas?



    viernes, 11 de noviembre de 2005 14:21

Respuestas

Todas las respuestas

  • This is a known issue - it has to do with the way resources are loaded. It is safe to ignore
    viernes, 11 de noviembre de 2005 15:07
  • thanks for the reply, but this is causing me severe problems, see http://community.sharpdevelop.net/forums/2270/ShowPost.aspx#2270
    viernes, 11 de noviembre de 2005 15:39
  • The reason you see this message in debugger is a handled exception is internal procedure which retrieves exception message for exception which occurred previously.

    Your real problem is this first exception, not the handled exception. You should catch this exception and print out error message and/or errors from error collection.

     

    viernes, 11 de noviembre de 2005 21:28
  • I've re-posted this as http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=134214&SiteID=1, the problem is #ZipLib, not ADO
    lunes, 14 de noviembre de 2005 14:50
  • I've re-raised this as I've determined that the problem seems to be System.Data.SqlServerCe v3.0.3600.0, runtime v2.0.50727, not #ZipLib.

    I created a 2nd test application using .netcf 1.0 and System.Data.SqlServerCe v1.0.5000.0, runtime v1.1.4322, and got no problem

    Is there I way I can handle this exception so that it doesn't cause this problem?

    Ilya, I didn't really understand your previous post, could you please elaborate?

    I've spent 5 days trying to work this out now, am I banging my head against a brick wall? My boss isn't too happy either!

    Is there a reason why System.Data.SqlServerCe has this *new* bug in it?
    jueves, 17 de noviembre de 2005 9:21
  • Sure. Somewhere deep in resource processing code we have something like this:

    try {
       // Try loading some strings here.
    } catch {
       // Oops, could not load strings, try another way.
    }

    Exception is thrown and handled already, it would never show up in your application. The only way to see it is to attach debugger and observe this message.

    As you could see from the code, it has nothing to do with your problem. The real problem here is what debugger shows you something you should not see. I’ll file a bug to mask it out in next version so nobody else would be confused and distracted from the real problem.

    jueves, 17 de noviembre de 2005 17:04
  • OK, ignoring it
    viernes, 18 de noviembre de 2005 9:08
  • Hi Ilya,

    There seems to be a lot of first time exceptions with the compact framework, that slow things down somewhat.  I've experimented a little and it appears to be to do with the use of the My.Resources namespace to reference resource strings.  It also occurs when using a sqlce data adapter or reader.

    e.g. when directly calling on a resource with the My.Resources namespace:

     

    * A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll

    * A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll

     

    or when initialising a form, the CF generates these exceptions:

     

    * A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll

    * A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll

     

    A first chance exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll

    or when using a datareader to read a SQLCE 3.0 table

     

    * A first chance exception of type 'System.IO.IOException' occurred in mscorlib.dll

     

    Also, every time a web service is used with a valid "http://..." URL, the CF generates the exception:

     

    * A first chance exception of type 'System.UriFormatException' occurred in System.dll

     

    Are some of these problems to do with a setting I've overlooked, e.g. security, or unresolved bugs in the CF?

    miércoles, 22 de marzo de 2006 13:39
  •  

    NB I've discovered that:

     

    * A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll

    * A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll

    * A first chance exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll

     

    was caused by using the Icon property of a form to store an icon - the resource manager doesn't seem to like it!

     

     

    miércoles, 22 de marzo de 2006 13:59
  • Yes, there's a number of cases when framework would throw and handle exceptions. We’re working on reducing number of such cases for performance reasons. Otherwise this is normal and has no impact on your application.

    miércoles, 22 de marzo de 2006 17:19
  • Thanks.  Wasn't sure if I was missing something.

    NB Worked around the issue of using the My.Resources namespace by making my own global variable for the resource manager (at least until all forms are instantiated), that way the errors only occur the first time it's referenced for a string, instead of every time a new form references the My.Resources namespace.  Also, icons loaded into memory variables once has reduced the impact of lengthy first chance 'access denied' exceptions, every time icons are pulled from a resource file.

    .... Thought this would be useful info!

    miércoles, 22 de marzo de 2006 17:47
  • Yes, it's a good idea to cache resource data instead of retrieving it every time. Even though these exception are not "errors" per se as they are expected and handled, they do have performance impact.

     

     

    miércoles, 22 de marzo de 2006 18:12
  • I want ignore it . But my application always exit unknown. I must fix the "first chance exception of type'system.IO.IOException' "

    please help me, Ilya Tumanov.Thank you.

    jueves, 30 de marzo de 2006 11:57
  • You probably getting another exception which is up to you to process. Handled exception happens on attempt to retrieve exception message for original exception. You should ignore handled exception, but you have to process the first one.

    jueves, 30 de marzo de 2006 16:52
  • Hello chisanga,

        There is not problems with exception but ocurs that the load forms time is increase when de debugger is printing in Console. For example, is a sqlce connection, the first time that conect is more slow (about 2 sec) that second times (0.X sec).
        For these reason, Can you post an example of cache resources?. Is very useful for me.

    Thanks in advance.
    jrmamirez from Spain
    martes, 04 de abril de 2006 6:46
  • Caching resources is more about using a resource file, e.g.

    'Overrides the Icon property, to cache the resource instead of access the resource file a number of times

    Public Shadows ReadOnly Property Icon() As Icon

    Get

    If miconMain Is Nothing Then miconMain = DirectCast(myApp.Resources.GetObject("icon_frmError"), Icon)

    Return miconMain

    End Get

    End Property

    NB.  I paint the icon on the form as it doesn't show in the taskbar on Pocket PC.

    For the sqlceconnection, just keep the connection open for as long as you need it if you want to save time accessing the connection later.

    martes, 11 de abril de 2006 11:20
  • chisanga... can you please send to me a zip file with the sample? I new and is very important for me.

    My mail is ramica@inicia.es

    Thanks you in advance.

    ramica
    miércoles, 19 de abril de 2006 17:32
  • I get

    A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll

    A first chance exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.SqlClient.dll

    errors while connecting to SQL from Pocket PC 2003. I am not able to get to the point of connecting to the database.

    viernes, 12 de mayo de 2006 17:17
  • that is so bad practices!
    domingo, 13 de agosto de 2006 19:12
  • So is there any road map on when we will get a solution to these first chance exceptions. Its a real bug bare for me as the forms take so long to load due to countless exceptions of this type and

     

    A first chance exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll

     

     

    lunes, 02 de julio de 2007 11:59
  • Yes, it should be fixed in 3.5. I would not expect significant improvements in form loading time though because exception handing time is insignificant compared to the task which causing it (which I would guess loading number of images). Beta 1 of VS Orcas is available; you can try it and see for yourself.

    lunes, 02 de julio de 2007 16:37
  • Try { } catch() {}  is not the way a framework should be built up.
    I think there should be other ways of handling like checking for empty result sets or check if a file is really open, eg.

    For example, I have a form with many elements which get image elements from ressources.
    I counted 194 Exceptions from mscorelib. This is WAY TOO MUCH! As you know, throwing an exception is much more costly than an if which is checking before.

    My problem is, that i cannot change the Designer Classes of my forms too much, because VSS would never load the form again in its designer.
    miércoles, 10 de octubre de 2007 10:02
  • Hi Ilya,

    I'm having the same problem. Even I cannot run the app in debug mode. So not where to put this try-catch block.

    Help is much appreciated.

    Thanks in advance

    Kumar
    martes, 23 de diciembre de 2008 13:55
  • You don't. If you have exception propagated to you then it is completely different issue. You have to find the reason for the exception and fix your code.


    This posting is provided "AS IS" with no warranties, and confers no rights.
    martes, 23 de diciembre de 2008 18:03
  • I have Windows 7, Visual Studio 2008, with SQLExpress and 3.5 .Net Framework installed and I am getting the same thrown exception.

    All I am doing is the step by step process found in Help found here..

    ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.en/dv_vbcnexpress/html/6e225ab7-ad8a-43ef-b15b-ad7f53de9402.htm
    ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.en/dv_vbcnexpress/html/c8148fa5-f671-4f8f-b32e-e9016b76223d.htm
    ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.en/dv_vbcnexpress/html/caf3ecbd-87f5-4748-b990-7395409a19c7.htm

    The program will still run, but not display any data.
    Ruler of the undershorts
    viernes, 01 de enero de 2010 22:52