{"id":9471,"date":"2016-08-24T14:07:02","date_gmt":"2016-08-24T13:07:02","guid":{"rendered":"http:\/\/www.itwriting.com\/blog\/?p=9471"},"modified":"2016-08-24T14:07:02","modified_gmt":"2016-08-24T13:07:02","slug":"time-for-another-look-at-pure-net","status":"publish","type":"post","link":"https:\/\/www.itwriting.com\/blog\/9471-time-for-another-look-at-pure-net.html","title":{"rendered":"Time for another look at \u201cpure .NET\u201d"},"content":{"rendered":"<p>Back in the Nineties there was a lot of fuss about \u201cpure Java\u201d. This meant Java code without any native code invocations that tie the application to a specific operating system.<\/p>\n<p>It is possible to write cross-platform Java code that invokes native code, but it adds to the complexity. If it is an operating system API you need conditional code so that the write API is called on each platform. If it is a custom library it will have to be compiled separately for each platform.<\/p>\n<p>Over on the Microsoft .NET site, developers have tended to have a more casual approach. After all, in the great majority of cases the code would only ever run on Windows. Further, Microsoft tended to steer developers towards Windows-only dependencies like SQL Server. After all, that is the value of owning a developer platform.<\/p>\n<p>Times change. Microsoft has got the cross-platform bug, with its business strategy based on attracting businesses to its cloud properties (Office 365 and Azure) rather than Windows. The .NET Framework has been forked to create .NET Core, which runs on Mac and Linux as well as Windows. SQL Server is coming to Linux. <\/p>\n<p>Another issue is porting applications from 32-bit to 64-bit, as I was reminded recently when migrating some ASP.NET applications to a new site. If your .NET code avoids P\/Invoke (Platform Invoke) then you can compile for \u201cAny CPU\u201d and 64-bit will just work. If you used P-invoke and want to support both 32-bit and 64-bit it requires more care. IntPtr, used frequently in P\/Invoke calls, is a different size. If you have custom native libraries, you need to compile them separately for each platform. The lazy solution is always to run as 32-bit but that is a shame.<\/p>\n<p>What this means is that P\/Invoke should only be used as a last resort. Arguably this has always been true, but the reasons are stronger today.<\/p>\n<p>This is also an issue for libraries and components intended for general use, whether open source or commercial. It is early days for .NET Core support, but any native code dependencies will be a problem.<\/p>\n<p>Breaking the P\/Invoke habit will not be easy but \u201cPure .NET\u201d is the way to go whenever possible.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Back in the Nineties there was a lot of fuss about \u201cpure Java\u201d. This meant Java code without any native code invocations that tie the application to a specific operating system. It is possible to write cross-platform Java code that invokes native code, but it adds to the complexity. If it is an operating system &hellip; <a href=\"https:\/\/www.itwriting.com\/blog\/9471-time-for-another-look-at-pure-net.html\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Time for another look at \u201cpure .NET\u201d<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26,55],"tags":[104,236,565,586],"class_list":["post-9471","post","type-post","status-publish","format-standard","hentry","category-development","category-microsoft","tag-net","tag-c","tag-mac","tag-microsoft"],"_links":{"self":[{"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/posts\/9471","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/comments?post=9471"}],"version-history":[{"count":0,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/posts\/9471\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/media?parent=9471"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/categories?post=9471"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.itwriting.com\/blog\/wp-json\/wp\/v2\/tags?post=9471"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}