Good Morning group!

I've made some minor changes to my coding (to open a log file, write to it and then close it) and now I'm getting an error that I've not seen before. The error code is CA2213. I've read what it says and I've tried to look it up online, but I don't seem to grasp what it means. Hopefully you can help.

When I double click the error, the yellowed out line is:
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
The remaining code says:

Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub

The error message say to "Change Dispose Method to call Close or Dispose on this field". Where is this change supposed to be?

In advance, thanks for your help.

Don

Have you looked at the explanation on this page?

You need to show the code where the error happens.

Which code part is highlighted during this error?

Group,

I get the error when I try to build the project. The Errors List says, "CA2213 (the warning code) Main contains filed Main.objwriter2 that is of IDisposable type StreamWriter. Change the Dispose method on Main to call Dispose or Close on this field."

When you click the error message, the following code is highlighted in yellow:
Protected Overrides Sub Dispose(ByVal disposing as Boolean)
This is found on the Main.Designer.vb tab. The remaining code is as follows:

        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub

I'm confused as to what it's trying to get me to do. I have found that the text file (called "logFile") that "objwriter2" is trying to write to is "being used by another application", which should be false. This file is on my computer and is not open or being used by anything else.

For the time being, I've removed objwriter3 from the program which allows it to run fine. But I do want to put it back in. Any thoughts as to what I need to do?

Don

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.