Accessor Generation Bug - Unit Test Related

There is a very specific case when the accessors generated by Visual Studio (Visual Basic) .NET 2005 have a bug in them. I will try to quickly outline the situation below. I would like to know if Microsoft is aware of this bug and when a fix will be available, as well as alert others in the community of this problem and how to fix it.

Take the following two classes:

Friend Class Foo
Private oBar as Bar
Friend Property MyBar() as Bar
Get
Return oBar
End Get
Set(ByVal value as Bar)
oBar = value
End Set
End Property
End Class

Friend Class Bar
End Class

Now, generate accessors for both classes.

If you try, now, to instantiate a FooAccessor and then to set the MyBar property equal to a new BarAccessor, you will get an error when you try to run the unit test code. This is because the accessor code generated by the IDE forgets one key piece of code in the accessor's implementation of the "Set_MyBar" functionality. The "Set_MyBar" will expect, as a parameter, a BarAccessor (which is good), but then it will try to set the property equal to the BarAccessor object, rather than the BarAccessor.Target object, which will cause a type mismatch error.

So, you would see code in the VSCodeGenAccessors.vb file that looks like:

m_privateObject.SetProperty("MyBar", Value)

when it should be:

m_privateObject.SetProperty("MyBar", Value.Target)

It's a very simple fix to just add the ".Target" to the code within the VSCodeGenAccessors.vb file yourself, but you must then be aware that if you ever regenerate that class, you will have to also go in and re-fix this bit of code as well.

I hope this helps others out there and saves you all from the same headaches of trying to track down this nefarious bug yourselves as I had to.

Microsoft, I hope you guys are aware of this and will have a fix out for it soon; this problem makes using the built-in VS2005 unit testing framework much more difficult to justify from a code maintainability and coding efficiency standpoint.

have a nice day...

/Bob



Answer this question

Accessor Generation Bug - Unit Test Related

  • Accessor Generation Bug - Unit Test Related