top of page

Fix UnauthorizedScriptingAPIAccessException

As you upgrade your scripts to ESAPI 15.x you may encounter the following exception as soon as your script starts:

VMS.TPS.Common.Model.UnauthorizedScriptingAPIAccessException: Application was not able to execute script '<Your\Script\Path>'. The script '<Your Script (version)>' is not a valid ESAPI script.

This exception happened to me when I tried using the EclipsePlugInRunner (v. 2.0.0) on a script using ESAPI 15.5. It also happened on a stand-alone app that depended on ESAPI 15.5.

The problem seems to happen when an application references an assembly that references ESAPI 15.x but the application itself doesn't use ESAPI directly. It doesn't matter if you reference ESAPI from the application. If nothing in ESAPI is used by the application, then the exception occurs (probably because the compiler optimizes away the reference).

The solution, then, is to make sure you use something from ESAPI (and reference ESAPI) from the main application. For example, you could define the following method:

// Fix UnauthorizedScriptingAPIAccessException
public void DoNothing(PlanSetup plan) { }

This is enough to prevent the compiler from optimizing away the ESAPI reference. Once the reference is included in the application, you won't get the above exception.

Related Posts

See All

ESAPI Essentials 1.1 and 2.0

A few months ago, I introduced ESAPI Essentials—a toolkit for working with ESAPI (available via NuGet). I've recently added one major feature: asynchronous access to ESAPI for binary plugin scripts. Y

Announcement: ESAPI Subreddit

A few months ago, Matt Schmidt started the ESAPI subreddit. It's another useful resource for finding and discussing ESAPI-related topics. According to the description, This community is to post and di

Dump All Patient Data from ESAPI

If, for whatever reason, you need to dump out all of the data for a patient from ESAPI, there's a quick and dirty way to do it. Well, there are probably several ways to do it, but here's one I've foun

bottom of page