469,592 Members | 1,713 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,592 developers. It's quick & easy.

.Net 2.0 classes very buggy?

Hi all,

I'm playing with Lutz Roeders Reflector and have found several areas
where I think there are issues in the framework libraries. I can't see
how the following should work as expected and the compiler gives me an
error on the 'text1 = text1...' line. Is it really this buggy (this
particular bug is in several places) or am I missing something? You can
see that that code has a possibility of crashing if the property has a
.. in it. I think the line should read 'text1 = property.Name....'.

The code is from the ProfileBuilder class in the System.Web.Compilation
class.

private void CreateCodeForProperty(AssemblyBuilder assemblyBuilder,
CodeTypeDeclaration type, ProfileNameTypeStruct property)
{
string text1;
int num1 = property.Name.IndexOf('.');
if (num1 > 0)
{
text1 = text1.Substring(num1 + 1);
}
if (!assemblyBuilder.CodeDomProvider.IsValidIdentifie r(text1))
{
throw new
ConfigurationErrorsException(SR.GetString("Profile _bad_name"),
property.FileName, property.LineNumber);
}
CodeMemberProperty property1 = new CodeMemberProperty();
property1.Name = text1;
property1.Attributes = MemberAttributes.Public;
property1.HasGet = true;
property1.Type = property.PropertyCodeRefType;
CodeMethodInvokeExpression expression1 = new
CodeMethodInvokeExpression();
expression1.Method.TargetObject = new
CodeThisReferenceExpression();
expression1.Method.MethodName = "GetPropertyValue";
expression1.Parameters.Add(new CodePrimitiveExpression(text1));
CodeMethodReturnStatement statement1 = new
CodeMethodReturnStatement(new CodeCastExpression(property1.Type,
expression1));
property1.GetStatements.Add(statement1);
if (!property.IsReadOnly)
{
CodeMethodInvokeExpression expression2 = new
CodeMethodInvokeExpression();
expression2.Method.TargetObject = new
CodeThisReferenceExpression();
expression2.Method.MethodName = "SetPropertyValue";
expression2.Parameters.Add(new
CodePrimitiveExpression(text1));
expression2.Parameters.Add(new
CodePropertySetValueReferenceExpression());
property1.HasSet = true;
property1.SetStatements.Add(expression2);
}
type.Members.Add(property1);
}

Your thoughts would be welcome.

Ryan

Jun 12 '06 #1
9 1228
"Ryan" <ry***@lightsdown.com> wrote in message
news:11**********************@j55g2000cwa.googlegr oups.com...
Hi all,

I'm playing with Lutz Roeders Reflector and have found several areas
where I think there are issues in the framework libraries. I can't see
how the following should work as expected and the compiler gives me an
error on the 'text1 = text1...' line. Is it really this buggy (this
particular bug is in several places) or am I missing something? You can
see that that code has a possibility of crashing if the property has a
. in it. I think the line should read 'text1 = property.Name....'.

The code is from the ProfileBuilder class in the System.Web.Compilation
class.

private void CreateCodeForProperty(AssemblyBuilder assemblyBuilder,
CodeTypeDeclaration type, ProfileNameTypeStruct property)
{
string text1;
int num1 = property.Name.IndexOf('.');
if (num1 > 0)
{
text1 = text1.Substring(num1 + 1);
} ....
<snip>
.... Your thoughts would be welcome.


When I look at that method with Reflector the first line is:
string text1 = property.Name;
which means that all is well. If it's any help I'm using Reflector
v4.2.27.0.

Chris Jobson
Jun 12 '06 #2

Chris Jobson wrote:
"Ryan" <ry***@lightsdown.com> wrote in message
news:11**********************@j55g2000cwa.googlegr oups.com...
Hi all,

I'm playing with Lutz Roeders Reflector and have found several areas
where I think there are issues in the framework libraries. I can't see
how the following should work as expected and the compiler gives me an
error on the 'text1 = text1...' line. Is it really this buggy (this
particular bug is in several places) or am I missing something? You can
see that that code has a possibility of crashing if the property has a
. in it. I think the line should read 'text1 = property.Name....'.

The code is from the ProfileBuilder class in the System.Web.Compilation
class.

private void CreateCodeForProperty(AssemblyBuilder assemblyBuilder,
CodeTypeDeclaration type, ProfileNameTypeStruct property)
{
string text1;
int num1 = property.Name.IndexOf('.');
if (num1 > 0)
{
text1 = text1.Substring(num1 + 1);
}

...
<snip>
...
Your thoughts would be welcome.


When I look at that method with Reflector the first line is:
string text1 = property.Name;
which means that all is well. If it's any help I'm using Reflector
v4.2.27.0.

Chris Jobson


V4.2.43.0 seems to have bugs then, thanks for checking it out.

Ryan

Jun 12 '06 #3
What makes you think this class is buggy? What exactly do you mean with
crashing? Any exception would be helpfull. Also, keep in mind that you are
reverse engineering a private non documented class.

Willy.
"Ryan" <ry***@lightsdown.com> wrote in message
news:11**********************@j55g2000cwa.googlegr oups.com...
| Hi all,
|
| I'm playing with Lutz Roeders Reflector and have found several areas
| where I think there are issues in the framework libraries. I can't see
| how the following should work as expected and the compiler gives me an
| error on the 'text1 = text1...' line. Is it really this buggy (this
| particular bug is in several places) or am I missing something? You can
| see that that code has a possibility of crashing if the property has a
| . in it. I think the line should read 'text1 = property.Name....'.
|
| The code is from the ProfileBuilder class in the System.Web.Compilation
| class.
|
| private void CreateCodeForProperty(AssemblyBuilder assemblyBuilder,
| CodeTypeDeclaration type, ProfileNameTypeStruct property)
| {
| string text1;
| int num1 = property.Name.IndexOf('.');
| if (num1 > 0)
| {
| text1 = text1.Substring(num1 + 1);
| }
| if (!assemblyBuilder.CodeDomProvider.IsValidIdentifie r(text1))
| {
| throw new
| ConfigurationErrorsException(SR.GetString("Profile _bad_name"),
| property.FileName, property.LineNumber);
| }
| CodeMemberProperty property1 = new CodeMemberProperty();
| property1.Name = text1;
| property1.Attributes = MemberAttributes.Public;
| property1.HasGet = true;
| property1.Type = property.PropertyCodeRefType;
| CodeMethodInvokeExpression expression1 = new
| CodeMethodInvokeExpression();
| expression1.Method.TargetObject = new
| CodeThisReferenceExpression();
| expression1.Method.MethodName = "GetPropertyValue";
| expression1.Parameters.Add(new CodePrimitiveExpression(text1));
| CodeMethodReturnStatement statement1 = new
| CodeMethodReturnStatement(new CodeCastExpression(property1.Type,
| expression1));
| property1.GetStatements.Add(statement1);
| if (!property.IsReadOnly)
| {
| CodeMethodInvokeExpression expression2 = new
| CodeMethodInvokeExpression();
| expression2.Method.TargetObject = new
| CodeThisReferenceExpression();
| expression2.Method.MethodName = "SetPropertyValue";
| expression2.Parameters.Add(new
| CodePrimitiveExpression(text1));
| expression2.Parameters.Add(new
| CodePropertySetValueReferenceExpression());
| property1.HasSet = true;
| property1.SetStatements.Add(expression2);
| }
| type.Members.Add(property1);
| }
|
| Your thoughts would be welcome.
|
| Ryan
|
Jun 12 '06 #4

Ryan wrote:
Hi all,

I'm playing with Lutz Roeders Reflector and have found several areas
where I think there are issues in the framework libraries. I can't see
how the following should work as expected and the compiler gives me an
error on the 'text1 = text1...' line.
What's the error?
Is it really this buggy (this
particular bug is in several places) or am I missing something? You can
see that that code has a possibility of crashing if the property has a
. in it.


OK. Can you show us the code that would make this crash?

--
Larry Lard
Replies to group please

Jun 12 '06 #5
You are too quick to consider things to be buggy.
Reflector is right, if you are not sure check the IL..

IL_0015: ldloc.1
IL_0016: ldc.i4.1
IL_0017: add
IL_0018: callvirt instance string [mscorlib]System.String::Substring(int32)

which turns into...

text1 = text1.Substring(num1 + 1);
in C#

Willy.
"Ryan" <ry***@lightsdown.com> wrote in message
news:11**********************@j55g2000cwa.googlegr oups.com...
|
| Chris Jobson wrote:
| > "Ryan" <ry***@lightsdown.com> wrote in message
| > news:11**********************@j55g2000cwa.googlegr oups.com...
| > > Hi all,
| > >
| > > I'm playing with Lutz Roeders Reflector and have found several areas
| > > where I think there are issues in the framework libraries. I can't see
| > > how the following should work as expected and the compiler gives me an
| > > error on the 'text1 = text1...' line. Is it really this buggy (this
| > > particular bug is in several places) or am I missing something? You
can
| > > see that that code has a possibility of crashing if the property has a
| > > . in it. I think the line should read 'text1 = property.Name....'.
| > >
| > > The code is from the ProfileBuilder class in the
System.Web.Compilation
| > > class.
| > >
| > > private void CreateCodeForProperty(AssemblyBuilder assemblyBuilder,
| > > CodeTypeDeclaration type, ProfileNameTypeStruct property)
| > > {
| > > string text1;
| > > int num1 = property.Name.IndexOf('.');
| > > if (num1 > 0)
| > > {
| > > text1 = text1.Substring(num1 + 1);
| > > }
| > ...
| > <snip>
| > ...
| > > Your thoughts would be welcome.
| >
| > When I look at that method with Reflector the first line is:
| > string text1 = property.Name;
| > which means that all is well. If it's any help I'm using Reflector
| > v4.2.27.0.
| >
| > Chris Jobson
|
| V4.2.43.0 seems to have bugs then, thanks for checking it out.
|
| Ryan
|
Jun 12 '06 #6

Larry Lard wrote:
Ryan wrote:
Hi all,

I'm playing with Lutz Roeders Reflector and have found several areas
where I think there are issues in the framework libraries. I can't see
how the following should work as expected and the compiler gives me an
error on the 'text1 = text1...' line.


What's the error?
Is it really this buggy (this
particular bug is in several places) or am I missing something? You can
see that that code has a possibility of crashing if the property has a
. in it.


OK. Can you show us the code that would make this crash?

--
Larry Lard
Replies to group please


Well, I think the issue is with the later versions of reflector. The IL
may be correct but it is not easy to read so I am going on VB/C#
output. As Chris Jobson pointed out, it looks like my particular
version of reflector (or a conflict with the add ins).

I did not assume that the .Net classes were buggy, I was just asking as
I was not certain what was going on.

It looks like inline initialisation is not being output correctly. The
following;
private void CreateCodeForProperty(AssemblyBuilder assemblyBuilder,
CodeTypeDeclaration type, ProfileNameTypeStruct property)
{
string text1;
int num1 = property.Name.IndexOf('.');
if (num1 > 0)
{
text1 = text1.Substring(num1 + 1);

Should read (according to Chris);
private void CreateCodeForProperty(AssemblyBuilder assemblyBuilder,
CodeTypeDeclaration type, ProfileNameTypeStruct property)
{
string text1 = property.Name;
int num1 = property.Name.IndexOf('.');
if (num1 > 0)
{
text1 = text1.Substring(num1 + 1);

So you get text1 manipulation of an empty string and the compiler
complains.

Ryan

Jun 12 '06 #7
Sorry, I misread Chris post, he is right the first line should look like ...

string text1 = property.Name;

this is not the only bug in reflector (all versions), I for one never trust
the output generated by reflector.

Willy.

"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:O0**************@TK2MSFTNGP02.phx.gbl...
| You are too quick to consider things to be buggy.
| Reflector is right, if you are not sure check the IL..
|
| IL_0015: ldloc.1
| IL_0016: ldc.i4.1
| IL_0017: add
| IL_0018: callvirt instance string
[mscorlib]System.String::Substring(int32)
|
| which turns into...
|
| text1 = text1.Substring(num1 + 1);
| in C#
|
| Willy.
|
|
| "Ryan" <ry***@lightsdown.com> wrote in message
| news:11**********************@j55g2000cwa.googlegr oups.com...
||
|| Chris Jobson wrote:
|| > "Ryan" <ry***@lightsdown.com> wrote in message
|| > news:11**********************@j55g2000cwa.googlegr oups.com...
|| > > Hi all,
|| > >
|| > > I'm playing with Lutz Roeders Reflector and have found several areas
|| > > where I think there are issues in the framework libraries. I can't
see
|| > > how the following should work as expected and the compiler gives me
an
|| > > error on the 'text1 = text1...' line. Is it really this buggy (this
|| > > particular bug is in several places) or am I missing something? You
| can
|| > > see that that code has a possibility of crashing if the property has
a
|| > > . in it. I think the line should read 'text1 = property.Name....'.
|| > >
|| > > The code is from the ProfileBuilder class in the
| System.Web.Compilation
|| > > class.
|| > >
|| > > private void CreateCodeForProperty(AssemblyBuilder assemblyBuilder,
|| > > CodeTypeDeclaration type, ProfileNameTypeStruct property)
|| > > {
|| > > string text1;
|| > > int num1 = property.Name.IndexOf('.');
|| > > if (num1 > 0)
|| > > {
|| > > text1 = text1.Substring(num1 + 1);
|| > > }
|| > ...
|| > <snip>
|| > ...
|| > > Your thoughts would be welcome.
|| >
|| > When I look at that method with Reflector the first line is:
|| > string text1 = property.Name;
|| > which means that all is well. If it's any help I'm using Reflector
|| > v4.2.27.0.
|| >
|| > Chris Jobson
||
|| V4.2.43.0 seems to have bugs then, thanks for checking it out.
||
|| Ryan
||
|
|
Jun 12 '06 #8
On 12 Jun 2006 06:51:36 -0700, "Ryan" <ry***@lightsdown.com> wrote:

I did not assume that the .Net classes were buggy, I was just asking as
I was not certain what was going on.

Ryan


Ryan,

I think you should look again at the title that you gave this thread:
".NET 2.0 classes very buggy?"

Sorry, but it is a pet peeve of mine to check these technical
newsgroups and see dozens of posts implying that there is a bug with
such-and-such class or method in the framework.

For me personally, if I hit a problem with the framework, the order
that I follow in diagnosing it is:

1. Have I made a simple typo?
2. Do I have a misunderstanding with how the method/class is supposed
to function?
3. Re-read the MSDN Library docs.
4. Is this a common misunderstanding? (search the newsgroups)
5. Check books on my bookshelf.
6. Look at the internals of the framework with Reflector to get a
better understanding of what is going on under the covers.

etc.

Claiming to have found a bug in the .NET Framework would probably be
the last step in my search, yet for so, so many people, it seems to be
step #1.

Rant-mode off.

Chuck

Jun 21 '06 #9

Chuck Heatherly wrote:
On 12 Jun 2006 06:51:36 -0700, "Ryan" <ry***@lightsdown.com> wrote:

I did not assume that the .Net classes were buggy, I was just asking as
I was not certain what was going on.

Ryan


Ryan,

I think you should look again at the title that you gave this thread:
".NET 2.0 classes very buggy?"

Sorry, but it is a pet peeve of mine to check these technical
newsgroups and see dozens of posts implying that there is a bug with
such-and-such class or method in the framework.

For me personally, if I hit a problem with the framework, the order
that I follow in diagnosing it is:

1. Have I made a simple typo?
2. Do I have a misunderstanding with how the method/class is supposed
to function?
3. Re-read the MSDN Library docs.
4. Is this a common misunderstanding? (search the newsgroups)
5. Check books on my bookshelf.
6. Look at the internals of the framework with Reflector to get a
better understanding of what is going on under the covers.

etc.

Claiming to have found a bug in the .NET Framework would probably be
the last step in my search, yet for so, so many people, it seems to be
step #1.

Rant-mode off.

Chuck


Hey, I understand, that'll be why I put a question mark there at the
end of the title. I was after some input from more knowledgable people
because I did not take at face value what I was seeing.

Jun 21 '06 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Michal Vitecek | last post: by
10 posts views Thread by Frances Del Rio | last post: by
17 posts views Thread by rkusenet | last post: by
11 posts views Thread by Zoury | last post: by
11 posts views Thread by unwantedspam | last post: by
173 posts views Thread by Zytan | last post: by
5 posts views Thread by lobequadrat | last post: by
10 posts views Thread by Phat G5 (G3) | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.