Partial trust environment support

Fixed a bug where the library would crash when running in a partial
trust environment.