Visual Studio 2019: Break points do not break - visual-studio-2019

I have a very strange behavior in Visual Studio and I can't explain it.
In a bigger project I have a class, that looks something like this:
Public Class DatabaseDescription
Inherits DatabaseDescriptor
Private _tableNames As List(Of String)
...
Public ReadOnly Property TableNames As IEnumerable(Of String)
Get
If (_tableNames Is Nothing) Then
_tableNames = Me.GetTableNames
End If
Return _tableNames
End Get
End Property
Private Function GetTableNames() As IEnumerable(Of String)
Dim result As New List(Of String)
...
Stop
Debug.Print("Hallo")
...
result.Add(tableName & "_Test")
...
Return result
End Function
...
End Class
The class variable _tableNames is only used in the property TableNames, nowhere else.
I set a break point in the function GetTableNames right at the beginning, so, if this function ever gets called, my break point should be hit.
I set a break point right at the beginning of the property TableNames.
I put an explicit Stop and a Debug.Print in the function GetTableNames.
I added a "_Test" to every table name, just to be sure that I'm working with the right code.
And guess what... when running my code TableNames gets filled, without my break points ever being hit. The explicit Stop didn't work either. But I see my Debug.Print and every table name has a "_Test" at the end.
All the projects in my solution are in debug configuration. When I delete the library in question from the output folder, it gets re-created. Restarting Visual Studio didn't help either. Change the "_Test" to "_Test2" and changing the Debug.Print text have an immediate effect, but the break points and the explicit Stop won't work. Other break points in the same class work, eventhe one in the property, when I access it the first time on purpose.
Any ideas?

Apparently some feature or function of Visual Studio got the value of TableNames for Intellisense reasons and for that they probably ignore break points or explicit Stops.
After closing a few of Visual Studios windows (like "Watch", "Local" or "Diagnostic Tools") the problem vanished.

Related

C# folder.FolderPath (and many other dynamic properties)

I logon to an RDOSession, then:
foreach(RDOStore store in rdoSession.Stores)
{
RDOFolder folder = store.GetDefaultFolder(rdoDefaultFolders.olFolderInbox);
Debug.WriteLine(folder.FolderPath);
}
Visual Studio marks FolderPath as an error: RDOFolder does not contain a definition for FolderPath...
If I omit that line (so the code will run), then break right after getting the folder, I can add folder to the watch list and expand it. It shows no properties at all unless I expand the Dynamic View node. I can then see all the properties referred to in the Redemption docs.
My question is: how do I refer to Redemption properties like FolderPath in code? Some properties are fine -- e.g. folder.Items will compile just fine. But many are not -- like folder.FolderPath.
The FolderPath property is implemented by the IRDOFolder2 interface and derived from RDOFolder. Try to cast an instance of the RDOFolder
class to IRDOFolder2 and get the property value.
Also you may try using the Outlook object model which provides the MAPIFolder.FolderPath property which returns a string (string in C#) that indicates the path of the current folder.

In BillingClient setup .setListener(this) references my calling activity instead of a PurchasesUpdatedListener

The docs show the following for setting up a Billingclient.
private BillingClient billingClient;
...
billingClient = BillingClient.newBuilder(activity).setListener(this).build();
In .setListener(this), the 'this' part is supposed to reference a PurchasesUpdatedListener, even though you don't explicitly create one to put in these parenthesis. Apparently just using 'this' is supposed to be enough. In the docs and all the examples I've seen, a PurchasesUpdatedListener is never created to put here, it just uses 'this', apparently self-referencing the billingclient being created. This hasn't worked for me though, and I keep getting:
Should I use something else for the (activity) part than (getApplicationContext())? I've tried (this) and various other things here as just the word 'activity' isn't recognized.
Instead setListener(this) put setListener(new PurchasesUpdatedListener(){... }) and implement the required methods (usually AndroidStudio does it automatically)
Or
add .. implements PurchasesUpdatedListener at the end of your MainActivity declaration
the same thing as you can do on many listeners, for example the well known OnClickListener

Understanding Mock Unit Testing

am trying to understand using Mock unit testing and i started with MOQ . this question can be answered in General as well.
Am just trying to reuse the code given in How to setup a simple Unit Test with Moq?
[TestInitialize]
public void TestInit() {
//Arrange.
List<string> theList = new List<string>();
theList.Add("test3");
theList.Add("test1");
theList.Add("test2");
_mockRepository = new Mock<IRepository>();
//The line below returns a null reference...
_mockRepository.Setup(s => s.list()).Returns(theList);
_service = new Service(_mockRepository.Object);
}
[TestMethod]
public void my_test()
{
//Act.
var myList = _service.AllItems();
Assert.IsNotNull(myList, "myList is null.");
//Assert.
Assert.AreEqual(3, myList.Count());
}
Here is my question
1 . In testInitialize we are setting theList count to 3(string) and we are returning the same using MOQ and in the below line we are going to get the same
var myList = _service.AllItems(); //Which we know will return 3
So what we are testing here ?
2 . what are the possible scenarios where the Unit Testing fails ? yes we can give wrong values as 4 and fail the test. But in realtime i dont see any possiblity of failing ?
i guess am little backward in understanding these concepts. I do understand the code but am trying to get the insights !! Hope somebody can help me !
The system under test (SUT) in your example is the Service class. Naturally, the field _service uses the true implementation and not a mock. The method tested here is AllItems, do not confuse with the list() method of IRepository. This latter interface is a dependency of your SUT Service therefore it is mocked and passed to the Service class via constructor. I think you are confused by the fact that AllItems method seems to only return the call from list() method of its dependency IRepository. Hence, there is not a lot of logic involved there. Maybe, reconsider this example and add more expected logic for the AllItems method. For example you may assert that the AllItems returns the same elements provided by the list() method but reordered.
I hope I can help you with this one.
1.) As for this one, your basically testing he count. Sometimes in a collection, the data accumulates so it doesn't necessarily mean that each time you exectue the code is always 3. The next time you run, it adds 3 so it becomes 6 then 9 and so on.
2.) For unit testing, there are a lot of ways to fail like wrong computations, arithmetic overflow errors and such. Here's a good article.
The test is supposed to verify that the Service talks to its Repository correctly. We do this by setting up the mock Repository to return a canned answer that is easy to verify. However, with the test as it is now :
Service could perfectly return any list of 3 made-up strings without communicating with the Repository and the test would still pass. Suggestion : use Verify() on the mock to check that list() was really called.
3 is basically a magic number here. Changes to theList could put that number out of sync and break the test. Suggestion : use theList.Count instead of 3. Better : instead of checking the number of elements in the list, verify that AllItems() returns exactly what was passed to it by the Repository. You can use a CollectionAssert for that.
This means getting theList and _mockRepository out of TestInit() to make them accessible in a wider scope or directly inside the TestMethod, which is probably better anyways (not much use having a TestInitialize here).
The test would fail if the Service somehow stopped talking to its Repository, if it stopped returning exactly what the Repository gives it, or if the Repository's contract changed. More importantly, it wouldn't fail if there was a bug in the real implementation for IRepository - testing small units allows you to point your finger at the exact object that is failing and not its neighbors.

VB6 and Delphi - TStringList is free by VB

I have the following situation:
An object is instantiated in VB6 using OCX made ​​in Delphi.
when I
...
Dim x As New spdComponent
Set x = spdComponent.ConverterType (XML)
count = x.item.count
TXT = ""
...
Count receives the value of all items of the TStringList OCX correctly, but soon the line below, where TXT gets empty, the value of 'x.item.cout' is lost.
When I debug in Delphi, in reality what happens is a TStringList be released from memory, but this happens without any sense (it seems that there is a conflict of interest between Delphi and VB).
Searching here and on google, I saw that many commented about not using TStringList but PChar, it would be a more appropriate way of working, but the question remains as to make use of C # 2005 and the same OCX, the problem is not occurs. (as in other languages​​, only in VB 6, so far).
Well, I have evidence that the VB kills the object (TStrinList) because for him, that object is not longer necessary, but it does.
One strange thing that happens is, if I
count = spdComponent.ConverterType(XML).item.count
It's work, do all the necessary processes without any error, but that first case, the error still remains.
Has anyone encountered similar problems?
Thanks guys, anyone who can give me a hand ... will be grateful
AFAIR, VB Classic uses reference count semantics for management of memory. This means, somewhere in your code, all references to the instance created by spdComponent.ConverterType(XML) are cleared (pointing to Nothing) or got out of scope.
EDIT: in you code you're destroying the instance created by Dim x As New spdComponent when you do Set x = spdComponent.ConverterType (XML). Maybe you could test this:
' Removed the instantiation on the declaration
Dim x As spdComponent
Set x = spdComponent.ConverterType (XML)
count = x.item.count
And tell us if something changed...

What does a EClassNotFound raised at runtime really mean when the class in question is there at compile and link time, and there explicitly in code?

I have a runtime error happening in the rtl Streaming in of a form, causing an exception EClassNotFound to be raised, while doing TReader.ReadRootComponent. The particular error message is "Class not found TActionList".
What is odd is:
My main form uses Action list.
For fun, I added ActnList.pas (from the VCL source folder) to my project, to try to fix it.
This happens to me when instantiating a form that I had working until a few minutes ago. The change that I made was in some sub-frame code: I removed all its implementation section code with an ifdef marker, because I am mocking up some frames, for unit testing and prototypes.
I tried adding the action list class to the project, and I tried with and without various compiler and link options, and yet, I still get this exception. Obviously something weird is up. There must be another weird way to get this problem.
In fact, it seems there is something really weird going on. When this error is raised, I get the following call stack:
rtl.Classes.ClassNotFound('TActionList')
rtl.Classes.TReader.FindComponentClass(???)
rtl.Classes.FindExistingComponent
rtl.Classes.TReader.ReadComponent(nil) /// NIL!? WHAT!!!!!
rtl.Classes.TReader.ReadDataInner(???)
rtl.Classes.TReader.ReadData(???)
rtl.Classes.TComponent.ReadState(???)
vcl.Controls.TControl.ReadState(???)
vcl.Controls.TWinControl.ReadState($60B9CF0)
vcl.Forms.TCustomForm.ReadState(???)
rtl.Classes.TReader.ReadRootComponent($606EB90)
rtl.Classes.TStream.ReadComponent($606EB90)
rtl.Classes.InternalReadComponentRes(???,???,$606EB90)
rtl.Classes.InitComponent(TComplexFormContainingFrames)
It seems the nil is intentional, in TReader.ReadDataInner(Instance:TComponent):
while not EndOfList do ReadComponent(nil);
Update: I believe the answer to this question is to understand "serialization contexts" as Mason has mentioned. And, it's time to admit my own Stupidity: I removed the parent of the frame from the project, not realizing it was the parent of the frame. I worked around it being missing by stubbing the type declaration for TMyFrameParent as TMyFrameParent = class(TFrame), and this in turn lead to the condition in question. I am leaving the question here because I think it might be really handy in future to note when this exception occurs in arcane cases, and how to fix it. In particular, Mason has a really interesting bit of information about "serialization contexts" and how they apply to class-name-finding.
It means that the class wasn't found in the current deserialization context. Not all existing classes are registered for all loading. Each form class has RTTI containing references to the components it uses. To get this to work, make sure that your form (or frame, if this is a frame) declares at least one TActionList before the private tag:
TMyForm = class(TForm)
ActionList: TActionList;
OtherComponent: TSomeComponent;
private
//whatever
public
//whatever
end;
Use Classes.RegisterClass to register classes you want to use with the streaming system. Quote from the doc
Form classes and component classes that are referenced in a form declaration (instance variables) are automatically registered. Any other classes used by an application must be explicitly registered by calling RegisterClass if instances are to be saved. Once classes are registered, they can be loaded or saved by the component streaming system.
It seems that this happens when you copy a frame from one project to another project, and that frame inherits from something, and you fake the inheritance, but leave the "inherited" item descriptions in the frame dfm, items like this:
inherited ActionList: TActionList
Left = 520
Top = 576
end
This in turn results in the "current deserialization context" that Mason talked about, not containing the class. One fix is to change Inherited to object in all the above cases.
There is another way to get this error: put 'public' at the top of a form definition class. By default class members are 'published'. I accidentally added 'public' to the top of a form declaration and it produces multiple 'Class not found' exceptions at run-time.
I got a "EClassNotFound" error when I had a TLabel declaration present in my DFM file but there was no declaration for it in the corresponding PAS file. Somehow the form editor screwed up.
The error was not visible until I deleted all labels from my form except that particular "corrupted" one. It was difficult to hunt it down because that label was hidden under a panel.
One easy fix is to cut (ctrl+x) that label (once you find it) from the form and paste it back. This time the form editor will correctly insert a declaration for it in the PAS file.
There is yet another way to get this error: I have put 'private' at the top of a form definition class (because none of the elements were used outside the form).
So same like in previous answer (by Server Overflow): by default class members are 'published' and if you change visibility of a form declaration it produces multiple 'Class not found' exceptions at run-time.

Resources