{"id":4197,"date":"2017-12-30T17:20:00","date_gmt":"2017-12-31T01:20:00","guid":{"rendered":"https:\/\/www.coretechnologies.com\/blog\/?p=4197"},"modified":"2022-05-01T22:39:27","modified_gmt":"2022-05-02T05:39:27","slug":"force-dot-net-64-bit","status":"publish","type":"post","link":"https:\/\/www.coretechnologies.com\/blog\/alwaysup\/force-dot-net-64-bit\/","title":{"rendered":"Q &#038; A: How do I force my .NET console application to run 64-bit?"},"content":{"rendered":"<div align=\"center\"><img loading=\"lazy\" decoding=\"async\" class=\"no-lazy-load\" src=\"\/blog\/images\/qa-dot-net.webp\" title=\"Q &#038; A - .NET\" alt=\"Q &#038; A - .NET\" width=\"380\" height=\"154\" border=\"0\" \/><\/div>\n<div class=\"blog-qa-question-box\">\n<img loading=\"lazy\" decoding=\"async\" class=\"no-lazy-load\" src=\"https:\/\/cdn.coretechnologies.com\/images\/quotes-transparent-21x21.webp\" width=\"21\" height=\"21\" \/>&nbsp;&nbsp;We have installed AlwaysUp version 9.7.2.88 (Sep. 2 2016) on Windows Server 2012 R2 Standard. We have multiple jobs that run a 64-bit .NET Console Application as a windows service, but we keep getting a SystemOutMemoryException error. What we found watching the Task Manager is that the EXE always runs as 32-bit. <b>How do we get AlwaysUp to run the console app as 64-bit<\/b>?<\/p>\n<p align=\"right\">&#8212; Clayton<\/p>\n<\/div>\n<p>\nHi Clayton. There are a couple of ways to force your .NET application to run in 64-bit mode:\n<\/p>\n<ol style=\"margin-left:1.3em;padding:0;\">\n<li>\n<h2><b>Build a 64-Bit .NET Version<\/b><\/h2>\n<p>\nIf you use <a href=\"https:\/\/www.visualstudio.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">Microsoft&#8217;s Visual Studio<\/a>, the build configuration is likely be set to <b>Any CPU<\/b> (the default):<br \/>\n<a href=\"\/blog\/images\/visual-studio-any-cpu-configuration.png\" class=\"zoomPopup\" rel=\"zoomgroup noopener noreferrer\" title=\"Visual Studio Any CPU Configuration\" target=\"_blank\"><br \/>\n<img decoding=\"async\" src=\"\/blog\/images\/visual-studio-any-cpu-configuration.png\" title=\"Visual Studio Any CPU Configuration (click to enlarge)\" alt=\"Visual Studio Any CPU Configuration\" border=\"0\" width=\"500\" ><\/a>\n<\/p>\n<p>\nThis will produce an executable that will run in either 32-bit or 64-bit mode, depending on the version of .NET available.\n<\/p>\n<p>\nTo run your executable in 64-bit only, change the configuration to <b>x64<\/b> and rebuild.\n<\/p>\n<p>\nIf your project doesn&#8217;t have a x64 configuration, create one like this:\n<\/p>\n<ol type=\"a\">\n<li>\n<p>Select <b>Build &gt; Configuration Manager&#8230;<\/b><\/p>\n<\/li>\n<li>\n<p>In the Configuration Manager, <\/p>\n<\/li>\n<li>\n<p>click the <b>Active solution platform<\/b> entry and select <b>&lt;New&gt;<\/b> from the menu that appears:<br \/>\n<a href=\"\/blog\/images\/create-new-visual-studio-configuration.png\" class=\"zoomPopup\" rel=\"zoomgroup noopener noreferrer\" title=\"Create a New Visual Studio Configuration\" target=\"_blank\"><br \/>\n<img decoding=\"async\" src=\"\/blog\/images\/create-new-visual-studio-configuration.png\" title=\"Create a New Visual Studio Configuration (click to enlarge)\" alt=\"Create a New Visual Studio Configuration\" border=\"0\" width=\"480\" ><\/a>\n<\/p>\n<\/li>\n<li>\n<p>In the <b>New Solution Platform<\/b> window, choose <b>x64<\/b> in the top box. We recommend copying settings from <b>Any CPU<\/b> and creating new project platforms (the default):<br \/>\n<a href=\"\/blog\/images\/select-x64-visual-studio-solution.png\" class=\"zoomPopup\" rel=\"zoomgroup noopener noreferrer\" title=\"Create a New Visual Studio Configuration: Select x64\" target=\"_blank\"><br \/>\n<img decoding=\"async\" src=\"\/blog\/images\/select-x64-visual-studio-solution.png\" title=\"Create a New Visual Studio Configuration: Select x64 (click to enlarge)\" alt=\"Create a New Visual Studio Configuration: Select x64\" border=\"0\" width=\"480\" ><\/a>\n<\/p>\n<\/li>\n<li>\n<p>Click the <b>OK<\/b> button to record your changes. Close the Configuration Manager<\/p>\n<\/li>\n<li>\n<p>You should now have x64 as a build option. Set it and recompile to produce a 64-bit only executable:<br \/>\n<a href=\"\/blog\/images\/activate-x64-visual-studio-configuration.png\" class=\"zoomPopup\" rel=\"zoomgroup noopener noreferrer\" title=\"Activate the x64 Configuration in Visual Studio\" target=\"_blank\"><br \/>\n<img decoding=\"async\" src=\"\/blog\/images\/activate-x64-visual-studio-configuration.png\" title=\"Activate the x64 Configuration in Visual Studio (click to enlarge)\" alt=\"Activate the x64 Configuration in Visual Studio\" border=\"0\" width=\"480\" ><\/a>\n<\/p>\n<\/li>\n<\/ol>\n<li>\n<h2><b>Use CorFlags to Force .NET 64-Bit<\/b><\/h2>\n<p>\nIf your application is built with &#8220;Any CPU&#8221; but you can&#8217;t rebuild it in Visual Studio, Microsoft&#8217;s free <a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/framework\/tools\/corflags-exe-corflags-conversion-tool\" target=\"_blank\" rel=\"noopener noreferrer\">CorFlags utility<\/a> will come to the rescue.\n<\/p>\n<p>\nCorflags.exe is distributed with the <a href=\"https:\/\/developer.microsoft.com\/en-us\/windows\/downloads\/windows-10-sdk\" target=\"_blank\" rel=\"noopener noreferrer\">Windows 10 SDK<\/a>. Be sure to select the &#8220;.NET Development Tools&#8221; component when installing.\n<\/p>\n<p>\nWe actually found the CorFlags exe file in a couple of places on our hard drive:<\/p>\n<blockquote><p>C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v10.0A\\bin\\NETFX 4.6.1 Tools\\Corflags.exe<\/p><\/blockquote>\n<blockquote><p>C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v7.0A\\Bin\\Corflags.exe<\/p><\/blockquote>\n<p>\nYou may find CorFlags in older .NET SDK installations as well &#8212; it has been around since the release of .NET 2.0 (2005).\n<\/p>\n<p>\nOnce you have located CorFlags:\n<\/p>\n<ol type=\"a\">\n<li>\n<p>Make a copy of the executable you want to run in 64-bit. The application we used for testing is called SystemInfoDotNet.exe, so we copied it to SystemInfoDotNet64.exe.<\/p>\n<\/li>\n<li>\n<p>Open a command prompt with admin rights.<\/p>\n<\/li>\n<li>\n<p>CD to the folder containing the copied application.<\/p>\n<\/li>\n<li>\n<p>Run CorFlags on the copied application file. Specify the <b>\/32BIT-<\/b> option to strip away the ability to run in 32-bit mode:<br \/>\n<a href=\"\/blog\/images\/run-corflags.gif\" class=\"zoomPopup\" rel=\"zoomgroup noopener noreferrer\" title=\"Run CorFlags \/32BIT-\" target=\"_blank\"><br \/>\n<img decoding=\"async\" src=\"\/blog\/images\/run-corflags.gif\" title=\"Run CorFlags \/32BIT- (click to enlarge)\" alt=\"Run CorFlags \/32BIT-\" border=\"0\" width=\"480\" ><\/a>\n<\/p>\n<\/li>\n<\/ol>\n<p>The copied executable will always run in 64-bit mode.<\/p>\n<p>For example, our SystemInfoDotNet utility &#8212; which displays basic process and system information &#8212; normally runs in 32-bit mode:<br \/>\n<a href=\"\/blog\/images\/SystemInfoDotNet-running.png\" class=\"zoomPopup\" rel=\"zoomgroup noopener noreferrer\" title=\"SystemInfoDotNet running before CorFlags\" target=\"_blank\"><br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"\/blog\/images\/SystemInfoDotNet-running.png\" width=\"459\" height=\"300\" title=\"SystemInfoDotNet running before CorFlags (click to enlarge)\" alt=\"SystemInfoDotNet running before CorFlags\" border=\"0\"  ><\/a>\n<\/p>\n<p>But after running CorFlags on SystemInfoDotNet64, it magically runs in 64-bit mode:<br \/>\n<a href=\"\/blog\/images\/SystemInfoDotNet64-running.png\" class=\"zoomPopup\" rel=\"zoomgroup noopener noreferrer\" title=\"SystemInfoDotNet running after CorFlags\" target=\"_blank\"><br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"\/blog\/images\/SystemInfoDotNet64-running.png\" width=\"459\" height=\"300\" title=\"SystemInfoDotNet running after CorFlags (click to enlarge)\" alt=\"SystemInfoDotNet running after CorFlags\" border=\"0\" ><\/a>\n<\/p>\n<\/li>\n<\/ol>\n<p><\/p>\n<p>\nBest of luck with your .NET application Clayton!<\/p>\n<!-- relpost-thumb-wrapper --><div class=\"relpost-thumb-wrapper\"><!-- filter-class --><div class=\"relpost-thumb-container\"><style>.relpost-block-single-image, .relpost-post-image { margin-bottom: 10px; }<\/style><h3>You may also like...<\/h3><div style=\"clear: both\"><\/div><div style=\"clear: both\"><\/div><!-- relpost-block-container --><div class=\"relpost-block-container relpost-block-column-layout\" style=\"--relposth-columns: 3;--relposth-columns_t: 2; --relposth-columns_m: 2\"><a href=\"https:\/\/www.coretechnologies.com\/blog\/windows-services\/net-vs-sc\/\"class=\"relpost-block-single\" ><div class=\"relpost-custom-block-single\"><img decoding=\"async\" loading=\"lazy\" class=\"relpost-block-single-image\" alt=\"Q&amp;A: Should I use NET or SC to start\/stop\/restart our Windows Services?\"  src=\"https:\/\/www.coretechnologies.com\/blog\/wp-content\/uploads\/net-vs-sc-command-150x150-1.png\" style=\"aspect-ratio:1\/1\" style=\"aspect-ratio:1\/1\"><\/img><div class=\"relpost-block-single-text\"  style=\"height: 75px;font-family: Arial;  font-size: 12px;  color: #333333;\"><h2 class=\"relpost_card_title\">Q&amp;A: Should I use NET or SC to start\/stop\/restart our Windows Services?<\/h2><\/div><\/div><\/a><a href=\"https:\/\/www.coretechnologies.com\/blog\/alwaysup\/windows-password-management\/\"class=\"relpost-block-single\" ><div class=\"relpost-custom-block-single\"><img decoding=\"async\" loading=\"lazy\" class=\"relpost-block-single-image\" alt=\"Q&amp;A: Where does AlwaysUp store the Password for my Windows Account?\"  src=\"https:\/\/www.coretechnologies.com\/blog\/wp-content\/uploads\/password-security-150x150-1.png\" style=\"aspect-ratio:1\/1\" style=\"aspect-ratio:1\/1\"><\/img><div class=\"relpost-block-single-text\"  style=\"height: 75px;font-family: Arial;  font-size: 12px;  color: #333333;\"><h2 class=\"relpost_card_title\">Q&amp;A: Where does AlwaysUp store the Password for my Windows Account?<\/h2><\/div><\/div><\/a><a href=\"https:\/\/www.coretechnologies.com\/blog\/alwaysup\/version-10-5\/\"class=\"relpost-block-single\" ><div class=\"relpost-custom-block-single\"><img decoding=\"async\" loading=\"lazy\" class=\"relpost-block-single-image\" alt=\"New Version\"  src=\"https:\/\/www.coretechnologies.com\/blog\/wp-content\/uploads\/new-version-150x150.png\" style=\"aspect-ratio:1\/1\" style=\"aspect-ratio:1\/1\"><\/img><div class=\"relpost-block-single-text\"  style=\"height: 75px;font-family: Arial;  font-size: 12px;  color: #333333;\"><h2 class=\"relpost_card_title\">AlwaysUp 10.5: Restricted Rights, Smoother Shutdowns, and more<\/h2><\/div><\/div><\/a><\/div><!-- close relpost-block-container --><div style=\"clear: both\"><\/div><\/div><!-- close filter class --><\/div><!-- close relpost-thumb-wrapper -->","protected":false},"excerpt":{"rendered":"<p>&nbsp;&nbsp;We have installed AlwaysUp version 9.7.2.88 (Sep. 2 2016) on Windows Server 2012 R2 Standard. We have multiple jobs that run a 64-bit .NET Console Application as a windows service, but we keep getting a SystemOutMemoryException error. What we found &hellip; <a href=\"https:\/\/www.coretechnologies.com\/blog\/alwaysup\/force-dot-net-64-bit\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":3560,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[21,26,57,59,67,127,180],"class_list":["post-4197","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-alwaysup","tag-64-bit","tag-alwaysup-tag","tag-console-application","tag-corflags","tag-dot-net","tag-qa","tag-visual-studio"],"_links":{"self":[{"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/4197","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/comments?post=4197"}],"version-history":[{"count":3,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/4197\/revisions"}],"predecessor-version":[{"id":11295,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/4197\/revisions\/11295"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/media\/3560"}],"wp:attachment":[{"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/media?parent=4197"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/categories?post=4197"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/tags?post=4197"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}