首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在System.Security.Principal.WindowsIdentiy in .NET461?

如何在System.Security.Principal.WindowsIdentiy in .NET461?
EN

Stack Overflow用户
提问于 2019-04-11 07:36:50
回答 1查看 307关注 0票数 2

摘要

我在2017年和2019年打开了一个.NET461解决方案,并试图编译它。构建正在抱怨在相应的测试项目中找不到ShimWindowsIdentity。在Visual 2015中,构建,特别是ShimWindowsIdentity没有问题。

目标

我需要使用WindowsIdentity的构造函数来对函数进行单元测试。我知道包装WindowsIdentity是有可能的,但这需要我现在避免的代码更改(重构)。

到目前为止尝试过

为了使WindowsIdentity的shims在VS 2017/2019中工作,我尝试并检查了以下内容:

  • 删除假程序集并从头构建它们。
  • 禁用存根生成,并显式添加mscorlib.fakes所需的存根和短消息
  • 检查项目和测试项目中的TargetFrameworkVersion v4.6.1

mscorlib.fakes

代码语言:javascript
复制
<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/">
 <Assembly Name="mscorlib" Version="4.0.0.0"/>
 <StubGeneration>
   <Clear />
   <Add FullName="System.IO.Stream!"/>
 </StubGeneration>
 <ShimGeneration>
   <Clear/>
   <Add FullName="System.Security.Principal"/>
   <Add FullName="System.DateTime!"/>
   <Add FullName="System.IO.Stream!"/>
 </ShimGeneration>
</Fakes>

期望

生成用于WindowsIdentiy的shims。

实际

我在mscorlib.4.0.0.0.Fakes.messages中看到了以下警告:Cannot generate shim for System.Security.Principal.WindowsIdentity: type is not supported because it is not available or changed between versions.

EN

回答 1

Stack Overflow用户

发布于 2019-11-22 10:49:37

玩得很开心,试着假装HttpRequest.LogonUserIdentity

  1. 根据这个https://developercommunity.visualstudio.com/content/problem/35053/ms-fakes-is-unable-to-generate-stubs-for-types-inc.html,您必须针对4.6.2或最新安装的.net框架版本。试试看
  2. 我个人无法为我的环境中的这个特定类生成shims (使用.net 4.8)。我试图针对461,462,48人。对于4.8版本,我最后得到了另一条消息:由于内部限制,不支持为System.Security.Principal.WindowsIdentity+d__95:类型生成shim。

对我来说,除了我的web应用程序是内置在(4.6.1)中之外,针对其他版本没有任何意义,所以我放弃了,用假包装伪造了HttpRequestBase类,并夸大了httpRequest.LogonUserIdenity,返回了我所需要的东西。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55627066

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档