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
- Disable C# rule sandbox mode. For details, see Configure C# Security.
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>\Service Virtualization Designer\Designer\Extensions
- <Server installation folder>\Service Virtualization Server\Server\Extensions
Enable the C# rule to reference your third-party library/assembly.
Open the appropriate file for Designer or Server:
<Designer installation folder>\Service Virtualization Designer\Designer\bin\Config\scripted-rule-context.xml
<Server installation folder>\Service Virtualization Server\Server\bin\Config\scripted-rule-context.xml
Add your assembly reference to the ReferenceAssemblies section, as follows:
<property name="ReferenceAssemblies" value="System,System.Core,<MyCompany.MyLibrary>" />
Restart the relevant application to apply the changes:
- Designer: Close and reopen the Designer.
- Service Virtualization Server: Restart the Service Virtualization Server service.