简体   繁体   English

CLR 类库是否必须在 Win32 中运行?

[英]Does a CLR Class Library have to be run in Win32?

I created a CLR project in VS2017.我在 VS2017 中创建了一个 CLR 项目。

Included:包括:

  • CLR Class Library(C++) .NET Framework 4.5 CLR 类库(C++) .NET Framework 4.5
  • C# ConsoleApp C# 控制台应用程序

There is a simple ref class defined in the Library.库中定义了一个简单的 ref 类。 The class is called from my C# code.该类是从我的 C# 代码中调用的。 I am fine with its performance but it does not work always.我对它的性能很好,但它并不总是有效。

It depends on how I run it.这取决于我如何运行它。

  • "Debug" and "x86" works “调试”和“x86”有效
  • "Debug" and "x64" does not work “调试”和“x64”不起作用
  • "Release" and "x86" works “发布”和“x86”有效
  • "Release" and "x64" does not work “发布”和“x64”不起作用

So in Debug and Release it only works when the CLR Class Library is run in Win32.因此,在 Debug 和 Release 中,它仅在 CLR 类库在 Win32 中运行时才有效。

Do I make a mistake or is this intended behaviour?我犯了错误还是这是有意的行为?

Thanks in advance!提前致谢!

Usually the purpose of using C++/CLI language (I assume that's what you mean by "CLR Library") is to use both native and .Net objects.通常使用 C++/CLI 语言(我假设这就是“CLR 库”的意思)的目的是使用本机和 .Net 对象。 Because of native code, the binary library is tied to either 32-bit or 64-bit platform.由于本机代码,二进制库绑定到 32 位或 64 位平台。 Apparently, in your case, this is 32-bit (x86).显然,就您而言,这是 32 位 (x86)。

To answer my question.回答我的问题。

Hans Passant wrote:汉斯·帕桑特写道:

Changing the solution platform only affects the C++/CLI project, not the C# project.更改解决方案平台仅影响 C++/CLI 项目,而不影响 C# 项目。 Right-click the C# project > Properties > Build tab to select the jitter you want to use.右键单击 C# 项目 > 属性 > 构建选项卡以选择要使用的抖动。 Untick the "Prefer 32-bit" checkbox for the x64 solution configuration.取消勾选 x64 解决方案配置的“首选 32 位”复选框。 Again for the Release configuration.再次用于发布配置。

It worked when I unticked "Prefer 32-bit" in the C# project properties under the Build section.当我在 Build 部分下的 C# 项目属性中取消选中“Prefer 32-bit”时,它起作用了。 Thanks!谢谢!

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

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