Bug in .NET 1.1

  • Thread starter Truong Hong Thi
  • Start date
T

Truong Hong Thi

Recently I had to write a custom user control which requires lots of
drawing. When surfing .NET framework 1.1 source with Lutz Roeder's .NET
Reflector, I happened to find something: class System.Drawing.SR
contains 2 methods GetDouble(CultureInfo, string) and
GetFloat(CultureInfo, string), I paste the source code here:

public static double GetDouble(CultureInfo culture, string name)
{
double num1 = 0;
SR sr1 = SR.GetLoader();
if (sr1 == null)
{
object obj1 = sr1.resources.GetObject(name, culture);
if (obj1 is double)
{
num1 = (double) obj1;
}
}
return num1;
}

Note that the class implements singleton pattern, SR.GetLoader static
method returns the single instance of the class (it uses
double-checking and locks on typeof(SR)).

It is clear that the author of this method expects a
NullReferenceException. It should have been "if (sr1 != 0)". The same
error appears in GetFloat method. Other similar methods of the class
(like GetInt) does not have that error.

Although these two methods were not used (the Analyze feature of
Reflector tells me so), they appear funny to me :). I did not think
there are such things in the framework.

I will check this on .NET Framework 2.0.

Regards,
Thi
 
S

Stoitcho Goutsev \(100\)

Truong Hong Thi,

Implementing design time support for controls require a lot of digging into
the framework code. We are so happy to have this excelent tool - Reflector
thanks to Lutz.

The more you dig the more bugs like this you can find. But don't be so hard
on the MS guys I believe if we look at ours code we can find bug like this
also. The class is internal - not supposed to be used and as you said it is
not used anywhere in the assembly, so what's the big deal. I believe if they
used it they would've found this problem.


I was currious and check in v2.0 this and many other GetXXX methods are
completely gone.
 
T

Truong Hong Thi

Yes, thay were removed in v2.0.

In both versions, the class SR (I guess it is "System Resources") is
used in many other places, like System.SR (in System.dll),
System.Windows.Forms.SR, System.Web.SR. Microsoft had to copy the same
class to other assemplies because they did not want to expose it. It is
not a good thing copying code around, and it is an sign that the we
lack something for this. I expect future version of C# would support an
access specifier (or some kind of attribute to place on public stuff)
like "same evidence" which allow access by assemblies of the same
evidence (same strong name, for example).

Isn't this a good idea?
 
S

Stoitcho Goutsev \(100\)

Truong Hong Thi,

I believe SR has something to do with resources, but .NET privides good API
for managing resources anyway.

MS implmentation of the platform is tied to the Windows OS, so there are
many internal classes that use native methods. No one should care about
their existance because the API has to be platform indipendent (except
Windows Forms).

Imagine that there wasn't reflection or Reflector-like tools, you'll never
know about classes like SR and you'll never made this post in the first
place :).

Even though I say that, many times a day I hade the fact that some class or
member is declared internal and I whish I could use it. I found thought that
more often than never the internl functionality is somewhere exposed thru
some public class or service, but it needs a lot of digging to find it.
Analyze feature of the Reflector helps big times, but not always.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top