在完全信任级别下运行控制台应用程序。完全信任级别可以消除此错误。但是,我们不允许运行具有完全信任级别的应用程序。我们使用自定义权限运行部分信任。
该程序似乎在以下代码行上中断:
return myLogs.Where(x => x.PROCESS_SUCCESS == "Y" &&
x.PROCESS_ENVIRONMENT.ToUpper() == Settings.Environment.ToUpper() &&
x.PROCESS_DATE.Value.Month == DateTime.Now.Month &&
x.PROCESS_DATE.Value.Year == DateTime.Now.Year).Any();
错误1:
Request for the permission of type 'System.Security.Permissions.FileIOPermission,
mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
错误1(需求部分):
The demand was for:
<PermissionSet class="System.Security.PermissionSet"
version="1">
<IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
Read="USERNAME;COMPUTERNAME"/>
错误2:
System.Reflection.TargetInvocationException: Exception has been thrown by the target
of an invocation. --->
System.TypeAccessException: Attempt by method
'DynamicClass.lambda_method(System.Runtime.CompilerServices.Closure,
System.Data.Entity.Core.Common.Internal.Materialization.Shaper)' to access type
'System.Data.Entity.Core.Common.Internal.Materialization.Shaper' failed. --->
System.Security.SecurityException: Request for the permission of type
'System.Security.Permissions.FileIOPermission, mscorlib, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089' failed.