August 2004 - Posts

If you run as a least privilege user account, you will have probably noticed you generally can’t install software (other than xcopy deployment).  Don wrote about his experience of this recently, and I had exactly the same happen to me last week when I installed ActiveSync. Unfortunately the story with ActiveSync is a bit more nasty than most well behaved applications.

First you don’t get prompted to run the app, nope it just starts.  So if you ran the installer as Admin, ActiveSync runs as Admin, and next thing you know your pocket PC is syncing with your Admin account not your account (or at least trying to )  Worse, to kill that process you have to use Task Manager !

Software that wants to automatically run after install, really can’t do much about this. Even if it could attempt to work out which is the main UI identitiy, it would be fraught with “guessing” what your intentions are. 

The best approach is to NOT use RunAs to run the Admin account to install software. Either log out and log in as Admin, or elevate your own permission to Administrator for the installation process (note: you can do this per “process” !!).  The later is the way to do it in my books.  To find out more about the “MakeMeAdmin”, see Aaron Margosis' blog.

with 2 comment(s)
Filed under:

MSDN DVD’s really rock, except they have a habit of removing stuff. So when you update the DVD’s you really need to look at what has been removed each month.  Problem is on the August DVD’s the search for new and removed products only includes up till July L

This sux !!

You can use the web search at msdn.microsoft.com/subscriptions/ in the meanwhile as that does have August contents included.

Let’s hope this was just an oversight, not a sign of things to come.

BTW: I really wish they would send out a quarterly or six monthly “Archive” set of things removed.  For example, Resource Editor for VB6.

with 1 comment(s)
Filed under:

After updating to XP SP2, I noticed I had “issues” when trying to open some hyperlinks from Outlook.  No big deal I thought as I actually got prompted to select the exe file for the hyperlink, so I selected IE and all seemed fine …  until today that is ..

Today I went to open a .htm file from a CD.  First, the Open command initiated the Open With dialog.  Okay I thought, I’ll just choose IE again.  But try as I may, after selecting IE, the Open With dialog would select Notepad.

Next, I ran explorer as Administrator to see if it was a problem with just my user account, but no, when run as Administrator I had the same problem.  So I brought up the file associations dialog, and found that the default for .htm files was the “Open” command which had IE set to open using DDE  (funny how Microsoft doesn’t support DDE in .NET, yet their own apps use it hey ???)

No, the issue was not DDE, it was the file name !!  The path to internet explorer was correct, but there was an extra space after the .exe and before the closing ”.

The fix :

Change:

“C:\Program Files\Internet Explorer\iexplore.exe ”
to
“C:\Program Files\Internet Explorer\iexplore.exe”

with 1 comment(s)
Filed under:

Windows.Forms in Whidbey includes a new design time property you can set on controls.  This property is named GenerateMember.  Set it to False, and instead of the usual field generated for the control, it only gets declared inside the InitializeComponent method.  So this un-clutters your object’s fields.  You can still reference the object but you would have to iterate through it’s container object’s Controls collection.
Interestingly enough you can still hook up events for the control via the designer, and the AddHandler code is also added inside the InitializeComponent method.

For VB.NET this is a departure from the generated Property that is created for each WithEvents variable.

The good thing about this is the clutter removal.  For static labels, you really don’t need them as fields.  So this is kind of cool …

But …

Yes, I know, you were waiting for the criticism right ?  Well yep, this again is one of those so close but yet so far kind of implementations.  It’s great being there, but why can’t I set defaults for each control ?  I mean really, why doesn’t winforms use best practices and read defaults from a config file ? ;)

I would really like a config file where I can add a control to it specified by type, and set the default for members like this.  For example I would add
<control name=”System.Windows.Forms.Label”>
    <GenerateMember=False>
    <DefaultPrefix=”lbl”>
    <Accessibility=”Private”>
</control>
   
Really, how hard is it for these designers to read config files and if the type is in there, use those settings as default ? 
Hey, if I say Mark Boulter three times really loud do you think that will invoke him on this thread ???

Seriously, just that little extra can make a HUGE difference in productivity.


 

with 1 comment(s)
Filed under: , ,

(Setting WithEvents to Nothing)

Under the covers, Events use Delegates, and Delegates store a reference to the object in which the method address resides. (Sender property of Delegate).

One major problem with this, is if you have shared components or components with shared internal components (e.g. an instance object that use an internal factory for monitoring events on an application basis).  In this case the component can be kept alive after the form it was in closes, and in fact the component can keep the form alive as it has a reference to it.

This problem applies to both C# and VB.NET.  In fact it is a problem each language needs to address.  VB.NET is well designed for declarative event wiring, using clean property sets and gets to wire and unwire events.   However it fails to utilize that.  Ideally VB.NET should create an UnWire method, and in that method set every WithEvents variable to nothing.  The UnWire would be called from the Dispose method.

This pattern would allow safe removal of any hanging circular references that may be rooted via shared components.  Furthermore, it would allow components that use an internal factory pattern to monitor the remove handler to determine when to release expensive resources.

This is a simple addition to the “code spit” VB.NET does and would not impact performance.  It would help ensure memory is cleaned up properly.

with 1 comment(s)
Filed under: , ,

Great to see Paul has blogged about Custom events being added to VB.NET.  Not that I am biased at all, but it seems that VB has done this better than the C# team, and has included the Raise method, which transposes to the IL fire method as is associated with Custom events.  So this is all very cool, adds some new powerful functionality to VB.  However there is still room for improvement, IMO.

The approach VB.NET has taken is somewhere between baby steps and catch up football (talked about mixed metaphors ).  I think VB.Net has just looked at what C# has had, looked at what the IL specifications allow for, and basically gone with the more functional IL specification.  That’s great, but it just doesn’t feel or look like they looked at the whole picture.

The first embarrassment is the clumsy approach one has to take when actually working with the delegates.  Paul’s blog shows a good example of the Delegate.Combine calls needed to be used along with casting.  A holistic approach would have included simplified syntax to complete that story.

But, in my eyes, the whole custom event need is overly complex for what is usually just a combination of what should be high level language concepts//constructs.  To understand what I am ranting about here, it’s probably best if we look at the *WHY* we use custom events.  The reasons are typically

  1.  Storage optimization
  2.  Serialization
  3.  Asynchronous events
  4.  Exception handling
  5.  Other action when a delegate is added or removed

Really, the only time you should have to use custom events is case 5 above. For the other patterns, the language should do this menial coding for you.

1. Storage Optimization.  Paul provides a good example of this, and this is as is used by WinForms.  WinForms however uses a linked list as storage as the reason for the optimization is that there is a belief that usually only a few events will be handled.  So a small linked list performs well. A dictionary is probably more suited to a large list, in which case the optimization is not going to be worth the effort, as there will be penalties each time a handler is added/removed and a penalty each time an event is fired.  That is, unless the ratio of events to handled event is very high, you end up loosing on the swings anything you made up on the merry-go-round ;)
Still this is a simple pattern that should not require every developer to write all that code each time they want to use it

2. Serialization.  Rocky gives a good explanation of this technique.  Basically if you have objects that are based on MarshalByRef, you can’t serialize your object, unless you eliminate the event field from being serialized.  So you need to store some those delegates in a non serialized field.  See Rocky’s modified Custom event code here.
Note: Rocky decided to serialize those event delegates that could be serialized, and not serialize those that were MarshalByRef.   Another approach is to not separate the lists, instead not serialize any of the delegates.  Which you choose will depend on your architecture.

3. Asynchronous Events.  For this pattern you just iterate the invocation list and raise each event on a separate thread.

4. Exception handling.  One thing about raising events a lot of people don’t realize is that if any handler throws an unhandled exception, that will stop any other event handlers for that event getting notified.  Custom events allow you to code around this by getting the invocation list and wrap each invoke inside a Try Catch block.

5. Taking an action when an event handler is added or removed.  This pattern is useful if you have an expensive resource you only want to monitor if a consumer of your component//class wants event notification.  A simple example might be directory monitoring.  There would be no need to be monitoring a directory for changes unless there is a subscriber to your event. 


Of the above, as I mentioned before, only the last case scenario is the one I believe you should have to write code for.  All the other cases are really mundane code that the compiler should spit out for you.
Hopefully next version around, VB.Net will look at this and remove the need for all that typing ;)  My suggestion would be a CustomEvent attribute(s) or modifiers.  Eg:

 

<CustomEvent(StorageOptimize:=True, _
             Serialization:=None,  _
             Asyncronous=True,  _
             CatchExceptions=True)> _
Public Event Foo As EventHandler

 

Simple code like that which would apply those common four patterns, or any combination of them.  Most of those are simple Boolean switches, except the serialization one which would be, None, All, or NoMarshalByRef.

This isn’t rocket science, and the onus should not be on the VB developer to write all this repedative code, for what is well defined scenarios.  The whole concept of RAD is to remove that un-necessary glue code, and instead generate it for us.

 

 


 

with 2 comment(s)
Filed under: , ,

In case you didn’t see it already, Paul Vick has asked people what they would like to see in the language post Whidbey.  Anders has been talking some on channel 9 about the kind of things C# might be looking at.  Hopefully Paul and Amanda (blogless) might get some white board stuff happening on channel 9 too.  Something about whiteboards, they allows us to convey new ideas really well, IMO .

So far though, if this is the “futures” market, then my money is on YagJ I think that’s what we really need is a unified approach on the big picture items across VB and C#. 

What I don’t want to see is stuff like the C# team promoting things and the VB.NET team not talking about them.  Take for example generics. For ages everyone thought that was only a C# thing, yet reality was it came out of work on rotor research and was not a language specific item. Yet the C# team got in early and a lot of folk thought it was. 

Anyway … onto the big picture items ….

Well I look at what we do, and a lot of it is fetching data, displaying it, and then saving it.  And somewhere amongst that, manipulating it. Data at present is either late bound, or comes in the form of classes and typed datasets. The late bound uses is often with xml. So I think it would be nice if there was a simplified syntax, a native XML support.  A bit like how VB has the ! syntax.   And the ability to then have an Imports like statement for an XSD and have those strings validated.

Set operations would then be the next big thing.  The ability to create dynamic filters for selecting and sorting objects as well as datasets, and even in memory xml nodes. That is, bringing the concepts of SQL to objects and xml and removed from SQL ;)

On the binding, I am in two minds whether we need new code constructs for that.  Is binding an operation or a method? I think it’s a method. So I would rather see work go into the visuals for binding…. that nice drag and drop feeling.

And that’s where I would like to see some big picture additions. More designers, more of the white horse.  I would like to see a designer that has tiny screen shots of all a winforms application forms, and be able to draw relations between forms, visually set the start up form, the lifetime model, and interaction between forms.  Like let’s say I set an action item on a form to open another form. The designer would draw a line representing the information flow based on the action. And if I could then drag and drop fields or properties from my form to indicate the data to be passed to with that action. The result appearing as a package attached to that action arrow.  (I know, I know, I need a whiteboard here ) I would then like to also be able to zoom in/out from the app, wire up relations with the data, drag and drop pattern blocks onto the app surface to add basic features etc.

So I s’psoe what I am saying is I would like to see more “Visual” in Visual Basic J

 


 

with 1 comment(s)
Filed under:

Don Kiely blogged recently about wanting to be able to enable/disable network connections when running as a least privilege user (LPU).  I run as least privilege user on my laptop, and I had added my self to the Network Configuration Operators group.  But as Don pointed out to me, that also allows my account to do things such as modify the DNS settings and RAS properties, neither of which I really want or need. (see KB 297938).  So I quickly opened up Group Policy editor (gpedit.msc) and modified those settings J And just to show that a mere human can do this, here’s a screen shot (click on it the picture for larger view)

click on picture to see full size

You should notice that some of the settings I have as not configured.  These are things that I don’t want to enable for all members of the “users” group, and don’t want to disable them for me.  Group policy is applied last, so it overrides and settings I apply to my user account. So to be able to enable and disable network connections, I have to still add myself to the Network Configuration Operators group, but now I can’t modify the RAS entries to the TCPIP settings etc, which is exactly as I want it J

I was thinking just the other day about how Microsoft pays bounties for information that leads to the successful prosecution of hackers and virus writers.  Although a useful approach it’s a reactive one, not a pro-active one.  And I thought, gee wouldn’t it be better if MS had a reward based scheme for people finding hacks and letting them know. Well looks like the open source people read my mind and also beat MS to the punch.  Linspire and Mozilla now offer a bounty for bugs.

For Microsoft, considering the recent events where it took them something like eight weeks to patch the cross zone exploitation, and nearly a year to decide that ADODB stream was not a safe implementation, then you would think they would try to take a pro-active approach.  Problem is, that would mean Microsoft would have to release the source code.  These days considering all the patents they have in place, hardly seems like there is legitimate reason not too J

But that kind of ideology change in Microsoft would probably take years.  Perhaps a better approach would be if they out-sourced it.  That way they could control who sees the source, while keeping costs down.  They could have the contract bounty based, with both rewards and punishments.   One thing is for sure, Microsoft’s inability to fix internet explorer in a timely manner highlights the need for the ship to change the way it sails.

with no comments
Filed under: