{"id":212,"date":"2013-05-03T07:59:16","date_gmt":"2013-05-03T13:59:16","guid":{"rendered":"https:\/\/angelmarquez.com\/?p=212"},"modified":"2013-05-03T11:44:35","modified_gmt":"2013-05-03T17:44:35","slug":"things-mom-never-told-you-about-c-cli","status":"publish","type":"post","link":"https:\/\/angelmarquez.com\/?p=212","title":{"rendered":"Things mom never told you about C++ CLI"},"content":{"rendered":"<p>For the last few months I&#8217;ve been working on a project that utilizes C++\/CLI to bridge some legacy code with new code written in C#. A good chunk of that time has been spent running repeatedly into walls, pitfalls, quirks, and &#8220;known issues.&#8221; I figured I&#8217;d document some of the issues I&#8217;ve encountered in case someone out there to hopefully save people out there a few hours of frustration.<\/p>\n<h4><span style=\"text-decoration: underline;\">0) Preparation<\/span><\/h4>\n<ul>\n<li>The following are the books I&#8217;ve located dedicated to C++ CLI. The biggest problem with these books is they cover very simple scenarios and assume things &#8220;just work&#8221; when in reality they DON&#8217;T quite often and you end up on Google and Stack overflow trying to figure out some cryptic error message.<\/li>\n<\/ul>\n<h4><span style=\"text-decoration: underline;\">1) Avoid Visual Studio 2012 Update 2<\/span><\/h4>\n<p>If you&#8217;re doing C++\/CLI work Update 2\u00a0<strong>is the devil!<\/strong>\u00a0It breaks the mixed mode debugger. Relevant links:<\/p>\n<ul>\n<li><span style=\"line-height: 13px;\"><a href=\"http:\/\/connect.microsoft.com\/VisualStudio\/feedback\/details\/783004\/children-cannot-be-evaluated-on-c-cli-after-vs2012-update-2\">Children cannot be Evaluated&#8221; on C++\/CLI after VS2012 Update 2<\/a> (Microsoft connect)<\/span><\/li>\n<li><a href=\"https:\/\/connect.microsoft.com\/VisualStudio\/feedback\/details\/773794\/debug-visualizers-in-mixed-mode-apps-have-regressed\">Debug Visualizers in Mixed-Mode apps have regressed<\/a>\u00a0\u00a0(Microsoft connect)<\/li>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/16213095\/how-to-display-native-types-when-debugging-in-vs2012-for-mixed-mode-c-cli-mfc\">How to display native types when debugging in VS2012 for mixed mode C++\/CLI MFC app<\/a> (Stack Overflow)<\/li>\n<\/ul>\n<p>As a side note, XP Compatibility compilation is now broken:<\/p>\n<ul>\n<li><span style=\"line-height: 13px;\"><a href=\"http:\/\/connect.microsoft.com\/VisualStudio\/feedback\/details\/783183\/visual-studio-2012-update-2-broke-windows-xp-compatiblity\">Visual Studio 2012 Update 2 broke Windows XP Compatiblity<\/a>\u00a0(Microsoft connect)<br \/>\n<\/span><\/li>\n<\/ul>\n<p>And last but not least uninstalling Update 2 *may* leave your Visual Studio install crippled:<\/p>\n<ul>\n<li><a href=\"https:\/\/connect.microsoft.com\/VisualStudio\/feedback\/details\/785396\/uninstalling-vs2012-update-2-and-repair-of-vs-results-in-atl-files-missing\">Uninstalling VS2012 Update 2 and repair of VS results in ATL files missing<\/a>\u00a0\u00a0(Microsoft connect)<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h4><span style=\"text-decoration: underline;\">1) Compile time and link time errors<\/span><\/h4>\n<p>Some of these could depend heavily on exactly what you are doing so though you may get the same error you may have a completely different problem\/solution. Contact me if you have an issue+solution you&#8217;ve discovered and want added.<\/p>\n<h5>A) Error: &#8220;String cannot be of zero length. Parameter name: frameworkName&#8221;<\/h5>\n<p style=\"padding-left: 30px;\"><strong>Cause:\u00a0<\/strong>incorrectly created file located at\u00a0C:\\Users\\<span style=\"color: #ff6600;\">YOURNAME<\/span>\\AppData\\Local\\Temp\\.NETFramework,Version=v4.0.AssemblyAttributes.cpp<\/p>\n<p style=\"padding-left: 30px;\"><strong>Fix1:\u00a0<\/strong>The file should be written every build, so just delete teh file<\/p>\n<p style=\"padding-left: 30px;\"><strong>Fix2:\u00a0<\/strong>Open the file and confirm first parameter is empty string (\u00a0<code><strong>L\"\"<\/strong>). <\/code>If so then add appropriate framework to first parameter, as shown below in red:<\/p>\n<pre style=\"padding-left: 30px;\"><code>#using &lt;mscorlib.dll&gt;\r\n[assembly: System::Runtime::Versioning::TargetFrameworkAttribute(<strong>L\"<span style=\"color: #ff0000;\">.NETFramework,Version=v4.0<\/span>\"<\/strong>, FrameworkDisplayName=L\".NET Framework 4\")];<\/code><\/pre>\n<p style=\"padding-left: 30px;\">Answer found here:\u00a0<a href=\"http:\/\/stackoverflow.com\/questions\/13315940\/apps-exe-file-missing-net-targetframework-but-only-on-clean-builds\">http:\/\/stackoverflow.com\/questions\/13315940\/apps-exe-file-missing-net-targetframework-but-only-on-clean-builds<\/a><\/p>\n<p>&nbsp;<\/p>\n<h5>B) Error: &#8220;String cannot be of zero length. Parameter name: frameworkName&#8221;<\/h5>\n<p><strong>Cause:\u00a0<\/strong>incorrectly created file located at\u00a0C:\\Users\\YOURNAME\\AppData\\Local\\Temp\\.NETFramework,Version=v4.0.AssemblyAttributes.cpp<\/p>\n","protected":false},"excerpt":{"rendered":"<p>For the last few months I&#8217;ve been working on a project that utilizes C++\/CLI to bridge some legacy code with new code written in C#. A good chunk of that time has been spent running repeatedly into walls, pitfalls, quirks, and &#8220;known issues.&#8221; I figured I&#8217;d document some of the issues I&#8217;ve encountered in case [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33,2,1],"tags":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/angelmarquez.com\/index.php?rest_route=\/wp\/v2\/posts\/212"}],"collection":[{"href":"https:\/\/angelmarquez.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/angelmarquez.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/angelmarquez.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/angelmarquez.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=212"}],"version-history":[{"count":5,"href":"https:\/\/angelmarquez.com\/index.php?rest_route=\/wp\/v2\/posts\/212\/revisions"}],"predecessor-version":[{"id":215,"href":"https:\/\/angelmarquez.com\/index.php?rest_route=\/wp\/v2\/posts\/212\/revisions\/215"}],"wp:attachment":[{"href":"https:\/\/angelmarquez.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=212"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/angelmarquez.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=212"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/angelmarquez.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=212"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}