Debug a C# scripted rule

Debug a Service Virtualization C# scripted rule in a Visual Studio project, using the debugging features of Visual Studio, or of another C# IDE.

For example, you may want to trace the flow of your script and inspect values inside the variables to better understand what is happening when your script runs. This can help you to more effectively troubleshoot your issues.

Enable debugging

To debug a Service Virtualization C# scripted rule in an external tool, enable the debug feature in Service Virtualization Designer. If your virtual service is deployed on Service Virtualization Server, enable the debug feature on the Server machine as well.

  1. Edit the file scripted-rule-context.xml located in <Service Virtualization installation folder>\bin\Config.

    For example, for the Designer, the file is located by default in C:\Program Files\Micro Focus\Service Virtualization Designer\Designer\bin\Config\scripted-rule-context.xml.

  2. Change the value of DynamicAssemblyCompilation value to Debug.
  3. Change the value ScriptCompilation to Debug.

Back to top

Debug the script

  1. From the Data Model Editor, open the C# rule in a Visual Studio project.
  2. Add a breakpoint (F9).
  3. Attach the debugger to the VirtualServiceDesigner process (Ctrl+Alt+P).
  4. In Service Virtualization, switch your virtual service to Simulating mode.
  5. Open Simulation preview and click on a row in the data model.

    Alternatively, perform another action that triggers the execution of your script, such as intercepting a request.

While the script runs, the debugger will hit your breakpoints when the flow of execution reaches them. When hit, you can view the content of your variables, step through the code, inspect the script internals, and resume execution when you are ready.

Back to top

See also: