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


  • 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")
            Dim myDataAdapter As SqlCeDataAdapter = New SqlCeDataAdapter("Select * FROM AppSettings", myConn)
            Dim myData As System.Data.DataSet = New System.Data.DataSet
        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?

    Friday, November 11, 2005 2:21 PM


All replies

  • This is a known issue - it has to do with the way resources are loaded. It is safe to ignore
    Friday, November 11, 2005 3:07 PM
  • thanks for the reply, but this is causing me severe problems, see
    Friday, November 11, 2005 3:39 PM
  • 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.


    Friday, November 11, 2005 9:28 PM
  • I've re-posted this as, the problem is #ZipLib, not ADO
    Monday, November 14, 2005 2:50 PM
  • 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?
    Thursday, November 17, 2005 9:21 AM
  • 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.

    Thursday, November 17, 2005 5:04 PM
  • OK, ignoring it
    Friday, November 18, 2005 9:08 AM
  • 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?

    Wednesday, March 22, 2006 1:39 PM

    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!



    Wednesday, March 22, 2006 1:59 PM
  • 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.

    Wednesday, March 22, 2006 5:19 PM
  • 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!

    Wednesday, March 22, 2006 5:47 PM
  • 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.



    Wednesday, March 22, 2006 6:12 PM
  • 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.

    Thursday, March 30, 2006 11:57 AM
  • 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.

    Thursday, March 30, 2006 4:52 PM
  • 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
    Tuesday, April 04, 2006 6:46 AM
  • 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


    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.

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

    My mail is

    Thanks you in advance.

    Wednesday, April 19, 2006 5:32 PM
  • 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.

    Friday, May 12, 2006 5:17 PM
  • that is so bad practices!
    Sunday, August 13, 2006 7:12 PM
  • 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



    Monday, July 02, 2007 11:59 AM
  • 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.

    Monday, July 02, 2007 4:37 PM
  • 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.
    Wednesday, October 10, 2007 10:02 AM
  • 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

    Tuesday, December 23, 2008 1:55 PM
  • 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.
    Tuesday, December 23, 2008 6:03 PM
  • 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..


    The program will still run, but not display any data.
    Ruler of the undershorts
    Friday, January 01, 2010 10:52 PM