简体   繁体   English

Service Fabric 无法加载程序集 c#

[英]Service Fabric couldn't load assembly c#

"Could not load file or assembly 'Microsoft.ServiceFabric.Data' or one of its dependencies. An attempt was made to load a program with an incorrect format." “无法加载文件或程序集‘Microsoft.ServiceFabric.Data’或其依赖项之一。尝试加载格式不正确的程序。”

Exception Details: System.BadImageFormatException: Could not load file or assembly 'Microsoft.ServiceFabric.Data' or one of its dependencies.异常详细信息:System.BadImageFormatException:无法加载文件或程序集“Microsoft.ServiceFabric.Data”或其依赖项之一。 An attempt was made to load a program with an incorrect format.试图加载格式不正确的程序。

I added nuget of Service Fabric to my web api and here's the exception.我在我的 web api 中添加了 Service Fabric 的 nuget,这是个例外。 I tried to complie x64 / AnyCPU / x86我试图编译 x64 / AnyCPU / x86

Any help?有什么帮助吗?

The answer for this question solved this issue for me这个问题的答案为我解决了这个问题

I get a "An attempt was made to load a program with an incorrect format" error on a SQL Server replication project 我在 SQL Server 复制项目中收到“尝试加载格式不正确的程序”错误

We recently had the issue when trying to run the code from Visual Studio.我们最近在尝试从 Visual Studio 运行代码时遇到了问题。 In that case you need to do TOOLS > OPTIONS > Projects and Solutions > WEB PROJECTS and check the "Use the 64 bit version of IIS Express for web sites and projects".在这种情况下,您需要执行 TOOLS > OPTIONS > Projects and Solutions > WEB PROJECTS 并选中“为网站和项目使用 64 位版本的 IIS Express”。

I faced the same issue, both for web applications and when running tests.我在 Web 应用程序和运行测试时都遇到了同样的问题。

When running a web application : : System.BadImageFormatException : "Could not load file or assembly 'Microsoft.ServiceFabric.Data' or one of its dependencies. An attempt was made to load a program with an incorrect format."运行 Web 应用程序时 :: System.BadImageFormatException :“无法加载文件或程序集 'Microsoft.ServiceFabric.Data' 或其依赖项之一。尝试加载格式不正确的程序。”

Possible cause: your IIS is not setup to run in a 64 bit version.可能的原因:您的 IIS 未设置为在 64 位版本中运行。 Service Fabric assemblies only run on 64 bit platforms. Service Fabric 程序集仅在 64 位平台上运行。

Solution: In that case you need to do (as suggested above) in Visual Studio TOOLS > OPTIONS > Projects and Solutions > WEB PROJECTS and check the "Use the 64 bit version of IIS Express for web sites and projects".解决方案:在这种情况下,您需要在 Visual Studio TOOLS > OPTIONS > Projects and Solutions > WEB PROJECTS 中执行(如上所述)并选中“为网站和项目使用 64 位版本的 IIS Express”。

When running a test : System.BadImageFormatException : "Could not load file or assembly 'Microsoft.ServiceFabric.Data' or one of its dependencies. An attempt was made to load a program with an incorrect format."运行测试时: System.BadImageFormatException :“无法加载文件或程序集 'Microsoft.ServiceFabric.Data' 或其依赖项之一。尝试加载格式不正确的程序。”

Possible cause: your test runner is not setup to run in a 64 bit version.可能的原因:您的测试运行器未设置为在 64 位版本中运行。 Service Fabric assemblies only run on 64 bit platforms. Service Fabric 程序集仅在 64 位平台上运行。

Solution: Change the test runner settings in Visual Studio: Test menu > Test Settings > Default Processor Architecture > Set to x64.解决方案:在 Visual Studio 中更改测试运行程序设置:测试菜单 > 测试设置 > 默认处理器架构 > 设置为 x64。

Also make sure that all your projects are configured to run on x64 platforms, not x86.还要确保您的所有项目都配置为在 x64 平台上运行,而不是在 x86 平台上运行。 You can ensure this in the Configuration Manager of your solution, make sure you do not have any active profile for x86.您可以在解决方案的配置管理器中确保这一点,确保您没有任何适用于 x86 的活动配置文件。

我遇到了同样的问题,除了上一个答案中显示的步骤(工具 > 选项 > 项目和解决方案 > WEB 项目并选中“使用 64 位版本”),我必须转到我的项目属性 -> 构建 -> 并设置将“平台目标:”升级到 x64。

This happened to me before.这发生在我身上。 Somehow during the install, it did not copy some of the files which I don't know why.不知何故,在安装过程中,它没有复制一些我不知道为什么的文件。 All I did was reinstall the SDK again.我所做的只是重新安装 SDK。 I think stopping the SF service and making sure I don't have any VS running helps.我认为停止 SF 服务并确保我没有任何 VS 运行有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM