Try Catch Finally , pointers and Vb.net 2005 compiler warnings

Tech-Archive recommends: Fix windows errors by optimizing your registry



Hi,
The compiler gives Warning 96 Variable 'cmdSource' is used before it has
been assigned a value. A null reference exception could result at runtime.

Dim cmdSource as SQlClient.SQLDataReader
Try
Set up the database read and do it.
Catch ex as system.exception
exception stuff here
Finally
cmdSource.close()
End try

Can't see a way out of this (Assuming a desire to explicity close in the
finally)
If you Dim inside the try statement you go out of scope in the finally.

Is there a tidy way to get rid of these warnings? My (was Vb.net 2003) Data
acccess class is now littered with them.
Thanks
Bob


.



Relevant Pages

  • Re: Try Catch Finally , pointers and Vb.net 2005 compiler warnings
    ... Dim cmdSource as SQlClient.SQLDataReader = Nothing ... Notification list for the "Use of variable prior to assignment " condition. ... > The compiler gives Warning 96 Variable 'cmdSource' is used before it has ... A null reference exception could result at runtime. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Try Catch Finally , pointers and Vb.net 2005 compiler warnings
    ... I went with the inital assignment of both the command object and the ... > The compiler gives Warning 96 Variable 'cmdSource' is used before it has ... A null reference exception could result at runtime. ... > Dim cmdSource as SQlClient.SQLDataReader ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Converted a solution to VS2005 and it is complaining: Variable PF2 is used before it has been as
    ... A null reference exception could result at runtime. ... Make sure the structure or all the reference members are initialized before use ... The compiler does not know which members of PF2 are accessed within ... member that has not been initialized, thus you get the warning because it ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Converted a solution to VS2005 and it is complaining: Variable PF2 is used before it has been as
    ... A null reference exception could result at runtime. ... Make sure the structure or all the reference members are initialized before use ... The compiler does not know which members of PF2 are accessed within ... member that has not been initialized, thus you get the warning because it ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Picture Box
    ... \System.Drawing.dll] to solve conflict and get rid of warning. ... null reference exception could result at runtime. ... Deploying 'C:\WINDOWS\assembly\GAC_MSIL ...
    (microsoft.public.dotnet.framework.compactframework)