Spurious "Not Defined" error messages

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

We have a project with many other projects referenced (all of which are referenced at the project level and are included in the solution). Frequenly, if we make a change in project A (such as adding a property, or even simply changing a line of code), a form in project B will then show 10 or more "object such-and-such is not defined". To fix this problem we check out the form in project B and 90% of the time that fixes it (but nothing changes in the code or on the form - if we check the code in, our repository just ignores it since the code hasn't changed!). The other 10% of the time, we solve the problem but cutting a line out of the "Windows Form Designer Generated code" section where all the objects are declared (Friend Withevents...") and simply pasting it back in - again, no changes

I'm using VS.NET 2003

This has been pretty annoying for a while, but now it is out of control, frequently showing a hundred errors messages in 3 or more forms, all of which have to be checked out and un-checked out before the app will compile. This really derails the train of thought, as you can imagine

Any suggestions would be greatly appreciated!
 
Hi,

Thanks for posting in the community.

First of all, I would like to confirm my understanding of your issue.
From your description, I understand that when have many projects which
reference each other, after you change the code in one project, you will
get the Error.
Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.

Can you post what is the exact error message you've got?
Also to isolate the problem, I think you may try to create a new solution
and add just two of your projects, e.g. Project A and Project B.
Clear other reference, just add reference to Project B in Project A. Change
the code to see if the problem persist.

Also add the the other reference one by one, to see which one cause the
problem.
Have you check if you have circular reference, i.e. A reference B, B
refence C C reference A?

Please Apply My Suggestion Above And Let Me Know If It Helps Resolve Your
Problem.


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
I saw this behaviour with the following situation:
- Project A defines a base class with a Protected WithEvents variable
- Project B, which is in another assembly, inherits from the base class
in project A
- Project B has an event handler method which handles events from the
WithEvents variable defined in project A

This scenario, altough completely legal, should be avoided with VB.NET
2003 (and 2002), since the IDE cannot cope with it (you'll get the
errors you described). Instead, use AddHandler/RemoveHandler to handle
such events.

AFAIK, MS should be aware of this problem and has hopefully fixed it
already for Whidbey.

Best regards,
Urs
 
Hi Urs,

Thanks for posting in the community.

Based on my test, I can not reproduce the problem.
Here is my reproduce steps.
[ProjectB]
Imports System.Windows.Forms
Public Class BaseClass
Protected WithEvents fm As Form
Private str As String = "Test"
Public Property sk() As String
Get
Return str
End Get
Set(ByVal Value As String)
str = Value
End Set
End Property
End Class

[ProjectA]
[Class1.vb]
Public Class DerivedClass
Inherits ProjectA.BaseClass
Public Sub Test()
fm = New Form
fm.Show()
Me.sk = "Hello"
End Sub
Private Sub fm_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles fm.Closing
MsgBox("fm_Closing")
End Sub
Private Sub fm_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles fm.Click
MsgBox("Click")
End Sub
End Class

[Form1.vb]
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim o As New ProjectB.DerivedClass
o.Test()
End Sub

Also I have added a new property to ProjectA.BaseClass and press
Ctrl+Alt+B to build the solution, the event will fire again.

Can you build a reproduce sample as simple as possible as long as it can
reproduce the problem, and send to me by removing the "online" from my
email address?
I look forward to hearing from you.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Eric, Urs, Peter.

I am working on a large solution with several large project included into
it. I also am connected to Visual Source Safe.

There are only two developers working on this solution, and both of us have
the same problem.. spurious errors in projects that we haven't even edited..
usually on forms.. but sometimes on a control inherited from Label..

The errors appear upon compilation, then if I check out the offending Form
or Class then comment out the line defining the object it claims to be
missing, then uncomment the same line, the problem goes away for a few more
compiles.. then re-appears..

It only seems to be a problem when the solutions gets above a certain size..
I have several other solutions that contain small projects, and the problem
never occurs there..

So I would guess it has something to do with the size of the solution..

Also it means it is extremely difficult to give a small reproduction of the
problem.

also several others are having the same problem.. see post in
microsoft.public.vsnet.ide on 05Feb2004 by Jeff Lindholm, title "Compile
Errors - only sometimes"

I can only re-iterate what Urs stated, and hope this problem goes away with
Whidbey!

Here's hoping,
Rigga.

Eric G. Harrison said:
We have a project with many other projects referenced (all of which are
referenced at the project level and are included in the solution).
Frequenly, if we make a change in project A (such as adding a property, or
even simply changing a line of code), a form in project B will then show 10
or more "object such-and-such is not defined". To fix this problem we check
out the form in project B and 90% of the time that fixes it (but nothing
changes in the code or on the form - if we check the code in, our repository
just ignores it since the code hasn't changed!). The other 10% of the time,
we solve the problem but cutting a line out of the "Windows Form Designer
Generated code" section where all the objects are declared (Friend
Withevents...") and simply pasting it back in - again, no changes.
I'm using VS.NET 2003.

This has been pretty annoying for a while, but now it is out of control,
frequently showing a hundred errors messages in 3 or more forms, all of
which have to be checked out and un-checked out before the app will compile.
This really derails the train of thought, as you can imagine!
 
Peter,
as said, this the error will only show up very spuriously (sometimes not
for weeks, and then all of a sudden multiple times a day!), and it seems
like it only shows up on large projects, not on small ones. That means,
sorry, I cannot give you a simple expample.

We had this problem about half a year ago and cleaned up all the
Protected Withevents variables then. I'm sorry I cannot rebuild the
project with the state half a year ago.

It seems to have to do with Building a project (not *re*building) it,
since when you rebuild it the problem goes away.

Sorry I can't be of more help
Urs
 
Rigga,
did you check if you have this Protected WithEvents scenario I
described? Since we got rid of those constructs and consequently avoid
them, we never had this problem again.
Urs
 
Peter, obviously othesr are running into this problem and have posted more information. Thanks for your quick reply!
 
Urs, we're not using exactly that construct, but we are using some components from Infragistics that are using Friend WithEvents in their declarations. Other than that, it sounds like the same problem. Later tonight we're going to take the form that we're inheriting from and move it into the same project as the derived classes

Thanks again, and I'm glad to see all the other responses - this is obviously a real problem!
 
Hi,

Thanks for posting in the community.

I am researching the issue, if I have new information, I will update with
you ASAP.
Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi,

I still can not reproduce the problem I also try to add my solution to the
Visual source safe.

To isolate the problem, I think you may try to re create a new solution and
add the projects and rebuild the project one by one to the solution to see
if the problem persists.

Also you may try to copy the whole solution to another machine to see if
the problem persists.

You may also take a look at the build log in the OutPut panel, to see if
all of the projects build successful.

Please try my suggestion and let me know the result.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Urs,

I don't think we have this Protected WithEvents situation exactly as you
describe it...
but we do use Protected WithEvents to define some object.. but usually
handle any events in the same class / form where they are defined..

Rigga.
 
Back
Top