更新:正如评论中指出的,下面的代码指的是可移植的pdb。可移植的 pdb 与我的情况无关,但使用沙盒应用程序域和可移植的 pdb 的人们可能仍然会对这个问题感兴趣。
我正在受限沙箱(AppDomain)内运行代码。从此沙箱中抛出的异常没有附加行号。解除CAS限制使得行号出现,所以和CAS有关。StackFrameHelper.InitializeSourceInfo
似乎负责提供行号。那里有一个条件分支,它在受限路径上执行,但在第二个路径上失败Assert
ion (堆栈跟踪.cs:135 https://referencesource.microsoft.com/#mscorlib/system/diagnostics/stacktrace.cs,135):
// need private reflection below + unmanaged code for the portable PDB access itself
// PERF: these demands are somewhat expensive so do the quick check first. We are aiming for
// ~50k traces/s at 5 frames/trace on decent 2017 era hardware to maintain rough performance
// parity with 4.7 implementation that didn't have Portable PDB support
if (!CodeAccessSecurityEngine.QuickCheckForAllDemands())
{
new ReflectionPermission(ReflectionPermissionFlag.MemberAccess).Assert();
new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Assert();
}
这给出了以下异常,但是这在第 205 行被吞没并且加载 pdb 被简单地跳过:
在执行相同类型的另一个修改之前,必须恢复堆栈遍历修饰符。
根据文档 https://learn.microsoft.com/en-us/dotnet/api/system.security.codeaccesspermission.assert?view=netframework-4.8#exceptions and 另一个问题 https://stackoverflow.com/questions/2911830/code-access-security-in-reporting-services-2008每帧只能有一个有效的断言。所以上面的代码似乎无效,这是 mscorlib (4.8) 中的编程错误吗?
为了解决这个问题,我必须防止进入该分支。我似乎找不到来源CodeAccessSecurityEngine.QuickCheckForAllDemands
。它似乎与完全信任有关,但是调用程序集已经完全信任。还断言不受限制的访问(new PermissionSet(PermissionState.Unrestricted).Assert()
) 打电话之前exception.ToString()
没有任何影响。 AppDomain 被配置为沙箱,IsFullyTrusted https://learn.microsoft.com/en-us/dotnet/api/system.appdomain.isfullytrusted?view=netframework-4.8回报false
.
如何解决这个可能的错误?
None
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)