Could someone help shed light on what is going on here?
If I do this in a C# program:
dynamic data = Json.Decode("{\"myObjects\": [ { \"id\": 1 }, { \"id\": 2 } ] }");
int id = data.myObjects[0].id;
I am able to access id and it is set to 1... everything is fine up until this point.
What I don't understand is why, when I'm debugging the program, I cannot view the contents of datain the Locals inspector. Instead it tells me this, as if it doesn't know how to process the array.
Error No further information on this object could be discovered
'data' is declared as dynamic type and thats why you cannot mouse over and see the value. You could still see the value if you add 'data' to Watch.
There seems to be a bug/limitation of Visual Studio (at least the 2013 version I use). If you put a watch on data, you can click on Dynamic View and see that it has stuff, but if you click on myObject (that is a DynamicJsonArray) you only get its "dynamic" part, and not its "fixed" properties (like the Length) and if you try to click on its Dynamic View you receive No further information on this object could be discovered... but if you create a watch for data.myObject, then you'll still have the unusable Dynamic View, but you can look at the "fixed" properties of the DynamicJsonArray (like the Length) and if you click on the Result View you can see the items of the array. See image:
The other answers did not work for me, but I found an alternative way to view the array contents in Visual Studio.
I have found that we can see the contents of the DynamicJsonArray in the Watch window (or IntelliSense), by looking inside the Non-Public members of the top level object. Inside that, we see the private _values member and inside that, we see the values. Upon opening the relevant value, we see the Key and Value members inside.
We can then proceed to open the Value node and then, the Results View, which will show the items in the array. We can then finally access the individual items in the collection
Related
I am trying to access a property value deep inside another received variable. I don't know the terminolgy so apologies but cant describe it properly which the image below.
I am using a Library called CmdMessenger, to send/recevie data over serial port.
I receive data back from the serial port using the libray, no problem. But There is some data I need to extract which is 'nested' inside the variable as shown in the Locals screenshot below.
I receive the 'arugument' variable at the top, and can read its immediate 'Arguments' property fine, but I wish to extract the data from the other highlighted 'arguments' property at the bottom of the list, which currently has 'PBC' as its value. See screenshot:
public static void SendFirmwareVersion(ReceivedCommand arguments)
{
//read value ok from root of that property.
string[] x = arguments.Arguments;
//Then need to read value from other property deep inside that?
}
This is not soemthing i've had to do before, so quite frankly wouldnt know where to start, but it seems possible as there data is there?
PS: Feel free to edit the title that describes what I am trying to acheive.
Thanks.
I have a System.Collections.Generic.Dictionary object in my code and am trying to view its contents while stopped at a breakpoint in the Visual Studio debugger. The Dictionary class in .NET of course contains a list of keys and values.
If I right-click on the loaded object, and try to drill down into its contents, I seem to get into an infinite loop. For instance, if I'm trying to see the contained keys, I expand the Keys element, which shows me a count, and another collection called "Non-Public members". I expand the latter, and get another dictionary object, which has a Keys element, which I can expand to get another instance of "count" and "Non-Public members", which I can expand, etc., etc.:
Using QuickWatch gives me the same result, so how do I actually view the keys contained in the object?
I know this issue is fixed in later versions of Visual Studio. However, for some of us who are stuck in an older version of VS here is a quick fix to see the keys of a dictionary.
Let's say we have a dictionary named 'dict'. We need the keys to see the values. So in a watch window do this:
dict.Keys.ToList()
That will allow you to drill down into the list and see the keys.
If you know the index of the key you want to you do the following:
dict.Keys.ToList()[1]
This will display the key at index 1.
Now you can take that key and see what the value is with:
dict[dict.Keys.ToList()[1]]
Of course you can replace the index into the keys list with the actual key value in another watch line if that is easier.
EDIT:
In addition, it is also possible to see the entries of a dictionary with the following in the watch window:
'dict.entries'
This will give you a list of entries to look through. Each entry will have a 'key' and 'value' property.
I have a simple class called SSR2 with one property.
public class SSR2
{
public string SSRs { get; set; }
}
in another class I am instantiating a list of SSR2 and add a new item to it. everything works fine and compile correctly, but int the quick watch something weird happens, or I am missing something. There are two properties which I never seen before : "Capacity" and "Count", and the capacity is set to 4, 3 of them are null.
Why am I getting this behavior ? normally I am expecting a list with direct access to members like below :
Thank for your help.
I had the same problem, I fixed it by going to Tools>Options>Debugging>General in Visual Studio, and unchecking "Show raw structure of objects in variables windows".
By unchecking this box you should see the elements of the list as in your second screen shot.
A list is using an array, but abstracts you from the details. It still has a size, and needs to know how many items it has, so when you approach the mad, it can allocate more space for it.
So, having a list of one item is silly, since the next time you want to add you'll have to cart a bigger array.
I guess it creates the allocation for four items, and grows as needed later.
I've been working on a debugger visualizer for Visual Studio for some time and while the actual visualizer works fine. The problem is that it always places itself at the top of the visualizer list when examining a variable which really annoys some of the users who rather have Text as the top one (since the top one is also default when opening VS).
I can't find any support for this on DialogDebuggerVisualizer or DebuggerVisualizerAttribute which were my first thoughts so I've been scouring SO/MSDN/Google for information on how to affect the sort order of the visualizers (preferably to put mine last in the list) but to no avail.
Below is how I register my visualizer, it then just shows a form based on the value that is being visualized.
using Microsoft.VisualStudio.DebuggerVisualizers;
[assembly: System.Diagnostics.DebuggerVisualizer(
typeof(Shorthand.VSAddins.JsonVisualizer.JsonVisualizer),
typeof(VisualizerObjectSource),
Target = typeof(string),
Description = "Json Visualizer")]
namespace Shorthand.VSAddins.JsonVisualizer
{
public class JsonVisualizer : DialogDebuggerVisualizer
{
protected override void Show(IDialogVisualizerService windowService, IVisualizerObjectProvider objectProvider)
{
var json = objectProvider.GetObject() as string;
var form = new VisualizerForm { Json = json };
windowService.ShowDialog(form);
}
}
}
Does anyone know if it is possible to affect the order of the visualizers or should I just let it be?
I don't think there is a solution. But there is a workaround:
Define your own Text Visualizer and put appropriate DebuggerVisualizer attribute before the attribute of your JsonVisualizer. The result will be that string will be readable by default and Json Visualizer can be chosen. A window with a multi-line textbox is not too much work.
It is probably not even necessary to write visualizer. It should be possible to use internal one but I don't know its name (Which class is used for "Text Visualizer"?).
It will always appear first, by design. The under the hood cast has found the best match for the variable it is reflecting on.
however, you could do either of two things. You could make the visualizer only appear when the sting contains ':'
Or you could use reflection to reorder the visualisers by adding them to the end of the collection in the order you want, then removing the originals from the collection.
For the latter you will most likely have to change the collection from readonly to writable. Via reflection.
There is no reliable source to draw on other than your will to succeed.
I guess that VS 'under the hood' can distinguish between type of string and type of xml quite easily, but Xml is just a string too, so a key question here would be, how does VS tell the difference between the two?
Could you dissect the VS XML visualizer to see how it works (even if you have to use reflector on the DLL to do it, you might get to see the method that works it out)
Recently I have faced with a very strange problem. My Action method must return JsonResult,and all is good untill the last break point before return (At this moment I have correct json result).Then in browser console I see error 500 (Internal server error).Nothing exception in debugger.When I start to chek every step in debugger with F10,F11 I have noticed something strange.Unexpected infinitive invokes to my model properties (sometimes to model properties,sometimes infinitive invoking functions and then model proerties).I decide that this infinitive loop provoked error (but I still misunderstanding why I couldn't see it in debugger - perhaps this is aspect of IIS debugging).Code hasnt got weak places (I dont show it because it will take much more than few space).I know that my question is not constructive in stackoverflow terminalogy but I hope that somebody has encountered the same problem.I need only ideas.Thanks.
SOLUTION
As noticed #mreyeros and # LastCoder self referencing can be the reason of such behavior.I have cheked my model in details and found this place:
private IEnumerable<CollegeEstimateModel> _initialModels;
public IEnumerable<CollegeEstimateModel> InitialModels
{
get { return _initialModels = _initialModels ?? CreateInitialModelsList(); }
}
where CollegeEstimateModel contains above properties
I have added [ScriptIgnore] attribute and all become ok.
You should start by checking to see if the model that you are trying to serialize to your JSON result does not contain a property with a self referencing property. For example you have an Order object that contains a collection of details. The detail record has a navigation property back up to the parent order, thus causing a loop during serialization of the order object. This is just a guess of course, but hope that it helps