473,505 Members | 15,798 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Obsolete Directive Bug

In .NET, you can mark methods and accessors as obsolete by using the
[Obsolete(msg, errflag)] directive.

I've found some interesting behavior with the directive when used in a class
which is referenced as a return type by a web service:

Consider the following class:

class foo
{
private int _bar;

[Obsolete("Obsolete. Please use bar1.", true)]
public int bar
{
get {return _bar;}
}

public int bar1
{
get {return _bar * 5;}
}
}

The true flag on the obsolete directive means that the compiler will throw
an error when someone tries to reference the bar accessor. If it is left
false, the compiler only throws a warning.

Now take this a step farther. Create a web service called FooInfo, and a
method GetFoo which returns an instance of the Foo object (prior to
obsoleting the bar accessor).
the code might look like this

FooInfo fooInfo = new FooInfo();
Foo aFoo = fooInfo.GetFoo();

When you compile this code, it will compile fine (there is no specific
reference to bar or bar1 in the code). However, when you mark bar as
obsolete, the code will still compile, but the program will crash when you
try to run it. But it won't crash on the GetFoo line. It crashes on the
constructor for the WebService. The error will look like the following:

"File or assembly name uxc_b_hj.dll, or one of its dependencies, was not
found."

The name of the dll referenced will change each time (it is a temp dll
windows uses during runtime).

If you mark bar as obsolete, and leave it as a warning, everything works fine.

I'm sure there is is good reason this works this way, but the error is
certainly misleading, and took 4-5 hours to figure out, since the turning on
the obsolete directive happened two weeks ago in a different project.
Hopefully this will save others some time.

Jul 21 '05 #1
0 1698

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2727
by: BrianProgrammer | last post by:
I have this code below, that works like a champ, but two lines are continually marked as obsolete. See embeded notes. Private Shared Function TransformHTMLString(ByVal XSLT As String, _ ByVal...
2
5017
by: Steve James | last post by:
I am trying to mark an override method in a derived class as obsolete using the ObsoleteAttribute. The compiler, however is not picking up this attribute and is not generating a warning or an...
1
1407
by: BrianProgrammer | last post by:
I have this code below, that works like a champ, but two lines are continually marked as obsolete. See embeded notes. Private Shared Function TransformHTMLString(ByVal XSLT As String, _ ByVal...
0
304
by: jbeerni | last post by:
In .NET, you can mark methods and accessors as obsolete by using the directive. I've found some interesting behavior with the directive when used in a class which is referenced as a return type...
1
1840
by: Mike Hofer | last post by:
I've got two statements in my code that are both generating weird, weird, weird messages: The first one was, Dim document As System.Xml.XmlDocument Dim navigator As...
4
1439
by: Phill W. | last post by:
If I have a reusbale (GAC-'registered') assembly that contains two, related classes (imagine a DataSet and DataTable; the former contains instances of the latter, the latter has a reference to its...
5
1268
by: teddysnips | last post by:
In the class declaration of a web service that I've just picked up for maintenance: <Obsolete("Superseded by OrderPaymentElements")Public PaymentType As OrderPaymentType Public...
9
8388
by: Erwin Moller | last post by:
Hi, Can anybody comment on this? In comp.lang.php I advised somebody to skip using: <script language="javascript"> and use: <script type="text/javascript"> And mr. Dunlop gave this response:
0
961
by: shantanuaggarwal | last post by:
Hi all - would like to write a custom attribute, which, when applied to a constructor will make the compiler issue a warning. Just like the Obsolete Attribute, but with a name of my choosing. ...
0
7103
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7307
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7370
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7478
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4701
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3177
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1532
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
755
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
409
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.