473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 1685

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

Similar topics

4
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
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
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
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
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
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
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
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
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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
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
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...

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.