Debugging .NET assembly

PowerBuilder IDE provides PowerScript and C# cross-language integrated debugging for scenarios such as when a PowerBuilder application calls the C# assembly. The cross-language debugging allows you to use the PowerBuilder debugger to debug PowerScripts and use a C# editor (such as Visual Studio, Visual Studio Code etc.) to debug the C# assembly. When the PowerBuilder debugger goes to the script where the DotNetObject object executes the C# functions, the C# editor will be launched automatically to assist the debug; and when the C# editor finishes debugging the C# functions, it will return you to the PowerBuilder debugger and you can continue debugging the remaining PowerScripts.

However, before you can use the PowerScript and C# cross-language debugging, you will need to compile the C# assembly and configure the PowerBuilder IDE as required below.

Step 1: Build the C# assembly DLL under the debug mode in the C# editor.

When build completes, you shall be able to find the DLL file and the PDB file in the same folder.

About the PDB file

The PDB file stores the debugging and project state information about the DLL file. It must be placed with the DLL file while debugging.

The DLL file and the PDB file must exactly match with each other in order for debugging to work. You cannot use a PDB file from a different build even though the source files are exactly the same (exact duplication). It is recommended that you build the C# assembly DLL again in the same machine where debugging will be performed, so that the DLL file and the PDB file can exactly match with each other and comply with the current environment.

Step 2: Make sure to always place the DLL file and the PDB file together in the same folder, if you need to move the DLL and PDB files (for example, copy them to a location that can be called by the PowerBuilder application).

Step 3: Open the C# solution in a C# editor such as Visual Studio.

Step 4: Attach the PowerBuilder process (pb250.exe) to Visual Studio, so that when you debug the PowerBuilder application which calls the C# assembly, Visual Studio can be launched automatically to debug the C# assembly.

The following shows how to attach the PowerBuilder process in Visual Studio (other C# editors are similar):

  1. Select Debug | Attach to Process menu in the Visual Studio IDE.

  2. Select the PB250 process and then click Attach.

    You will see from the Output window that a bunch of DLLs are loaded.

After that, you can start the PowerBuilder debugger in the PowerBuilder IDE and select Step In to run through the scripts; when the debugger goes to the script where the C# function is executed, Visual Studio will be launched automatically to debug the C# function.