<p>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). </p>

<p>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...</p>

<p>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 <a href="http://forums.msdn.microsoft.com/en-US/vclanguage/thread/a52c3ee4-63f9-4ccd-b38c-b5cbefabc414/" rel="noreferrer">this link</a> 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.</p>

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

[{'answer_id': 14859, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 5, 'selected': True, 'text': '<p>Make sure the <a href="http://msdn.microsoft.com/en-us/library/ms924287.aspx" rel="noreferrer">Enable String Pooling</a> option under C/C++ Code Generation is turned on.</p>\n\n<p>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.</p>\n'}, {'answer_id': 14964, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>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.</p>\n\n<p>And no, if anything this should result in slightly faster run-time execution (nothing you could ever measure, however.)</p>\n\n<p>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".</p>\n\n<p>(Which is one of the reasons I no longer participate on MSDN.)</p>\n\n<p>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.</p>\n\n<p>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.</p>\n\n<p>But I don\'t think you\'ll see this error again, in any case.</p>\n'}, {'answer_id': 14970, 'author': 'Brian Ensink', 'author_id': 1254, 'author_profile': 'https://Stackoverflow.com/users/1254', 'pm_score': 2, 'selected': False, 'text': '<p>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.</p>\n'}]
['https://Stackoverflow.com/questions/14843', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1169/']