Visual Studio 2022社区版加载Microsoft.QualityTools.Testing.Fakes程序集失败
Visual Studio 2022社区版:Microsoft.QualityTools.Testing.Fakes加载权限拒绝问题
错误详情
System.IO.FileLoadException: 无法加载文件或程序集“Microsoft.QualityTools.Testing.Fakes”或其某一个依赖项。访问被拒绝。文件名: “Microsoft.QualityTools.Testing.Fakes” 在 System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) 在 System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) 在 System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) 在 System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) 在 System.Reflection.Assembly.Load(String assemblyString) 在 System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) 警告: 程序集绑定日志记录已关闭。要启用程序集绑定失败日志记录,请将注册表值 [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) 设置为 1。 注意: 与程序集绑定失败日志记录关联的性能损失。要关闭此功能,请移除注册表值 [HKLM\Software\Microsoft\Fusion!EnableLog]。
已尝试无效操作
- 删除Fakes文件夹并重建解决方案
- 创建
HKLM\Software\Microsoft\Fusion!EnableLog注册表项(仅获取更多错误细节,未解决问题)
解决方法
- 以管理员身份运行Visual Studio:右键Visual Studio图标选择「以管理员身份运行」,重新加载项目。
- 检查程序集权限:找到
Microsoft.QualityTools.Testing.Fakes所在路径(通常在Visual Studio安装目录Common7\IDE\PublicAssemblies或项目packages文件夹),右键文件选「属性」-「安全」,确认当前用户有读取和执行权限。 - 修复Visual Studio安装:打开Visual Studio安装程序,选择「修改」-「修复」,修复损坏组件或缺失依赖。
- 清理NuGet缓存并重装依赖:
- 打开NuGet包管理器控制台,执行命令:
nuget locals all -clear - 右键项目选「管理NuGet程序包」,卸载并重新安装相关Fakes包。
- 打开NuGet包管理器控制台,执行命令:
- 检查项目框架兼容性:确认项目目标.NET框架版本与
Microsoft.QualityTools.Testing.Fakes支持版本匹配,不匹配则调整项目框架。
内容的提问来源于stack exchange,提问作者starlin moses
相关产品推荐
相关产品推荐

