如何解决Resharper运行测试时'txic'程序集加载格式错误问题
问题:使用ClientBuildManager预编译时出现程序集加载错误
运行以下代码时返回错误:
无法加载文件或程序集“txic”或其依赖项之一。尝试加载格式不正确的程序。
using System; using System.Web.Compilation; class Program { static void Main() { string virtualPath = "/"; string physicalPath = @"C:\MyApp"; using (ClientBuildManager cbm = new ClientBuildManager(virtualPath, physicalPath)) { // Precompile the entire application Console.WriteLine("Precompiling application..."); cbm.PrecompileApplication(new MyBuildManagerCallback()); // Compile specific files string[] files = { "~/Pages/MyPage.aspx", "~/Controls/MyControl.ascx" }; foreach (string file in files) { try { Console.WriteLine($"Compiling {file}..."); cbm.CompileFile(file, new MyBuildManagerCallback()); } catch (Exception ex) { Console.WriteLine($"Error compiling {file}: {ex.Message}\n{ex.StackTrace}"); } } } } } public class MyBuildManagerCallback : ClientBuildManagerCallback { public override void ReportProgress(string message) { Console.WriteLine($"Progress: {message}"); } }
请问如何解决该问题?
补充说明:
该错误仅在通过Resharper运行测试时出现
解决方法
调整平台目标匹配程序集位数
这个错误大多是32位/64位程序集不兼容导致的。Resharper运行测试时的平台可能和项目不一致:- 右键项目 → 属性 → 生成 → 平台目标:如果依赖的txic是32位,选x86;如果是64位选x64,或者选Any CPU并勾选“首选32位”(针对32位程序集)。
- 打开Resharper选项 → 工具 → 单元测试 → 运行程序集的位数,选择和项目一致的选项(比如强制32位)。
检查txic程序集完整性
确认项目bin目录或C:\MyApp下存在txic.dll,且它的所有依赖项都齐全。如果是第三方程序集,确保安装的版本和项目引用一致。清理Resharper缓存
打开Resharper → 选项 → 环境 → 常规 → 点击“清除缓存”,重启VS后再运行测试,缓存异常也可能导致这类加载错误。对齐测试项目与目标项目的.NET版本
确保测试项目的.NET框架版本和使用ClientBuildManager的项目版本完全一致,版本不匹配会引发程序集加载问题。
内容的提问来源于stack exchange,提问作者Rubber
相关产品推荐
相关产品推荐


