Use a third-party library in a C# rule

You can add external libraries to your C# scripted rules.

For example, you may want to:

  • use a third-party library for reading an Excel file or accessing a database

  • share your own library across multiple rules or services instead of duplicating the code in every rule/service

Caution: Referencing a third-party library can introduce risk. It may not function properly, or may negatively impact Service Virtualization Server functionality.

Use a third-party library

  1. Disable C# rule sandbox mode. For details, see Configure C# Security.
  2. Copy the external library that you want to use (for example, MyCompany.MyLibrary.dll) to the Extensions folder of the Service Virtualization Designer or Server, depending on where the virtual service will run.

    • <Designer installation folder>\HPE Service Virtualization Designer\Designer\Extensions
    • <Server installation folder>\HPE Service Virtualization Server\Server\Extensions
  3. Enable the C# rule to reference your third-party library/assembly.

    1. Open the appropriate file for Designer or Server:

      <Designer installation folder>\HPE Service Virtualization Designer\Designer\bin\Config\scripted-rule-context.xml

      <Server installation folder>\HPE Service Virtualization Server\Server\bin\Config\scripted-rule-context.xml

    2. Add your assembly reference to the ReferenceAssemblies section, as follows:

      <property name="ReferenceAssemblies" value="System,System.Core,<MyCompany.MyLibrary>" />

  4. Restart the relevant application to apply the changes:

    • Designer: Close and reopen the Designer.
    • Service Virtualization Server: Restart the Service Virtualization Server service.