4

I've taken over a project with a lot of legacy code, both C++ and C#, currently compiling under VS 2010 (on windows 7).

When I built my solution, amazingly, 143 projects built successfully. However, there were a boat load of warnings. A surprising number of them were warning about obsolete functions.

warning CS0618: 'System.Runtime.InteropServices.UCOMIMoniker' is obsolete
warning CS0618: 'System.Runtime.InteropServices.UCOMIEnumMoniker' is obsolete
warning CS0618: 'System.Runtime.InteropServices.UCOMIRunningObjectTable' is obsolete
warning CS0618: 'System.Runtime.InteropServices.UCOMIRunningObjectTable' is obsolete
warning CS0618: 'System.Runtime.InteropServices.UCOMIBindCtx' is obsolete
warning CS0618: 'System.IO.Path.InvalidPathChars' is obsolete
warning CS0618: 'System.Configuration.ConfigurationSettings.AppSettings' is obsolete
warning CS0618: 'System.Net.Dns.GetHostByName(string)' is obsolete

What is meant by this? The functions are clearly still defined or they wouldn't compile or would give me some sort of 'not found' or 'not defined' error. Are the implementations missing? Do these functions still work (as well as they used to)?

Several I have looked up and they've been obsolete for a long long time. For example, GetHostByName :

.NET Framework

Supported in: 1.1
Obsolete (compiler warning) in 4.6
Obsolete (compiler warning) in 4.6
Obsolete (compiler warning) in 4.5
Obsolete (compiler warning) in 4.5.1
Obsolete (compiler warning) in 4.5.2
Obsolete (compiler warning) in 4
Obsolete (compiler warning) in 3.5
Obsolete (compiler warning) in 3.5 SP1
Obsolete (compiler warning) in 3.0
Obsolete (compiler warning) in 3.0 SP1
Obsolete (compiler warning) in 3.0 SP2
Obsolete (compiler warning) in 2.0
Obsolete (compiler warning) in 2.0 SP1
Obsolete (compiler warning) in 2.0 SP2

If I understand that right, its been obsolete for the last 8-9 years(.NET 2.0 came out in 2006). Why hasn't anyone fixed these? Do they need to be fixed? When I researched that GetHostByName method, its replaced with GetHostEntry. Easy enough... but hold on, there are lots of people complaining that it doesn't work the same with the new function and maybe you should replace it with a call to GetHostAddresses instead. Well, dang.

Given that I've got over 28k files in my solution, I'm not sure I can just go messing with things willy nilly. Is there way to know how long obsolete functions will be supported for? Should I expect that these will even work once I get the system installed? What are the system implications of having code invoke obsolete interfaces (MSDN)?

I am not trying to understand how to remove obsolete code from my own system, but how systems are supposed to deal with obsoleted interfaces on external systems (eg. MSDN). They clearly are not following a simple cycle of marking obsolete, replacing, and deleting old interfaces. What is their policy? How should users of MSDN defined interfaces react to the obsolete tag, particularly when the obsoleted code isn't replaced with an 'apples to apples' equivalent function.

LawfulEvil
  • 2,267
  • 24
  • 46
  • 1
    I think http://stackoverflow.com/questions/3510892/usage-of-the-obsolete-attribute already answers concrete part of this question (despite being C# specific), and remaining - "how long obsolete features are supported" is really not answerable directly as there tons of such APIs with likely different support lifetimes. Normally support for couple major version would be reasonable. – Alexei Levenkov Apr 21 '15 at 19:17
  • One of the fundamental aspects of my question is not addressed in that answer at all. Do obsolete functions interfaces continue to have non-trivial implementations? That is, do they still 'work'? I read that question before posting mine and felt that there were a number of unanswered questions which I needed the answer for. – LawfulEvil Apr 21 '15 at 19:24
  • 1
    I would expect such methods to "work" (strictly in a sense of how they are documented, and sometimes always throwing exception may be an option, also I never heard of such case with .Net Framework's APIs), but eventually disappear completely. – Alexei Levenkov Apr 21 '15 at 19:33

3 Answers3

10

Often classes or methods get marked as obsolete as they will be deprecated in the next release or are no longer the most efficient way to do a certain task. However, Microsoft often leaves these methods for a long time to guarantee backwards compatibility.

Alex
  • 21,273
  • 10
  • 61
  • 73
2

In programming the term 'OBSOLETE' means that the assembly/resource/function/type its deprecated or old, translated it means that the compiler notices you that there is a better or newer way to do it. Example: PHP's mysql_query() function.

Andrei Vlad
  • 215
  • 2
  • 10
0

I would agree with all the above answers. What i will suggest on the top of it is that when compiler complains about the obsolete method is an alarm to go ahead and replace it with the alternate approach provided in the SDK. If you are not planning to upgrade your project to newer .NET framework then you are good to live with this warning for the life time.