Mixed C ++ / CLI TypeLoadException内部限制:字段太多

时间:2021-11-05 04:34:43

On a quest to migrate some new UI into Managed/C# land, I have recently turned on Common Language Runtime Support (/clr) on a large legacy project, which uses MFC in a Shared DLL and relies on about a dozen other projects within our overall solution. This project is the core of our application, and would drive any managed UI code that is produced (hence the need to turn on clr support for interop).

为了将一些新UI迁移到Managed / C#land,我最近在一个大型遗留项目上启用了公共语言运行时支持(/ clr),该项目在共享DLL中使用MFC并依赖于我们内部的十几个其他项目。整体解决方案该项目是我们应用程序的核心,它将驱动生成的任何托管UI代码(因此需要为interop启用clr支持)。

After fixing a ton of little niggly errors and warnings, I finally managed to get the application to compile.. However, running the application causes an EETypeLoadException and leaves me unable to debug...

在修复了大量的小错误和警告之后,我终于设法让应用程序进行编译..但是,运行应用程序会导致EETypeLoadException并让我无法调试...

Doing some digging, I found the cause to be "System.TypeLoadException: Internal limitation: too many fields." which occurs right at the end of compilation. I then found this link which suggests to break the assembly down into two or more dlls. However, this is not possible in my case, as a limitation I have is that the legacy code basically remains untouched.

做一些挖掘,我发现原因是“System.TypeLoadException:内部限制:太多字段。”它发生在编译结束时。然后我发现这个链接建议将程序集分解为两个或更多dll。但是,在我的情况下这是不可能的,因为我的限制是遗留代码基本上保持不变。

Can anyone suggest any other possible solutions? I'm really at a dead end here.

任何人都可以建议任何其他可能的解我真的在这里死路一条。

3 个解决方案

#1


7  

Make sure the Enable String Pooling option under C/C++ Code Generation is turned on.

确保已启用“C / C ++代码生成”下的“启用字符串池”选项。

That usually fixes this issue, which is one of those "huh?" MS limitations like the 64k limit on Excel spreadsheets. Only this one affects the number of symbols that may appear in an assembly.

这通常可以解决这个问题,这是其中一个“嗯?” MS限制,例如Excel电子表格上的64k限制。只有这一个会影响程序集中可能出现的符号数。

#2


3  

Do you need to turn /clr on for the entire project? Could you instead turn it on only for a small select number of files and be very careful how you include managed code? I work with a large C++/MFC application and we have found it very difficult to use managed C++. I love C# and .NET but managed C++ has been nothing but a headache. Most of our problems happened with .NET 1.0/1.1 ... maybe things are better now.

你需要为整个项目打开/关闭吗?您是否可以仅针对少量选定的文件打开它,并且如何包含托管代码时要非常小心?我使用大型C ++ / MFC应用程序,我们发现使用托管C ++非常困难。我喜欢C#和.NET,但托管C ++一直是个头痛的问题。我们的大多数问题都发生在.NET 1.0 / 1.1上......也许事情现在变得更好了。

#3


2  

I have done this with very large mixed-mode (C#/C++) applications three times (3x) and once putting the above fix into place have never seen the error again.

我已经用非常大的混合模式(C#/ C ++)应用程序完成了三次(3x),并且一旦将上述修复程序放到位,就再也没有看到错误。

And no, if anything this should result in slightly faster run-time execution (nothing you could ever measure, however.)

不,如果有的话,这会导致运行时执行速度稍快(不过你可以测量的任何东西)。

But I agree it's somewhat of a stopgap. The internal limit on symbols didn't use to be an issue, or if it was, that limit was much higher. Then MS changed some of the loader code. I got onto MSDN and ranted about it and was told in no uncertain terms, "only an idiot would put that many symbols in a single assembly".

但我同意这是一个权宜之计。符号的内部限制并不是一个问题,如果是,则该限制要高得多。然后MS改变了一些加载程序代码。我进入了MSDN并对它进行了大肆宣传并且毫不含糊地被告知,“只有一个白痴会把那么多符号放在一个组件中”。

(Which is one of the reasons I no longer participate on MSDN.)

(这是我不再参与MSDN的原因之一。)

Well, color me stupid, but I don't think I should have to change the physical structure of my application, breaking things out into satellite DLLs, merely to get around the fact that the loader has decided 10,001 symbols is 1 too many.

好吧,给我上色傻,但我认为我不应该改变我的应用程序的物理结构,把事情搞砸到卫星DLL中,只是为了解决加载器已经确定10,001个符号太多的事实。

And as you pointed out, we often don't have control over how assemblies/satellite DLLs are structure, and the sort of dependencies they contain.

正如您所指出的,我们通常无法控制程序集/附属DLL的结构,以及它们包含的依赖类型。

But I don't think you'll see this error again, in any case.

但无论如何,我认为你不会再看到这个错误。

#1


7  

Make sure the Enable String Pooling option under C/C++ Code Generation is turned on.

确保已启用“C / C ++代码生成”下的“启用字符串池”选项。

That usually fixes this issue, which is one of those "huh?" MS limitations like the 64k limit on Excel spreadsheets. Only this one affects the number of symbols that may appear in an assembly.

这通常可以解决这个问题,这是其中一个“嗯?” MS限制,例如Excel电子表格上的64k限制。只有这一个会影响程序集中可能出现的符号数。

#2


3  

Do you need to turn /clr on for the entire project? Could you instead turn it on only for a small select number of files and be very careful how you include managed code? I work with a large C++/MFC application and we have found it very difficult to use managed C++. I love C# and .NET but managed C++ has been nothing but a headache. Most of our problems happened with .NET 1.0/1.1 ... maybe things are better now.

你需要为整个项目打开/关闭吗?您是否可以仅针对少量选定的文件打开它,并且如何包含托管代码时要非常小心?我使用大型C ++ / MFC应用程序,我们发现使用托管C ++非常困难。我喜欢C#和.NET,但托管C ++一直是个头痛的问题。我们的大多数问题都发生在.NET 1.0 / 1.1上......也许事情现在变得更好了。

#3


2  

I have done this with very large mixed-mode (C#/C++) applications three times (3x) and once putting the above fix into place have never seen the error again.

我已经用非常大的混合模式(C#/ C ++)应用程序完成了三次(3x),并且一旦将上述修复程序放到位,就再也没有看到错误。

And no, if anything this should result in slightly faster run-time execution (nothing you could ever measure, however.)

不,如果有的话,这会导致运行时执行速度稍快(不过你可以测量的任何东西)。

But I agree it's somewhat of a stopgap. The internal limit on symbols didn't use to be an issue, or if it was, that limit was much higher. Then MS changed some of the loader code. I got onto MSDN and ranted about it and was told in no uncertain terms, "only an idiot would put that many symbols in a single assembly".

但我同意这是一个权宜之计。符号的内部限制并不是一个问题,如果是,则该限制要高得多。然后MS改变了一些加载程序代码。我进入了MSDN并对它进行了大肆宣传并且毫不含糊地被告知,“只有一个白痴会把那么多符号放在一个组件中”。

(Which is one of the reasons I no longer participate on MSDN.)

(这是我不再参与MSDN的原因之一。)

Well, color me stupid, but I don't think I should have to change the physical structure of my application, breaking things out into satellite DLLs, merely to get around the fact that the loader has decided 10,001 symbols is 1 too many.

好吧,给我上色傻,但我认为我不应该改变我的应用程序的物理结构,把事情搞砸到卫星DLL中,只是为了解决加载器已经确定10,001个符号太多的事实。

And as you pointed out, we often don't have control over how assemblies/satellite DLLs are structure, and the sort of dependencies they contain.

正如您所指出的,我们通常无法控制程序集/附属DLL的结构,以及它们包含的依赖类型。

But I don't think you'll see this error again, in any case.

但无论如何,我认为你不会再看到这个错误。