Debugger.Launch() on windows service in Windows 8 - c#-4.0

After I installed Windows 8 perfectly legit statement like this doesn't work anymore:
#if DEBUG
Debugger.Launch();
#endif
Service starts ignoring that thing.
Yes, I am building the project in a debug mode.
if I change that to a Debugger.Break() - the service just fails, and still there's no dialog for attaching a debugger.

The secret lies in changing the registry key for the Visual Studio JIT debugger via the following:
reg add "HKCR\AppID\{E62A7A31-6025-408E-87F6-81AEB0DC9347}" /v AppIDFlags /t REG_DWORD /d 8 /f
Before making this change the value on my machine was 0x28. The above changes it to 0x8. In essence it removes the 0x20 flag.
If you search the Microsoft include files (WTypesbase.h) then you find the following:
#define APPIDREGFLAGS_IUSERVER_ACTIVATE_IN_CLIENT_SESSION_ONLY 0x20
Once you make this change then the JIT debugging window is displayed again. I believe that all of this relates to various session 0 security changes made by Microsoft.
Sourced from this post:
http://forums.arcgis.com/threads/69842-Debugging-your-SOE-on-Windows-8

Debugger.Launch would launch an application with a visual GUI. By default services do not interact with a desktop and thus anything they do cannot be "seen".
Support for interacting with the desktop has slowly been removed from Windows services ("Interact with the desktop" option has been removed from some Server versions for example). I would imagine they've continued this trend.
Windows Services by nature are not GUI applications, they can run before and after a user logs into a desktop and thus cannot show a GUI all the time. It's not generally a good idea to depend on an ability to have a GUI in a Service.
If what you want to do is debug a service, I suggest running it as a regular application so that you can do things like Launch and Debug. Shameless plug: you can see Developing Windows Services in Visual Studio for a way to write a service that supports that.

Is this a Windows Store app or a desktop app?
Try right-clicking on your project (the C# executable project if that's what you have) and selecting "Properties". Then in the left sidebar of options, click "Debug". In the "Start Action" section, check the box for "Do not launch, but debug my code when it starts".
Now you can hit F5 and run Visual Studio with breakpoints in your code, and it will sit and wait for you to fire up the process. Then run your application (outside of Visual Studio), and Visual Studio will attach the debugger.

Related

Visual Studio 2019 Processes not shutting down, NodeJS issues

I am working on a fresh install of Windows 10 Pro (10.0.18362) and trying to get Visual Studio 2019 setup and configured for .NET Core 3.1 Web Development but am running into several issues.
I created a default React.js ASP.NET Core Web Application and ran the project. Things seemed to be working alright, except that after updating JavaScript code the browser updates after a fairly long pause; things seem to be lagging.
After closing Visual Studio 2019 from the default Web App (no updates) there are several processes that seem to hang, and have to be shut down manually:
I have tried installing Visual Studio 2019 with the Node.js provided by the Visual Studio Installer, in addition to installing Node.js V12.4 and V13.6 manually with the same results.
Another problem: If I update the project from JavaScript to TypeScript using npx create-react-app client-app --typescript, Hot Updates stop working entirely. But after updating the JavaScript code and refreshing the browser things seem to update, so it does seem to be recompiling. I have tried debugging in Firefox and Chrome, both with the same results.
I am very hesitant to continue working with this install as I have had several issues when these processes. If these hang unexpectedly and are not shut down they will continue to use the old versions of the code and nothing that is done will update until the processes are shut down, causing complete insanity.
Could there a specific install procedure I need to perform as a workaround? Or am I possibly missing NuGet packages or Add-Ons? Since this is a fresh install of the operating system, are there Windows Features that I need to install? Or other configuration/permission changes that could be causing this?
Prior to this install, only projects created in Visual Studio 2017 seemed to work as expected. But I need to develop this site in .NET Core 3.0 and it looks like only Visual Studio 2019 is supported for that.
Update
After some messing around, it looks like Node is causing the problems. If I manually shut down the Node processes, then Visual Studio will finally shut down—but it leaves other processes like the VSCompiler and Consoles running. This happens even if I run Visual Studio as an administrator.
Should I install node before Visual Studio, or visa versa? Is there possibly some setup that I need to perform with Visual Studio or Node to get things working correctly?
Update 2
After not finding any fix I tried a complete reinstall of Windows, including a disk format, and then only installed Visual Studio and Node.js.
One interesting thing I found when doing this: I originally only installed Visual Studio and selected both the "Web Development" and "NodeJS Development". But when I tried to run a new .NET Core Web Application without any changes, I received an error saying that Node.js was not installed—even though I was able to find a node.exe in the MsBuilds folder under Visual Studio.
I completely uninstalled Visual Studio and all other components, installed Node.js, and then Visual Studio, but the problem still persists. Any time I try to run any kind of JavaScript using the SPA Templates, the Node.js processes don't shut down. If I kill the Node.js process then Visual Studio will finally shutdown, but it leaves the Console Window Host and VBCSCompiler running which have to be shut down manually.
I also tried creating a new .NET Core Web Application, except this time selecting the Angular Template and it works better: The Hot Reload works and it seems to run much faster. But the processes still don't shut down. The only difference is killing the Node.js processes doesn't let Visual Studio shutdown.
Update 3
Also not sure if this helps, but I tried setting the node.exe properties to "Run this program as an Administrator" to see if it happen to be a permission issue. This yielded the same results. I noticed that two windows will pop up, however: First a blank one, then the actual Angular server window.
I'm not sure if it's related, but when I tried to run the Angular Application again it looks like Angular is pointing at another (random) port than is set in the debug settings in the project.
One thing I did notice is that the usual Server Messages are not showing in the Output Window. It used to display the node.js messages such as "the server is running" and other compiler messages, but now it only displays the .NET output.
Update 4
Getting closer, I uninstalled Visual Studio and Node.js, then made sure to clean out any left over Visual Studio and node_modules folders from my AppData and User/Local directories, and then did a disk cleanup. Finally, I reinstalled Visual Studio—making sure to run the installer as Admin—and reinstalled Node.js.
I ran Visual Studio as an admin and created a new Angular App. Now, the Angular app works as expected, HMR works and things seem to run smoothly except that the processes still hang. The major difference is that killing the Microsoft Visual Studio 2019 process kills everything, whereas before it was leaving the VBSCCompiler, Node.js and consoles running.
When creating a React App things load fine. But, again, the HMR doesn't work and also leaves processes running. shutting down the main Visual Studio process seems to clean these up now too.
I'm afraid I don't have a fix but if anyone wants a quick way to kill all the errant node processes and speed things back up they can run:
taskkill /IM "node.exe" /F
I haven't had any issues executing this while VS is running.
In Visual Studio 2019, go to Tools, Options, Debugging, General and towards the bottom there is a checkbox for Automatically close the console when debugging stops. It is unchecked by default on new versions of VS and if you look at your ASP.NET Core project properties you will see that it is a console project. So without the checkbox checked, the console does not automatically close.
The problem is that it is a hidden console so you can't see it to shut it down manually. If you check the box for closing the console automatically, then the consoles and node.js will stop running whenever you stop the debugger. Also in Options, there is a Node.Js Tools area that you may want to look at as well. It has a checkbox for Wait for input when process exits abnormally. If the console is hidden, there is no way for you to do input so that could hold the process open as well.
Another option, if you don't want to change any of the debugging options, is to go to your project properties > Debug and change the Launch settings for the IIS Express profile to Project instead of IIS Express. This will actually make the console / command prompt visible and when you are done debugging you can Ctrl-C to stop the debugger or when you hit stop the console will give you the message to Press any key to close this window . . .
I had the same issue with React SPA, this worked for me:
Tools -> Options -> Debugging -> General -> Enable JavaScript debugging for ASP.NET (Chrome, Edge and IE) (Visual Studio 2017 and 2019) <- unchecked
also the dropdown next to the play button:
Script Debugging -> disabled
There are possibilities to run pre and post build tasks in Visual Studio. I would look for them in project settings.
I use VSCode. So, if you follow the explanation below you'll be able to tackle the problem.
Create a .bat file in your project root folder (for instance kill-node.bat) with the followwing content:
tasklist | find /i "node.exe" && taskkill /im node.exe /F || echo process "node.exe" not running.
Add a pre-build-task executing the .bat file
Add a post-build-task executing the .bat file
Done! Now every single time you start debugging/redebugging your app, the .bat file kills all node-zombie instances. And ditto for your stopping dubug moment.
The VSCode guide:
Perform step 1 of the algorithm above.
Open the file tasks.json in .vscode folder and prepend at top of its tasks the new one:
{
"label": "kill-node",
"command": "kill-node.bat"
},
Now alter the build task code (to activate our kill-node task at the pre-build time):
{
"label": "build",
"dependsOn": "kill-node", // <<< extra string to run kill-node task prior to build task
"command": "dotnet",
//... the rest of build task code
}
Open launch.json file and insert new string:
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"postDebugTask": "kill-node", // <<< extra string to run kill-node on debug end
//... the rest of launch.json file
}
}
That's it. Now you can no longer care of the node-zombie instances consuming your memory.
This should be fixed in ASP.NET Core 5.0, try upgrading if possible.

Visual Studio Extension to attach debugger to remote process running in .NET Core on Linux

I'm using Visual Studio 2019 to develop a .NET Core 3 application which runs on embedded Linux. I am able to build the code in Visual Studio 2019. If I copy the binaries manually to the Linux machine and then start the application running there then I am able to attach the Visual Studio debugger to the remote process over SSH in Linux and debug the application. This does work, but it's tedious to deploy it, start it and attach the debugger manually for each debug session. I do have a script in Visual Studio Code which works, but I want to use Visual Studio Professional.
I'm trying to write a Visual Studio Extension so that I can press a key in Visual Studio to have the application built, deployed, started and then connected to the debugger. I would then share the extension with my team. It's very nearly working, except for attaching the debugger.
In the extension I am able to list the processes running in the Linux machine and select my application using this code:
EnvDTE100.Debugger5 debugger = (EnvDTE100.Debugger5)dte.Debugger;
EnvDTE80.Transport transport = debugger.Transports.Item("SSH");
EnvDTE80.Engine engine = transport.Engines.Item("Managed (.NET Core for Unix)");
EnvDTE80.Process2 process = (EnvDTE80.Process2)debugger.GetProcesses(transport, "192.168.11.1").Item("app");
process.Attach2(debugger);
There are two problems:
The call to GetProcesses() opens a dialog where I need to enter the Linux username and press enter, how can I specify the username in code to avoid the dialog appearing?
Even though the selected process looks like the right one (process.ProcessID matches what I see in Linux if I run the ps command), I get an exception when I call Attach2(). The exception message is "Exception from HRESULT: 0x8971001E"
I feel like I'm really close to getting this to work, any suggestions for how to finish it?
I also solved the second problem by changing the parameter passed to Attach2() from debugger to engine, as shown below:
EnvDTE100.Debugger5 debugger = (EnvDTE100.Debugger5)dte.Debugger;
EnvDTE80.Transport transport = debugger.Transports.Item("SSH");
EnvDTE80.Engine engine = transport.Engines.Item("Managed (.NET Core for Unix)");
EnvDTE80.Process2 process = (EnvDTE80.Process2)debugger.GetProcesses(transport, "root#192.168.11.1").Item("app");
process.Attach2(engine);
I found out how to add the user Name, but not the Password:
In GetProcess(), set transportQualifier to $"{userName}#{hostName}".
The 1st time the Window will still Pop up and ask for the Password.
But after that VisualStudio has stored the connection including the password.

MPI debugging with VS2012

The cluster debugging option is removed from Visual studio 2012.
So is there any way to debug MPI apps in VS2012 ?
Visual studio 2012 and later versions do not support MPI debugging. However there is a workaround:
Start debugging by specifying mpiexec.exe as your command and related parameters and the name of your executable as command arguments:
Command-> mpiexec.exe
CommandArguments-> -n 2 myapp.exe
When the execution starts, use Debug->Attach to process... to attach the debugger to one your processes. Sometimes I add a simple press any key to continue logic to my app, just to pause the program until I finish this attaching process.
In order to ease tings you can use an extension called Reattach that lets you attach to the last processed you attached with one button click.
One problem with this workaround is that you cannot select which MPI process you attach :(

Where are the scan settings stored on ce 5.0 MC9090? They are not in the registry that I can see

We are using MC9090's running CE 5.0. We are using a program called Wavelink Studio Client to access our scan application. Studio Client is different and not the same as Wavelink Telnet CE. Wavelink Studio is only a "Go Between" and does not hold any settings. The Wavelink Studio basically looks at the scanner .dll and pulls settings from that.
My problem is that I have an Interleaved 2 of 5 barcode with 16 length. The MC9090 comes with two demo programs ScanWedge and ScanSamp. I can modify the length for int 2 of 5 in either of these programs and my barcode will scan through Wavelink Studio Client. However, after a warm boot I lose all my settings since these are just demo programs.
So, I turned to DataWedge. Which uses its own config folder to store settings, but I assume loads the settings into the scanner .dll. My barcode scans perfectly in Studio Client when DataWedge is installed only after the DataWedge process has been "Stopped" then "Started". If perform a warm boot and DataWedge starts... my barcode will not scan through studio client until DataWedge has been Stopped, then my barcode will scan through Studio Client whether DataWedge is Started or Stopped.
My question is: Is there a script/command line/bat/etc. that I could use that would "Stop" DataWedge, then "Start" DataWedge after a warm boot? This is one way to solve my problem.
If anyone has any other suggestions, please let me know. I have repeatedly been told that the settings from ScanSamp and ScanWedge (demo apps) are not stored anywhere on the device. I believe they are stored somewhere though. Because, when I make a change on DataWedge, I can open ScanWedge and the settings happen there to. So there must be some central location where the hard scan settings are stored? I just need to be able to edit the settings in this location and have them stay there. I don't even need DataWedge if the scanner would hold the settings in the .dll that I specify from ScanWedge. With datawedge uninstalled, I tried changing my settings in ScanWedge then using RemCapture to capture all the settings from the device.. I then loaded those settings onto another device to see if it would load the scan settings, but it did not.
Set the options in ScanWedge. Then Use "Remote Registry Editor" that comes with Visual Studio 2008 and go to this path: [HKEY_CURRENT_USER\Software\Symbol\ScanWedge]
There you will see the various settings for ScanWedge. To persist these settings over warm & cold boot do the following:
Open Notepad on the PC.
Type the following registry entry:
[HKEY_CURRENT_USER\Software\Symbol\ScanWedge]
"AutoEnter"=dword:00000000
"AutoPIE"=dword:00000000
"AutoTab"=dword:00000000
"Binary"=dword:00000000
"Data"=dword:00000001
"Escape"=dword:00000001
"Prefix"=""
"Suffix"=""
Save the file as scanwedge.reg
Place the file on your Terminal in the \Application Folder using ActiveSync.
Cold boot the terminal.
NOTE: A cold reboot will erase all files, except the application and platform folder. Save your files before cold booting.
Hope this helps.

How can I sign a Windows Mobile application for internal use?

I'm developing a Windows Mobile application for internal company use, using the Windows Mobile 6 Professional SDK. Same old story: I've developed and tested on the emulator and all is well, but as soon as I deploy to advice I get an UnauthorizedAccessException when writing files or creating directories.
I'm aware that an application installed to a device needs to be signed but I'm running into roadblocks at every turn:
Using the project properties 'Devices' window I select 'Sign the project output with this certificate, and choose one of the sample certificates from the SDK. This results in a build error: "The signer's certificate is not valid for signing" when running SignTool.
If I try to run SignTool.exe from the commandline, I get an error telling me to run SignTool.exe from a location in the system's PATH.
I can't use the 'Signing' tab in the Project Properties to create a test certificate - this is greyed out (presumably for WinMobile projects?).
If at all possible, I would like to avoid having to go through Versign or the like to get a Mobile2Market certificate. If I have to go this route for a final version that's fine, but I need to at least be able to test the app on real devices.
Any advice would be most welcome!
First, make sure you really do need to sign it (you might be able to adjust the device security model).
If you do, then run signtool.exe, but from a Visual Studio command prompt. The easiest way to get there is fromt he Start menu, select Microsoft Visual Studio 2008->Visual Studio Tools->Visual Studio 2008 Command Prompt. This will set up all the proper pathing for you.

Resources