July 2003 - Posts

Turn off 'Hide Advanced Members'!

I'm not sure why this is a default option for VB.NET, but if you look at VS.NET's options for VB.NET (Tools, Options, Text Editor, Basic) there's an entry "Hide Advanced Members". It's turned on by default. According to the docs:

When selected, certain members internally marked as "advanced" are hidden from view in the statement completion list. Advanced members are those that exist only for infrastructure purposes, but must be available to view. This option allows you to filter them from view if you do not need to see them.

I can't see any reason you'd want to hide a method/property/event/etc... of a class. And this came to light yesterday when I was helping someone who ran into the same problem I did with COM-Interop and Property statements. I mentioned the "let_Value" method and at his workstation we typed the object and then hit "." -- no "let_Value" method in Intellisense. I was stumped! I was positive the name of the method was "let_Value". I reviewed my blog and was correct -- it's "let_Value". Then I remembered that goofy setting. Turned that off and up popped the "let_Value" method.

One of the first things I do on a new VS.NET install is turn that option off.

Posted by PSteele | 1 comment(s)

Another Kudos!

I don't want to sound like a broken record (since many others have praised Scott and his work), but the new interface is really nice!  I still miss my WYSIWYG preview from Bloggar, but this is a great improvement.  And I love the new styles!  Thanks Scott!
Posted by PSteele | with no comments

Inheriting Constructors

An interesting thread on inheriting constructors, which .NET -- along with Java and C++ -- don't do. If you want all the same constructors as your base class, you need to add code for them.

Posted by PSteele | with no comments

Refactoring in .NET

Brenton House is asking about refactoring tools for VS.NET. I've also used Eclipse in the past and it's refactoring tools are nice. I really miss them in VS.NET. Of the links he posted, Xtreme Simplicity looks pretty nice. I'll be following the comments on his post closely.

Is anyone working on an open-source refactoring add-in for VS.NET?

Posted by PSteele | 1 comment(s)

FxCop and CLS Compliance

After finding out that VB.NET does not enforce CLS compliance (even with the CLSCompliant attribute set to True), I thought I could use FxCop to check this. Although ServerGeek said that FxCop complains about non-CLS compliance, I did not see such behavior. I created a simple, non-CLS compliant VB.NET assembly:

Namespace TestCls
    Public Class BadStuff
        Public Function CheckThis() As UInt32
            Return UInt32.Parse("5")
        End Function
    End Class
End Namespace

And got no complaints from FxCop (1.21) about it not being CLS compliant -- which it isn't since it exposes a non-CLS datatype (UInt32). Further research showed Peter Drayton mentioning FxCop as a possible use for this. Sam Gentile also commented that a tool to verify CLS compliance would be nice. I'm surprised there is no standalone tool for checking CLS compliance. Anyone working on a custom rules engine for FxCop for this purpose?

And please don't send me emails saying "csc.exe" is the tool you use to enforce CLS compliance! :)

Posted by PSteele | 11 comment(s)

NGEN *still* requires the IL.

While many people who are "into" .NET may already know this, I still see this come up in the Microsoft newsgroups from time to time. People read a little about NGEN and how it produces a native executable and they think they're in the clear (i.e. don't need to worry about the .NET framework or ILDASM). This is not true. Eric Gunnerson pointed this out in a newsgroup post a couple of years ago. It bears repeating:

Native compilation (ie preJIT with NGEN) does not address this. The whole assembly (metadata and IL) is still installed when this is done. The metadata is needed for class loading and reflection, and the IL is needed in case configuration changes make the native code outdated.

So yes, you can NGEN to get a native executable, but you still need the IL around. And the native code may not even be used all the time (configuration changes).

Also, to get the most out o f NGEN, you really need to run it on the users' system. There are a lot of things for NGEN to consider and you want those things decided on the client machine -- not a developers machine or a build machine.

Posted by PSteele | with no comments

VB.NET and DirectCast

Paul Vick: "...as it turns out, there are some narrow situations where using DirectCast can make things a tiny bit fast than they might otherwise be."
Posted by PSteele | with no comments

MS Tech Lead on VB.NET is blogging.

Scoble sends word that Paul Vick, MS Technical Lead on Visual Basic.NET now has a blog. Subscribed!
Posted by PSteele | with no comments

VB6, Variants and COM-Interop

Ran into an interesting issue with COM-interop and Variants. In VB6, I had a "Value" Property that was of type 'Variant'. While I loathe variants, it really was required for this project since it could hold all sorts of data. Since it could hold anything, this "Value" property had a "Property Get", "Property Set" and "Property Let". I needed to use this interface in a .NET class so I used TLBIMP.EXE and get a runtime-callable-wrapper (RCW).

I referenced the RCW in my .NET project and tried to set the value property:

Dim nameField As IField = DirectCast(New Field(), IField)
nameField.Value = "Patrick"

Ran it and hit an error: Error #13 - Type Mismatch. Since it was a Variant I wasn't sure why it couldn't hold a string. I tried a few other things (like casting to System.Object) but nothing worked. So I checked out the RCW with ILDASM and noticed something interesting with the "Value" property:

.property object Value()
{
  .custom instance void [mscorlib]System.Runtime.InteropServices.DispIdAttribute...
  .get instance object xxx._IField::get_Value()
  .set instance void xxx._IField::set_Value(object)
  .other instance void xxx._IField::let_Value(object)
} // end of property _IField::Value

What was that "other" thing? I checked the "let_Value" method with ILDASM and it looked very similar to the "set_Value" method. So I did a Google search and, once again, Mattias Sjogren has the answer:

If your COM interface has both Property Set and Property Let, the imported .NET property will always call the Set accessor, but the Let is imported as a function named let_PropertyName that you can call like any other function.

The Set accessor in VB6 is for object types. Since the data was string (or date, int, long, etc...) I needed to use the VB6 "Let" property. Since the RCW exposed that as a public function, I changed my code to:

nameField.let_Value("Patrick")

And it works like a champ! Kudos to the Interop team for exposing all of this (and Mattias for the explanation!).

Posted by PSteele | 4 comment(s)

.NET Success

Jason Alexander blogs about his success in moving an old ASP site to .NET:

At the end of the day, we cut our server farm in half to a site that is twice as fast, and twice as easy to debug, maintain, and build upon. We saved the business hundreds of thousands of dollars, and will continue to be able to do so because we can offer extremely fast development cycles.
Posted by PSteele | with no comments
More Posts Next page »