warning CS0618: ‘Device.OS’ is obsolete: ‘TargetPlatform is obsolete as of version 2.3.4. Please use RuntimePlatform instead.’

Here is a couple of compiler generated warnings I found on project I was recently reviewing:

  1. warning CS0618: ‘Device.OS’ is obsolete: ‘TargetPlatform is obsolete as of version 2.3.4. Please use RuntimePlatform instead.’
  2. warning CS0612: ‘TargetPlatform’ is obsolete

A CS0612 is generated when the code references a type or member to wich the parameterless ObsoleteAttribute was applied.

CS0618 is generated when the code references a type or member to wich a parameterized ObsoleteAttribute was applied.

In this case, the reference to Device.OS has to be replaced with a reference to Device.RuntimePlatform.

Since Device.OS was an enum of type TargetPlatform and Device.RuntimePlatform is a string, it is necessary to update the right hand of the expression as well.

For that you can use one of the string constants defined on the Device class:

  • iOS;
  • Android;
  • WinPhone;
  • UWP;
  • WinRT;
  • macOS;

Here’s how the code looked like originally:

And here’s how the looks code after the update:

Published by

Alfred Myers

I have been interested in computers since I got my hands on a magazine about digital electronics back in 1983 and programming them has been paying the bills since 1991. Having focused on Microsoft-centric technology stacks for the best part of two decades, in recent years I’ve been educating myself on open source technologies such as Linux, networking and the open web platform.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d