The following error occurs when we try to create a worksheet. The issue is resolved by setting IIS 7.0 LoadUserProfile to true. We are trying to understand why this is needed and teh secruity implications and if there is a workaround to make this work without having to change the default IIS setting<br><br><br>System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. <br>at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) <br>at System.Security.CodeAccessPermission.Demand() <br>at System.Environment.get_UserName() <br>at NPOI.HSSF.Model.InternalWorkbook.CreateWriteAccess() <br>at NPOI.HSSF.Model.InternalWorkbook.CreateWorkbook() <br>at NPOI.HSSF.UserModel.HSSFWorkbook..ctor() <br>at ....<br><br>The action that failed was: <br>Demand <br>The type of the first permission that failed was: <br>System.Security.Permissions.EnvironmentPermission <br>The first permission that failed was: <br><br>version="1" <br>Read="UserName"/> <br><br>The demand was for: <br><br>version="1" <br>Read="UserName"/> <br><br>The granted set of the failing assembly was: <br><br>version="1"> <br><br>version="1" <br>Access="Open"/> <br><br>version="1" <br>Allowed="ApplicationIsolationByUser" <br>UserQuota="512000"/> <br><br>version="1" <br>Flags="Execution"/> <br><br>version="1" <br>Window="SafeTopLevelWindows" <br>Clipboard="OwnClipboard"/> <br><br>version="1" <br>PublicKeyBlob="002400000480000094000000060200000024000052534131000400000100010095CCD95AF3B39D8BC20544D3F47FD24B53EBC5CCB693EAED116290629F8CD882C827EBD511AD59449224F0718D3F9D03B64945A6C8B6644266001B8C8426185330E3D96DA70AE16D4ACC21B8D4D480F1385C7E924273179375AA88F81380A72FB115712A313379D16AED4AA36208EE3B4A5DD785B06A07B2D868E3227F4495B5" <br>Name="NPOI" <br>AssemblyVersion="1.2.5.0"/> <br><br>version="1" <br>Url="file:///c:/xxx/web/bin/NPOI.DLL"/> <br><br>version="1" <br>Zone="Internet"/> <br><br>version="1" <br>Level="SafePrinting"/> <br><br><br>The assembly or AppDomain that failed was: <br>NPOI, Version=1.2.5.0, Culture=neutral, PublicKeyToken=0df73ec7942b34e1 <br>The method that caused the failure was: <br>NPOI.HSSF.Record.Record CreateWriteAccess() <br>The Zone of the assembly that failed was: <br>Internet <br>The Url of the assembly that failed was: <br>file:///c:/xxx/web/bin/NPOI.DLL <br>--- End of inner exception stack trace --- <br>at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) <br>at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) <br>at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) <br>at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams) <br>at System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args) <br>at ...
Comments: ** Comment from web user: tonyqus **
Comments: ** Comment from web user: tonyqus **
This should be a bug in NPOI 1.2.5 because the wrong exception is catched.
private static Record CreateWriteAccess()
{
WriteAccessRecord retval = new WriteAccessRecord();
try
{
retval.Username=(Environment.UserName);
}
catch ( AccessViolationException)
{
// AccessControlException can occur in a restricted context
// (client applet/jws application or restricted security server)
retval.Username=("POI");
}
}
AccessViolationException is not the correct exception to be catched. Instead, SecurityException should be used. This bug will be fixed in NPOI 2.0.