Visual Studio Extension for Custom Memory Window - visual-studio

My custom tool window in a Visual Studio Extension package is supposed to evaluate custom expressions during debug sessions for VS2012 and VS2013. The final goal is to build a graphical watch window. Therefore, I must fetch the value of the expression result from the debug engine.
The evaluation works fine via
IDebugStackFrame2 -> IDebugExpressionContext2 -> ParseText
IDebugExpression2 -> EvaluateSync -> IDebugProperty2
The first problem here: On Visual Studio 2013 ParseText() does not correctly report errors. But the IDebugProperty2 retrieved is valid (for valid expressions). On VS2012 I get proper errors for invalid expressions.
This is where the real problem starts. The result Property2 represents a complex custom object. In order to visualize it, a specific property from one of its base classes needs to get retrieved. In my current attempt, I am using IDebugProperty2.EnumChildren() to walk along its members up to the right place in the class hierarchy, similar as one would do in the Locals window in Visual Studio:
[result] -> base -> Raw -> base -> Non-public Members -> [private field] ... a.s.o.
This is somehow working but introduces the following problems:
Problem 1: Get an internal member of some complex object
The members and their order received from EnumChildren() seem to depend on some factors, which are not obvious to me:
* Does the object has a Debug Visualizer attached? (VS2013 ignores enum_DEBUGPROP_INFO_FLAGS.DEBUGPROP_INFO_VALUE_RAW in EnumChildren and gives back the beautified version + a "Raw View" node, VS2012 works as expected)
* Is a 'Non-public Members' node shown? Sometimes it is, sometimes not - dunno from what it depends on
* Setting of 'Just my code' (? I read about it in several posts but couldn't really figure out a reliable rule)
* ... there must be other dependencies ?
This turns out to be a really hacky way of aquiring an internal member of some complex expression result object. What could be a better way? Using IDebugProperty3 and some Debugger Visualizer tricks? Any pointer would be great.
Problem 2: VS2012 fails to give memory bytes
Once I have the private member of the result object, I use IDebugProperty2.GetMemoryBytes() in order to 'serialize' its value (a plain System.Array) and transfer it to my Custom Tool Window. While this is working in VS2013, in VS2012 IDebugProperty2.GetMemoryBytes() always returns VS_Constants.S_FALSE. I am really out of ideas here. Since there is a Memory Window in VS2012, there ought to be some way to get this working here also? What am I missing?
The code used to query the memory API:
IDebugMemoryContext2 memCtx = null;
IDebugMemoryBytes2 memBytes = null;
// getting the memory context is working ok
if (tmpProperty2.GetMemoryContext(out memCtx) == VSConstants.S_OK
// VS2012 fails here, always returns S_FALSE, memBytes remains null:
&& (tmpProperty2.GetMemoryBytes(out memBytes) == VSConstants.S_OK)) {
...
Some more context:
OS: Windows 8 and 8.1
Visual Studio: 2012 / 2013
Tool Window built with MPF (C#) in VS2013, (removed all vers. 12 references from the package before deploying to VS2012)
Debug engines: C# and Visual Basic

Related

Visual Studio Intellisense describing the property/method not working

I was using Visual Studio 2012 and it used to give the description of a property/method, which doesn't seem to work in VS2019. Is there an option that I will have to enable for this to work?
Below screesnhot is an example of File Input/Output operation:
When I scroll/hover over ios::app, it should give a description "Append to the end of the file" which it does not.
Second concern is that it is giving me a lot of other options as well (marked as * in VS). Is there an option to disable that permanently?
Final concern is that, when I hover over a function, it will display the parameters that the function is expecting (Or list of suggestions if the function is overloaded). But for some reason, in the below case, it is displaying along with namespace. Is there an option to disable that?
public static constexpr std::_losb::_Openmode std::_losb::app = (std::_losb::_Openmode)8

Xamarin + Visual Studio 2017 on Android: how debug Exception?

I have taken over a Xamarin.Forms (C#) application from an external source for fixing.
Problem is, that the application does sometimes fail with a runtime error:
System.NullReferenceException: Object reference not set to an instance of an object
The message appears in the output console and in a separate message window in Visual Studio. Unfortunately neither gives any more information about the failed object, a source code line number or a classname, there is just the bare message. Furthermore the "Call Stack" window in Visual Studio is always empty --> I have no easy way to find out where the failure occurs in foreign source code, because virtually no documentation of the program flow exists.
Full source code is available, and I have re-built the application with "Debug" configuration.
Right now the only option I can think of is to scatter breakpoints and Debug.Writelines all over the source code to get an idea where the problem occurs.
Is this really my only option, or did I miss some setting somewhere, so I can retrieve more info, so I can somehow go straight to the code where the failure occurs?
Thx!

Visual Studio tries to locate AutoMapper's PrimitiveExtensions.cs

I have a model that I'm mapping to DTO. All the mapping should be set up correctly. I'm using:
Mapper.AssertConfigurationIsValid();
I retrieve the model from the db. Its properties, including its child entities are correct and they are exactly what is found in the tables.
However, when I try to map it to DTO:
var entity = myService.Get(id)
var dto = Mapper.Map<myDTO>(entity);
Visual Studio shows the Open File dialog and tries to open the file PrimitiveExtensions.cs. I can't stop the app, and I need to end Visual Studio from the Task Manager.
This problem occurs for only one particular model (and it's child entities). Does it occur because the mapping is not set up correctly?
Most likely your VS tries to open the source file because it breaks on a first chance exception. Usually you should be able to cancel the file open dialog and then analyze the call stack or simply continue running the code.
You can disable breaking on first chance exception in the Debug -> Exceptions dialog.
In case it isn't only a first chance exception but an unhandled one you can tell VS to not try to open the library code by enabling "Enable just my code" in Tools - Options - Debugging.

VS2010 Intellisense behavior change (not fixed by ctrl-alt-space)

My intellisense is running like normal, except that it doesn't show me the parameters of a function or any overloads.
If I type in
HttpWebRequest req = new HttpWebRequest(
I don't get to see anything about the constructor of HttpWebRequest. It's very annoying. This just happened in the last few days (I think) after I updated the Productivity Power Tools (again, I think).
I've tried playing with the options in Tools -> Options -> Text Editor All Languages and C#, and Auto list members is checked, and so is Parameter information.
Any ideas?
In .NET 4 the HttpWebRequest constructor is protected and marked as obsolete. That means you can only call the constructor from a derived class. If you complete the statement manually it should give a "inaccessible due to its protection level" compiler error.

Debugging in Dynamics AX

I'm facing some troubles still while learning, so I guess it tends to get worse once I play with the big kids: warnings in dynamics aren't as precise and informative as VS's, there are no mouse-over tips, and exceptions to show me exactly where I've got it wrong.
I'm just too used to Visual Studio, it's intellisense and all the tools (dynamics is quite new when compared to Visual Studio)
More than solving simple code issues, i'd like to learn how to solve upcomming ones i might have in code not written by me or anything else i'd solve in 3 minutes in Visual Studio, as well as tips on how to survive in dynamics ax without all the Visual Studio tools.
The code editor in Dynamics AX has some intellisense, typing the name of a table or class variable followed by . or :: will give you a list of fields or methods available for that item. After you type the ( to start a method call, a tooltip pops up with parameters available on that method. When starting a new line, you can right click and List Tables, List Classes, List Types, etc. Most of those commands are also available via Shortcut Keys. Note that the intellisense only works if all the code in the method up to the location of your cursor is syntactically correct.
Make sure you have updated the cross reference in your development environment (Tools/Development tools/Cross-reference/Periodic/Update). With an updated cross reference, you can right click an any table, field, class, method, extended data type, or enum in the AOT and choose Add-Ins/Cross-reference/Used by to see where that item is used in the system.
You can also use Tools/Development tools/Code explorer to view the source to the application with all types, variables, and methods turned into hyperlinks so you can click to go right to the definition of that item.
Another useful tool is Application hierarchy tree, available either under Tools/Development tools, or on the right click Add-Ins menu. This will show you the class hierarchy, so you can easily see, for example, that SalesFormLetter derives from FormLetter, which derives from RunBaseBatch.
In the editor, you can highlight text and right click to Lookup Properties/Methods or Lookup Definition.
If you are trying to track down where in the system a particular infolog message is generated there are two strategies to use:
Set a breakpoint on the first line
of the method Info.add(). Then when
you run the code generating the
message, you will pop into the
debugger as soon as the infolog is
generated. You can then look at the stack
trace in the debugger to see where the code is that
generated the message.
Run Tools/Development
tools/Label/Label editor and search
for the text of the message. Select
the Label ID of the message, then
click Used by to see where that
message is used in the system.
There is also http://www.axassist.com/ which extends intellisense and many other extensions
What these guys said already is very interesting and helpful.
I'd like to add that within AX in real life you are probably working with multiple contexts. e.g. Code running in the client, code running in server, code running in p-code and in IL, COM integrations, Enterprise portal and so on.
My point is, if you want to figure something out through debugging, you must first understand where the code(s) you'd like to debug is running.
Knowing that is important because you might have to allow debugging or give permissions in multiple places.
Examples:
Windows AD debugging users (add yourself)
Allow debugging on client
Allow it on server
Disable IL if you want to use MorphX, otherwise attach the process in VS.
Allow World Wide Web Publishing Service to interact with desktop for EP.
One last thing, you are starting to work with ax right now, perhaps you will need to work with AX7(Dynamics 365 for Operations). This version of the system works only with visual studio. It is still x++, but you have a lot of the things VS provides you.
Take a look on EditorScripts Class,On AX Editor you can use it by right click and choose "Scripts". It is a kind of intellisense that can make by your self, for example: here is my in-line comment whenever I type "mycom" and press "tab"
public void template_flow_mycom(Editor editor)
{
xppSource xppSource = new xppSource(editor.columnNo());
int currentline = editor.currentLineNo();
int currentcol = editor.columnNo();
Source template = "//Partner comment "+date2str(today(),123,2,1,3,1,4, DateFlags::FormatAll )+" at "+time2str(timenow(), 1, 1)+" by MAX - Begin\n";
template+=strRep(" ", currentcol)+ "\n";
template+=strRep(" ", currentcol)+ "//Partner comment "+date2str(today(),123,2,1,3,1,4, DateFlags::FormatAll )+" at "+time2str(timenow(), 1, 1)+" by MAX - End\n";
editor.insertLines(template);
//move cursor to the empty line between the comments
editor.gotoLine(currentline+2);
editor.gotoCol(currentcol+4);
}

Resources