为什么.NET 4.0 给出“CRT 未初始化”的错误消息?加载非托管 DLL 时出错?

发布于 2024-09-28 05:51:18 字数 306 浏览 0 评论 0原文

我有一个由第三方提供的 DLL 以及包装它的附带 .NET 2.0 程序集。如果我使用 VS2008 创建一个 .NET 3.5 项目,我可以通过包装器程序集调用 DLL,并且它可以正常工作。但是,如果我使用 VS2010 创建等效的 .NET 4.0 项目,则在加载 DLL 时,我会在消息框中收到 R6030 - CRT notinitialed 错误。

我可以做些什么来让它在 .NET 4.0 项目中工作吗?是否与 CAS 更改有关,或者其他什么?

我现在正在 VS2008 中继续我的工作,但是了解正在发生的事情会很好......

I have a DLL supplied by a 3rd party along with an accompanying .NET 2.0 assembly that wraps it. If I create a .NET 3.5 project with VS2008 I am able to call into the DLL via the wrapper assembly and it works OK. However, if I create an equivalent .NET 4.0 project with VS2010 then I get a R6030 - CRT not initialized error in a message box at the time the DLL is loaded.

Is there something I can do to get this to work in a .NET 4.0 project? Could it be related to the CAS changes, or something else?

I'm carrying on with my work in VS2008 for now, but it would be good to understand what's happening...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

闻呓 2024-10-05 05:51:18

这不是 .NET 错误,而是 MS C 运行时(CRT、MSCRT)错误。

您的第 3 方 dll 可能正在使用某些 MSCRT dll(有很多版本)。在本机应用程序的进程启动时,CRT 被初始化(它包含随后调用 main 的程序入口点)。新线程还有一个入口点,以确保正确设置每个线程的数据。

如果 .NET 2 运行时1 默认情况下使用与本机代码相同的 MSCRT,然后它将被正确初始化。 .NET 4 可能使用较新的版本(新的 MSCRT 版本往往与新版本的 VS 一起提供,就像 .NET 一样),然后旧的 MSCRT 仅作为依赖项加载,而不用于应用程序启动。

大多数情况下,MSCT 都能正确处理此问题,但如果第 3 方 dll 正在做一些“聪明”的事情,它可能会绕过某些初始化,而这恰好在 .NET 使用的 MSCRT 版本相同的情况下起作用。此类不正确用法的一个示例是直接调用 CreateThread 而不是使用 MSCRT _beginthread 包装器。

要从根本上解决此问题,您需要对第三部分 dll 和包装器有足够的了解 - 更有可能的是您需要向第三方提供重新创建以供他们修复。


1记住V3.5 只是 2.0 CLI 之上的额外程序集。

That's not a .NET error, it is a MS C Runtime (CRT, MSCRT) error.

Your 3rd party dll is presumably using some MSCRT dll (there are lots of versions). At process start up of a native application the CRT is initialised (it contains the program entry point which then calls main). There is also an entry point for new threads to ensure per-thread data is set up correctly.

If .NET 2 runtime1 by default uses the same MSCRT as the native code then it will be correctly initialised. .NET 4 presumably uses a newer version (new MSCRT versions tend to come with new versions of VS, as .NET does) then the older MSCRT is only being loaded as a dependency and not used for application startup.

Most of the time MSCT handles this correctly, but if the 3rd party dll is doing something "clever" it might be bypassing some initialisation, and this just happens to work is the same version of MSCRT is used by .NET. An example of such incorrect usage is to directly call CreateThread rather than using the MSCRT _beginthread wrapper.

To root cause this you will need sufficient understanding of the 3rd part dll and wrapper—more likely you need to supply a re-create to the third party for them to fix.


1 Remember V3.5 is just extra assemblies on top of the 2.0 CLI.

玩物 2024-10-05 05:51:18

仅在调试时发生还是在运行时也发生?

我想到了两件事:

1).NET 的默认应用程序类型是针对 .NET 客户端框架的,这是最烦人的,我必须一直更改它。如果您将其保留为客户端,那么您可能会遇到各种奇怪的错误,而表面上与此无关。尝试改变这一点。

2)你需要VS 2010还是.NET 4.0?如果只有VS 2010那么你可以将目标框架设置为3.5并尝试查看问题是VS 2010还是.NET 4.0。

从互联网上的错误来看,这似乎是一个计时问题,并且未加载 C 运行时 - 这种行为似乎在 .NET 4.0 中发生了变化。我不知道如何解决它。

Does it happen only on debugging or also in running as well?

Two things come into mind:

1) Default application type for .NET is targeted at .NET Client Framework which is most annoying and I have to change it all the time. You could get all sorts of wierd errors if you keep it as client which at face have nothing to do it. Try changing that.

2) Do you need VS 2010 or .NET 4.0? If only VS 2010 then you can set the target framework to 3.5 and try to see if the problem is VS 2010 or .NET 4.0.

From looking at the error on internet, it looks like this is a timing issue and C runtime is not loaded - a behaviour which looks like changed in .NET 4.0. I have no idea how to fix it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文