I wonder that the obsolete attribute is checked at only runtime?
Think that you have two assemblies. Assembly A uses a method from Assembly B. After that we mark the method in Assembly B as obsolete which causes a compile time error when compiling assembly A.
No problem so far but the question is whether the older assembly A continue to work with new Assembly B or not? Thanks
It depends on what you are doing. The [Obsolete]
attribute is primarily for use at compile-time, but be aware that some parts of the runtime have different behavior when it is present (see below). It might cause problems, even to existing code that is not rebuilt, so we must conclude that NO, [Obsolete]
is not checked only at compile time.
For example, the code below will write Foo
but not Bar
:
using System;
using System.Xml.Serialization;
public class Data
{
public int Foo { get; set; }
[Obsolete] public int Bar {get;set;}
static void Main()
{
var data = new Data { Foo = 1, Bar = 2 };
new XmlSerializer(data.GetType()).Serialize(Console.Out, data);
}
}
(XmlSerializer
is a runtime too - not part of the compiler)