Using Visual Studio 2015 and 2017 for debugging
Author: Orly24
Creation Date: 8/8/2015 2:03 PM
profile picture

Orly24

#1
Hello,
I am trying to debug my code using by using Visual Studio 2015 Express.
I followed the instructions of "Programming | How can I debug my trading strategies in Wealth-Lab?", but it didn't work out.
I saved the compiled files in the main folder of wealth lab as it was asked to,but when i tried to open wealth lab it didn't open at all.

In addition, i noticed that the folder of the strategies(of wealth lab) contains only xml files,do i need to create one also?

Thank you!
profile picture

Eugene

#2
Hello,
QUOTE:
I followed the instructions of "Programming | How can I debug my trading strategies in Wealth-Lab?", but it didn't work out.

Without reviewing the steps you could have taken incorrectly (for now), here's a couple of immediate suggestions:

1. Try targeting .NET 4.5 explicitly (.NET 4.6 is VS2015 default)
2. Don't leave any properties of your StrategyHelper class without real implementation but as auto-generated stubs throwing NotImplementedException
3. Mind the bitness e.g. don't put a 64-bit DLL into 32-bit WL installation

If this didn't help, please don't hesitate to copy/paste the entire strategy code as well as a walkthrough of steps you took re: compilation, configuration, destination directory etc.

QUOTE:
In addition, i noticed that the folder of the strategies(of wealth lab) contains only xml files,do i need to create one also?

This is the folder for preinstalled strategies used during installation. No further action required. All your strategies (rule-, code-based, combination - except compiled strategy libraries) are stored elsewhere (see Wealth-Lab User Guide > Data > Where data are stored?)
profile picture

Orly24

#3
Hi,
First of all thank you for the support.

The code was compiled in .NET 4.5 and the project is x64 bit so i think there is no problem in that area.
I added here the code (i used one of your strategies for checking).
Do you see any problem?

CODE:
Please log in to see this code.
profile picture

Eugene

#4
Like I said, just get rid of all those occurrences of NotImplementedException. Make them return a real value.
profile picture

Orly24

#5
It worked!
Sorry for not understanding you well.
Thank you very much!
profile picture

tomphm

#6
Hi Eugene,

I am using MS Visual Studio (Microsoft Blend for Visual Studio) to debug WLP code and got the following error message when perform a build.

Error: Unknown build error, 'Cannot resolve dependency to assembly 'WealthLab.Extensions.Attribute, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null' because it has not been preloaded. When using the ReflectionOnly APIs, dependent assemblies must be pre-loaded or loaded on demand through the ReflectionOnlyAssemblyResolve event.'

I following steps in the guide "Programming | How can I debug my trading strategies in Wealth-Lab? " and at step 10 - "Build Class Library.."

Could you please point me to where thing might go wrong? Am I using the RIGHT MS Visual Studio (should I use Visual Studio Express 2015 for Windows Desktop instead?) Thank you.
profile picture

Eugene

#7
Hi Tom,

I don't know if Microsoft Blend is sufficient, I've never used it. Visual Studio Express 2015 is the right version.

Following steps in the guide could NOT lead to that error because 'WealthLab.Extensions.Attribute' is a MS123 assembly not mentioned in the tutorial by Fidelity. Are you using the ActiveTrader Strategy Pack source for debugging? If so, please add a reference WealthLab.Extensions.Attribute.dll in VS.
profile picture

tomphm

#8
Thanks Eugene.
profile picture

edwkelly

#9
Hello,

I am using this link Programming | How can I debug my trading strategies in Wealth-Lab? to begin my development using VS 2013 for coding and debugging starting with a test project (testWLP.dll).

I think your document (item 9) is saying to output the dll to C:\Program Files\Fidelity Investments\Wealth-Lab Pro 6.

"Set the Output Path of the project, in the Build tab of the Project's Properties, to the Wealth-Lab installation directory. This will cause the resulting assemblies to be built into the Wealth-Lab folder, and this be visible to Wealth-Lab."

Problem is when I output the dll there, the WLP process runs but without the UI.

When I output the dll to C:\Program Files\Fidelity Investments\Wealth-Lab Pro 6\Data\Strategies, the app runs ok but WLP doesn't show the custom strategy or folder for me to select it after attaching to WLP from VS.

The little project and some screen shots are attached for your review.

Thanks for your help,
Ed
profile picture

Eugene

#10
Hi Ed,

QUOTE:
I think your document (item 9) is saying to output the dll to C:\Program Files\Fidelity Investments\Wealth-Lab Pro 6.

Exactly.

QUOTE:
Problem is when I output the dll there, the WLP process runs but without the UI.

WLP crashed because your code is incorrect. Your case is exactly covered by my posts #2 and #4 in this very thread.

QUOTE:
When I output the dll to C:\Program Files\Fidelity Investments\Wealth-Lab Pro 6\Data\Strategies,

This is not the right path. WLP won't scan for the binary strategy library over there.

Despite my repeated attempts to warn about leaving any NotImplementedException on the forum, new developers will still get caught into this trap. I'm going to edit the Wiki article to make this more evident... EDIT: Done.

P.S. Here's a fully functioning example of a Strategy library (requires a verified Wiki account to download):

Home - Strategies.ActiveTrader
profile picture

edwkelly

#11
Thanks for editing the document.
profile picture

edwkelly

#12
Is there a way to use VS for debugging strategies without having to go through all the steps outlined here?

I mean, it works ok (thanks) but it is time consuming to edit, reload, attach, etc. For instance, is it possible to save a stock distribution to a file or db so the strategy development could be done completely in VS and then deployed to WLP when completed? Or, is there any way to quicken the strategy development process using VS?

Thanks,
Ed
profile picture

Eugene

#13
QUOTE:
Is there a way

Sure there is: check out PrintDebug in the QuickRef.

QUOTE:
it is time consuming to edit, reload, attach, etc.

Not at all with Edit and Continue which now works in 64-bit mode too.
profile picture

edwkelly

#14
Hello,

I may be asking for too much here, but here goes... I am using VS2013 as the editor and I am not able to get Edit and Continue to work. Since you stated it should work is the reason I've reposted.

It would really be helpful if there was a way to get it to work but the question is.... Since WLP is attached to the dll when the edits are made, it makes sense that VS would be prohibited from overwriting the dll on the fly?

In any case, I've attached some clips so you can see the configuration. If E&C won't work here, would my options be PrintDebug in scripts or the steps mentioned above? For example, could I use a dataset in VS just to work with the data but not have a UI until deployment?

Thanks for your help.

profile picture

Eugene

#15
Hi Edward,

It's not about E&C. To stress my point from reply #10 above, you just have to set the correct output folder as per the article's paragraph #9: to the Wealth-Lab installation directory. No arbitrary subfolder is going to work. Since the Strategies folder is not designed to contain compiled strategies, WLP will not scan this folder and your library is invisible to it.
profile picture

edwkelly

#16
The folder is set correctly. I am beyond that. The dll is located here C:\Program Files\Fidelity Investments\Wealth-Lab Pro 6 and if I follow the steps of:

Close WLP
Make changes in VS build the dll
Open WLP
Select Strategy

on all code changes, everything works ok. What I am trying to do is speed up this process, somehow!
profile picture

Eugene

#17
Then why show the misleading ProjProp.PNG with incorrect output folder?

According to FileStat.PNG, WLP is installed into Program Files so this must be its 64-bit version. In VS2013, E&C will not work in 64-bit mode - only 32-bit. This limitation has been removed in VS2015. You could install 32-bit WLP or upgrade to VS2015.
profile picture

edwkelly

#18
super thanks.

BTW, I didn't show an incorrect folder in ProjProp.PNG. The path with file name is
C:\Program Files\Fidelity Investments\Wealth-Lab Pro 6\TestWLP.dll

Whoops, just saw it, my mistake. I apologize.
profile picture

edwkelly

#19
Would you be so kind as to send me your VS2015 settings that allow you to use edit and continue?

I have installed VS2015, adhered to the steps previously stated in this post, and set the configuration parameters as best I know how and still getting the Error screen attached.

Please let me know if I need to send further information.

Thanks for you patience
profile picture

Eugene

#20
Sorry, I don't have VS2015 installed on my dev machine currently and I was using E&C in 32-bit mode. If it weren't the Community edition I'd have recommended to disable IntelliTrace (which shouldn't be available to versions below Ultimate anyway). From what I see the project's code isn't optimized so this factor can be scratched off, too. Not sure if "enable native debuggers" affects E&C but I'd try disabling it. You're better off checking out StackOverflow on this one e.g. applicable solutions. Also, have you tried E&C with 32-bit WLP (after appropriate changes to the project's output folder)?
profile picture

edwkelly

#21
No luck. I installed WLP 32bit (attached pic) and getting the same error.

My problem is I need the VS editor to go forward, but If that's not possible I just need to know. Right now I have too many unknowns to continue with the trial and error, so please advise...

Attached is the little test project.

Thanks
profile picture

Eugene

#22
Surely E&C worked before for my DLL development (as this is my bread and butter). But as I've never been a frequent user of this feature, there's really not much I can suggest.Your best bet is to experiment with the advices on StackOverflow (see applicable solutions) or ask on SO.
profile picture

edwkelly

#23
With all due respect, I think the best bet is that what worked before does not work now.
profile picture

Eugene

#24
As a side note, if you have ever experienced a pesky nuisance in VS called "Breakpoint will not be hit" you'd know how painful can its troubleshooting get:

The breakpoint will not currently be hit. No symbols have been loaded

It doesn't mean that something's broke beyond repair, just you're not experimenting hard enough. ;)
profile picture

edwkelly

#25
? -- Have to say that's a first, informing a customer they are not experimenting hard enough on a problem that looks like it's yours.

I have experienced that problem in the past and usually it was because the .pdb file was either trashed or not being built correctly (or way back because too many break points were being used). But, I am not even getting that far in this process since I am simply posting a dll to be used by another process..

My bet is the first error I continuously get immediately in the dialog is correct: " Attached to a process that does not support Edit and Continue on attach".

As they say in Texas. Fish or cut bait.
profile picture

Eugene

#26
:) Well, as for me I'm not surprised when 3rd party issues or limitations are believed to be Wealth-Lab's!

I've just dusted my memory off and successfully applied E&C with 32-bit Wealth-Lab Developer. The trick is to not to attach to process: you have to start WL6 by striking F5 (Start) in Visual Studio and let VS load WLP with the DLL. At least my Visual Studio version warns that E&C will not work if attached to process. This technique was a must in the early days of VS Express when it didn't have the attach to process capability and so I wrote this KB article to describe it:link removed UPDATE 2017/08/30: The debugging tutorial has been updated to include a walkthrough to enable E&C.


Now I recall why I suggested you to take the ActiveTrader Strategy library project from the Wiki. Being a fully functional demo solution, it's preconfigured to output the DLL straight to the WLD folder (via WealthLab.Strategies.ActiveTrader.csproj.user file and "Build > Output path") and is ready for F5. To sum up the technique in the Wiki, you just have to:

1) edit the StartProgram tag in the .csproj.user file accordingly*:
CODE:
Please log in to see this code.

* If VS2015 Community has the option to start external program in Project Properties then you may probably have to skip the entire StartProgram tag step.
2) then load the solution in VS,
3) choose your WLP main folder in Build > Output Path (because it's preconfigured for Wealth-Lab Developer, not Pro),
4) then edit project's References (which point to 6 WealthLab DLLs in a folder unavailable on your PC**),
** One dependency is WealthLab.Components.Community.dll - either install the Community Components extension and restart WLP to apply OR simply delete the reference and any class(es) that may be using it.

...and you're off to F5. Voila, not a Wealth-Lab problem at all - it's a Visual Studio peculiarity like I implied. :)

Thanks for saying thank you.
profile picture

jheffez

#27
I was able to follow the steps and debug a simple WL script via VS2015 express (pretty cool!) Keyword is simple however. Due to the limitation of it being a class and thus can't implement drawings and forms such as lines. This is a deal breaker since all my scripts have some sort of drawing/chart annotation.

. Any advice on how to overcome this limitation?

. Clearly, I can see how VS can save hours thanks to its powerful debugging. Are there any plans to have WL use Visual Studio natively or be more tightly integrated? Or at least add to WL better debugging? I'm sure everyone will greatly benefit from this.

Thanks,
Jake
profile picture

Eugene

#28
QUOTE:
Are there any plans to have WL use Visual Studio natively or be more tightly integrated? Or at least add to WL better debugging?

No, as the design has always been like that.
QUOTE:
Due to the limitation of it being a class and thus can't implement drawings and forms such as lines

There is no such limitation and I don't think that this question has to do with VS debugging. Please start a new thread and there provide more insight into what you're after. Thanks.
profile picture

Eugene

#29
jheffez wrote in a thread that doesn't exist:

I am able to debug in Visual Studio (2017) using the howto link. Meaning, create a class with the strategy, attach to WL process and F5/debug. However, when changing the code in VS and pressing F6 to rebuild I get the error below since WL is using/locking the class file so VS can't write the updated one. Closing all strategies/open windows in WL does not help. So, I have to close WL and repoen each time I change the code. Is there something I'm missing? There must be a better way to accomplish this.

VS error:
Severity Code Description Project File Line Suppression State
Error Could not copy "obj\Debug\MyStrategy.dll" to "..\..\..\..\..\..\..\Program Files\Fidelity Investments\Wealth-Lab Pro 6\MyStrategy.dll". Exceeded retry count of 10. Failed. ClassLibrary1
profile picture

Eugene

#30
You have to run Visual Studio as administrator. (Added a note to the How-To).

P.S. If set up properly, Edit and Continue in 64-bit VS Community works perfectly with Strategy libraries. Some changes to the code require a restart, though. Here's a list, for example:

Unsupported Edits in Visual Basic Edit and Continue
profile picture

jheffez

#31
Yes, I am running VS as admin.
WL locks the class file and won't let VS to rewite it. Once I open the strategy class from WL it's locked and VS can't write to it, even in administrator mode. Can you please clarify the order of things after changing the code in VS?

Edit/continue is set in VS, see screenshot attached.
What other settings I need to watch for?
profile picture

Eugene

#32
Please review post #26 right above. It's stressed there that you should not use "Attach to Process" for "Edit to Continue" to work. Here's a sample of a *.csproj.user file that enables to launch WL6 from your VS solution:

CODE:
Please log in to see this code.


P.S. The majority of our demo extensions comes with this file integrated:

Download Project Source Code
profile picture

jheffez

#33
Ok, gotcha. So I added the external WLP.exe path. I also saved as default the precompiled strategy workspace window to open in WL.
Now when I press F5 from VS it automatically launches WL and runs the precomplied strategy. But when I press the stop button in VS it closes WLP completely. There is a delay for WL to load and run each time I change the code. Is that to be expected? Is there a way to keep WL running to speedup the debug?
profile picture

Eugene

#34
The magic of "Edit and Continue" works instantly. There's no delay to load and run WLP each time you change the code. You never do it unless your code imposes a limitation on E&C - see link in post #30.

Set a breakpoint in your code in VS and when it's triggered (by itself or by a condition you've set), your Strategy code can be edited on-the-fly in VS while the breakpoint remains hit.

If you're not sure how to work with breakpoints, you might find studying some Visual Studio reference useful.
profile picture

psimmons

#35
I am new to Visual Studio. I'm running Miscrosoft Visual Studio Community 2017 on Windows 10.
I have tried to follow the wiki instructions in Programming | How can I debug my trading strategies in Wealth-Lab?

I think I have targeted .Net Framework 4.5.2 correctly. The New Project I open is Visual C# .Net Standard Class Library with .Net Framework set to 4.5.2

I think I have added WealthLab as a reference correctly because autocomplete and IntelliSense recognise it.

I think I have added the Guid correctly, but am not certain.

My primary problem is that when I derive the TestStrategy class from WealthScript, then Wealthscript is flagged as an error: The type 'Object' is defined in an assembly that is not referenced.You must add a reference to assembly mscorlib. When TestStrategyHelper is derived from StrategyBuilder then it also has a similar error.

In addition the WealthLab wiki step 6 says "For the WealthScriptType property, return a pointer to the Type of the main Strategy class." I'm afraid I don't understand what I need to do here. I don't understand where in the code to place return "typeof(DailyBuyer); " Could you give me some extra guidance here.

Presumably my main issue is the adding of a reference or my targeting of the .Net Framework is incorrect, but I can't find my mistake.
Thanks
Phil

My code is below:

CODE:
Please log in to see this code.
profile picture

Eugene

#36
Here's what went wrong:

1. You've put "return ..." where it's not applicable in C# i.e. outside of a method body. A method must have a type to return (or void) but here (in a class) it generates a compiler error.
2. Also, your curly braces are placed inappropriately regardless the "return" cause's position.
3. Finally, don't inherit from "StrategyBuilder" - this class is not meant to be used in Strategy creation, development or debugging.

As Step 6 (which has confused you) states, "Use code completion to provide stubs for the required properties. The Strategy Helper class returns properties that describe details about the Strategy that are needed by Wealth-Lab. Implement the properties in the code of your helper class."

I agree on that it may sound confusing. Simply put, it's meant to say this: "inherit a class from StrategyHelper and then hover over the interface name in your code, then right click the blue underline and choose Implement Interface". That's all to it - the rest is Visual Studio magic. With reduced and cleaned up template below you should be able to do it, and here's a couple of screenshots that are worth a thousand words:

How do you auto-implement an interface in C# 4.0 & Visual Studio 2012?
Implement Interface vs Implement Interface Explicitly in C#

CODE:
Please log in to see this code.


P.S. Please pay attention to advice in bold in Step 8 or your strategy library will crash WLP on startup.
profile picture

psimmons

#37
Eugene,
I finally got it!

In addition to your feedback I needed a NuGet package
PM> Install-package Microsoft.NETCore.Portable.Compatibility

My issue is described here:
https://stackoverflow.com/questions/27678071/asp-net-core-5-0-error-cs0012-the-type-object-is-defined-in-assembly-mscorli

This is why I did not see the blue underline auto code completion.

Therefore below is the code I generate:

CODE:
Please log in to see this code.


If you see anything wrong then please let me know.
Thank you for your support.
Phil
profile picture

Eugene

#38
Phil, thank you for the feedback. I haven't encountered this very odd autocompletion issue before. Perhaps it has to do with VS2017 and targeting. AFAIK, recent builds of WLP 6.19.x already target .NET 4.6. Maybe it's the choice of .NET 4.5.2 that caused the autocompletion failure in VS2017? I don't know - I'm not a VS2017 user and am pretty happy that I've picked VS2015 when upgrading from VS2012 recently as VS2017 had some bad press from the user community. Anyway, glad to help.
profile picture

psimmons

#39
Visual Studio is working well for me, however I continue to run into occasional framework compatibility issues.

In one strategy I insert a delay using:
CODE:
Please log in to see this code.


Initially this reported:

CS0234 The type or namespace name 'Thread' does not exist in the namespace 'System.Threading' (are you missing an assembly reference?)

It was solved by loading the .NET "System.Threading.Thread" NuGet package in addition to the Microsoft.NETCore.Portable.Compatibility NuGet package.

Then in another strategy I use:

CODE:
Please log in to see this code.


and this reported the same missing reference, and was solved by either (i) using the legacy syntax example described in
http://www2.wealth-lab.com/WL5Wiki/EnterAtPrice.ashx?HL=enteratprice
or (ii) by loading the same .NET "System.Threading.Thread" NuGet package.

As noted before I am running Visual Studio Community 2017 Version 15.4.0 on a Windows 10 machine, and reverting backwards to VS2015 now does not appeal to me, but I think if I was doing a new installation then I would use this version.

I currently have no issues but I don't understand what is happening here. I don't understand why EnterAtPrice would have a Framework compatibility issue when all other WealthScript functions that I use work as expected.

profile picture

Eugene

#40
Given that you said that you targeted 4.5.2 (I think 4.6+ will do for WLP 6.9.19), it's hard to understand why some crucial and commonplace elements like System.Threading.Thread look missing and have to be installed through NuGet. Are you sure you're not creating a new style portable library instead? This might explain that less APIs are available out of the box.

https://stackoverflow.com/questions/39223271/when-is-it-necessary-to-add-the-nuget-package-microsoft-netcore-portable-compati

QUOTE:
I don't understand why EnterAtPrice would have a Framework compatibility issue when all other WealthScript functions that I use work as expected.

This is not a native WealthScript function, rather an extension method. I'd even expect the opposite to happen (i.e. the legacy syntax would raise a warning) since "legacy" methods are marked with [Obsolete] attribute.

At any rate, running VS 2015 Community Update 3 here w/o issues.

UPDATE 10/24/2017:

And if you run into many problems with VS2017, consider giving SharpDevelop a chance :) I use it on my Windows tablet for development on-the-go.

SharpDevelop 5 download

With its installer size of 13 Megabytes it contains everything you need to build and debug WealthScript Strategies. Yes, that's 500 times less the size of the VS2015 Community offline installer or 1,500 times smaller than VS 2017 Community downloaded to your disk (to prepare an offline installer yourself since MSFT has removed this feature for legal reasons):

What is the download size of Visual Studio Community 2017 installation files using WebClient?
profile picture

algtrader

#41

Just putting in my 2cents worth. VisualStudio Community 2017 is great. One of the few pitfalls to watch out for is make sure all you're target a .NET Framework 4.5 or 4.6 and not .NET Core for projects involving WLP.
profile picture

Eugene

#42
Thanks Al, I've added a note to the Wiki tutorial on debugging.

Despite psimmons saying he thought he targeted 4.5, the need to install Microsoft.NETCore.Portable.Compatibility and "System.Threading.Thread" NuGet packages just should not arise.
profile picture

psimmons

#43
I finally discovered my previous issue discussed in comment 39 that was causing me to install NuGet packages in Visual Studio 2017.

It was my confusion between .NetFramework and .NetStandard. One of my projects in my solution was .NetStandard2.0. The need for NuGet packages was resolved by converting this to .NetFramework.

I briefly tried earlier versions of .NetStandard but could not get this to work, but perhaps further effort would succeed.

So in addition to not using .NetCore my suggestion is don't use .NetStandard either. And, as the wiki says, stick with .NetFramework.
profile picture

Eugene

#44
It's good to know that a dependency that targets .NET Standard (or other non-standard framework for Wealth-Lab 6.9 - pun intended) can lead to the effects described above.