The operating system is not presently configured to run this application

After installing Visual Studio 2010, I started getting an error message every now and then when I would try to view the designer in Visual Studio 2008.

The first popup would say:

The operating system is not presently configured to run this application

Which was followed by the message:

Cannot load MSO.dll

I found that mso.dll was located in “C:Program FilesCommon Filesmicrosoft sharedOFFICE12”, and after adding that path to my PATH environment variable in Windows (I’m running XP Pro) the issue seems to have gone away in VS2008.

Marking things as deprecated in VB.Net

If you have some old classes/methods that you can’t get rid off, but you dont’ want anyone to use them for new development, you should mark them as deprecated, which can be done with the Obsolete tag:

<Obsolete("Don't use this class")> _
Public Class Whatever

End Class

This will cause any reference to Whatever to produce a warning.  You can treat these as errors if you want by using one of the other constructors like this:

<Obsolete("Don't use this class", True) > _
Public Class Whatever

End Class

Embedded Images in HTML Emails with .Net

I had looked for a few examples of how to send embedded images in an html email with the .net api, and the first few I found didn’t work.

This code, found on the blog of one Mike Pope, did work however:

Imports System.Net.Mail
Imports System.Net.Mime
Imports System.IO

Dim fromAddress As String = "mike@elsewhere.com"
Dim toAddress As String = "mike@elsewhere.com"
Dim subject As String = "Test EmbeddedImage"
Dim contentId As String = "image1"
Dim path As String = Server.MapPath("~") & ""
Dim filename As String = path & "MyPicture.jpg"
Dim body As String = "Here is a linked resource: <img src=""cid:image1""/>"

Dim mailMessage As New MailMessage(fromAddress, toAddress)
mailMessage.Subject = "Testing embedded image"
Dim av1 As AlternateView
av1 = AlternateView.CreateAlternateViewFromString(body, Nothing, _
    MediaTypeNames.Text.Html)
Dim linkedResource As LinkedResource = New LinkedResource(filename)
linkedResource.ContentId = contentId
linkedResource.ContentType.Name = filename

av1.LinkedResources.Add(linkedResource)
mailMessage.AlternateViews.Add(av1)
mailMessage.IsBodyHtml = True
Dim mailSender As New SmtpClient("smtpHost")
Try
    mailSender.Send(mailMessage)
    labelStatus.Text = "Message sent!"
Catch ex As Exception
    labelStatus.Text = ex.Message
End Try

 

Car Negotiator

My wifes 12 year old Corolla was still running strong, but it was in need of some work and seeing as how we just had our first kid we decided it was probably time to get a new car.

I absolutely hate car shopping.  I hate the fact that you end up wasting so much time at the dealer, the BS pricing tricks, the high pressure sales tactics, the “treating me like I’m an idiot who doesn’t that monthly price is ues, the “let me go talk to my manager” crap, I hate all of it.

So, I decided to try hiring a car negotiator
http://www.nomorehaggling.com/

I had heard Phil Landers on WGN Radio a few years ago, and thought it sounded like a great idea.  I wasn’t in the market for a car at the time, but a few years later when I googled “car negotiator” he was the first in google.

For a fee of $395, Phil made 2 trips out to the dealer with us (one to negotiate the car, and one to pick it up).  He probably spent about 5 hours in total.

I didn’t find any reviews of him online, so I figured I would write this one so anyone in the future searching can feel better about going this route, as I would recommend him to others.

Most people want to know right off the bat, did he earn the money.  Well from a strictly $$ sense on the price of the car, we probably broke even.  On my first trip to the dealer (w/o Phil, when I was just looking) the salesman started right off talking about dealer invoice.  Normally it has been my experience that dealers will start with the sticker price, and then offer you some small amount below that as the first offer.  You then have a major gap between the dealers first offer, and where you think the final price should end up. 

With, Phil we ended up about 500 lower than the dealer offer, or about 500 bucks worth of dealer profit based on their invoice, but several hundred below invoice when you include a cash back deal that was going on.  So strictly on price, I don’t think it is beyond reason that I would have been able to get them to come down 500 from their offer, even if there wasn’t much room for haggling left.

However, if the dealer hadn’t been forthcoming on the first offer, I’m guessing I’d have probably ended up paying more than that. 

The place where Phil really helped (in our deal) was with the other stuff.  The car we had driven 2 days before was already sold, and there was a similar car on the lot, with a slightly less appealing color, and with an extra “protection package” option installed that would have cost us probably 400 more.  I think my wife and I were ready to conceed and just take this car, as the color wasn’t bad, and the cargo tray aspect of the protection package would be nice, even if we were paying too much for that option.  However, before we made this move Phil got the salesman to search the inventory of other local dealers for the color and options we wanted.  I didn’t realized that dealers will swap cars like that w/ no extra charge to the customer. 

Sure enough, a dealer in Schaumburg had the exact color/trim/options we wanted.  So we got exactly the car we wanted, and didn’t end up paying extra for some stuff we didn’t want just because it was on site at the dealer.

They lowballed us on the trade in: 500 bucks.  Phil went to work arguing for us.  The guy came back after “taking another look” they increased their offer by 200%.  Phil told us he thought 1600 was the lowest we should accept, and so their offer of 1500 was pretty close.  Phil made the guy go back to his manager again and he returned with “Split the difference: 1550 and free car washes for life.”  No deal.  It’s 1600 or we take it to carmax (where we already had an offer).  They relented and accepted 1600 for the trade.

When we went back to pickup the car the next day, there had been a mixup and the wrong car was brought in from the other dealer.  It didn’t mean we were getting the wrong car, just that we wouldn’t be driving it home that night.  My wife half jokingly said that they should throw in the cargo tray for free for the mixup.  Phil thought that was a good idea and argued for them to do just that: and they did.

When they told us we could come back the next day to pickup the right car, Phil convinced them to have someone deliver the car to our house, which was nice.  In addition to all this, he got them to give us any dealer installed options at cost, so we ended up getting all season floor mats at 1/2 the asking price.

As we went over all the paperwork, Phil made sure all the paperwork and numbers were legit and make sure we didn’t sign any of the stuff regarding the appearance of the car (which wasn’t there), which they were still trying to get us to sign (duh!).

During the entire process we never had to do any of the talking.  Phil drove the process with the salesmen and we cut through all the crap that you typically expect when buying a new car.

So if you hate the car buying process, and you want to make sure you leave the dealership without getting ripped off, and would rather not deal with any of the headache and stress involved in the car buying process, I’d highly recommend working with a car negotiator and  I’d highly recommend Phil.

 

Preventing Form Resetting

In an application I am creating, I do validation, filtering and ajax saving of values when the user changes something in a textbox.

A problem arrises if the user makes some changes, and then presses the Esc key 2 times.  This causes the form to reset, but it skips all my validation and auto-saving logic.

To prevent this, you can use this little snippet of jQuery javascript:

$(document).ready(
     function() {
         // prevent the esc key from resetting all the textboxes
          $("form").bind("reset", function(e) {
             e.preventDefault();
         });
     }
 );

 

 

Windows 2008 R2 Upgrade Hanging at 62

I was in server hell this weekend, as I was trying to upgrade a machine from 2008 to 2008 R2.

I had more problems than I could even write on this page, but most were unrelated to the actual upgrade itself.

The one thing I wanted to put here was regarding the fact that the update seemed to hang at 62% in the final step.

At one point I walked away and came back like an hour later to find it still at 62%.  I swore a bunch of times and left the computer running while I went back to my laptop to try researching the issue.

I found that there is a known issue in Windows 7 upgrade that causes it to lockup at 62%.  I figured I had something like that happening to me, but thankfully I didn’t pull the plug too early because sometime during the next 30 min or so, it moved to 63%, and soon it was done.

So, if you are upgrading to R2 and you are stuck at 62%, or 63% (63% took a long time too), don’t pull the plug.  Let it sit for another hour. 

Sending Faxes Online

Since we recently dropped AT&T in favor of a $6/month plan from Callcentric.com, I haven’t been able to use my fax machine.

It’s not really suprising, even though it’s SUPPOSED to work, it’s sone of those things where, the fax machine is trying to do digital to analog, and then the VOIP provider is doing analog to digital and this second conversion has an accepted amount of packet loss as part of the equation.

If that amount is above the tolerance level of the 2 communicating fax machines, then it doesn’t work.

So when I needed to send a fax the other day I again when looking for a simple online solution for a 1 time user like myself and I think I found it:  http://faxzero.com/.

There are tons of place out there that offer fax services online (http://fax.1888usa.com/), and many that offer some kind of free version, but they usually fall into 2 categories: 1) you can send a free fax, but it’s limited to 1-3 pages (I needed to send 4 pages) or 2) you can pay a monthly subscription to get the “pro” version.

FaxZero has the free version (lmiit 3 pages) but they also have a $2 option that you can use to send up to 15 pages (and no ad cover letter).

Perfect!  I uploaded my PDF, paid 2 bucks, got a confirmation message in my inbox.  Just what I wanted.

Customizing Style of RadGrid Edit Items

A developer wanted to customize his “edit” form with a telerik rad grid, and we found it less than simple to change the textboxes and other edit controls to make them more narrow, and/or other customizations.

 

I did some research and came across a few different technique for doing this that I am going to share with everyone.

 

Template Columns

The first option, which is the one he used because it is the easiest, is to convert your columns to “template columns.”  Converting columns changes:

 

<telerik:GridBoundColumn DataField=”EmployeeEmail” DataType=”System.Int32″ HeaderText=”EmployeeEmail”

SortExpression=”EmployeeEmail” UniqueName=”EmployeeEmail” />

 

To this:

 

<telerik:GridTemplateColumn DataField=”EmployeeEmail”

    HeaderText=”EmployeeEmail” SortExpression=”EmployeeEmail”

    UniqueName=”EmployeeEmail”>

    <EditItemTemplate>

        <asp:TextBox ID=”EmployeeEmailTextBox” runat=”server”

            Text=’<%# Bind(“EmployeeEmail”) %>‘></asp:TextBox>

    </EditItemTemplate>

    <ItemTemplate>

        <asp:Label ID=”EmployeeEmailLabel” runat=”server”

            Text=’<%# Eval(“EmployeeEmail”) %>‘></asp:Label>

    </ItemTemplate>

</telerik:GridTemplateColumn>

 

 

As you can see, this gives you control over the actual textbox item that will be displayed when you are in edit mode.

 

But using template columns can also be a bit of a pain, because you losing some of the simplicity that you had before when you simply allowed the rad grid to deal with the details of the display/edit cell items.  This also complicates things when you try to do anything in the ItemDataBound or ItemCreated events on the rad grid.  You can’t just grab the column, you have to dig deeper, looking for the contained child controls to find your actual edit control.

 

ItemDataBound

 

    Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound

        If TypeOf e.Item Is GridEditableItem And e.Item.IsInEditMode Then

            Dim editItem As GridEditableItem = e.Item

            If TypeOf editItem.Item(“EmployeeId”).Controls(0) Is TextBox Then

                CType(editItem.Item(“EmployeeId”).Controls(0), TextBox).Width = 30

            End If

        End If

    End Sub

 

 

In this example, I am setting the width of the EmployeeId textbox to only 30px.

 

 

CreateColumnEditor

 

    Protected Sub RadGrid1_CreateColumnEditor(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCreateColumnEditorEventArgs) Handles RadGrid1.CreateColumnEditor

        If TypeOf e.ColumnEditor Is GridTextBoxColumnEditor Then

            If e.Column.UniqueName = “FirstName” Then

                CType(e.ColumnEditor, GridTextBoxColumnEditor).TextBoxStyle.Width = 30

                CType(e.ColumnEditor, GridTextBoxColumnEditor).TextBoxControl.Style.Add(“text-align”, “right”)

            End If

        End If

    End Sub

 

 

I believe this event is fired when the grid is creating the edit columns.  You hook into this event, and then modify the textboxstyle in order to change the look of the edit control.

 

 

Defined Column Editor

 

You can achieve the same results as in CreateColumnEditor without writing any code if you drop a GridTextBoxColumnEditor on your page (outside of the RadGrid) like so:

 

<telerik:GridTextBoxColumnEditor ID=”GridTextBoxColumnEditor1″ runat=”server”>

    <TextBoxStyle Width=”50px” />

</telerik:GridTextBoxColumnEditor>

 

And then in your column you specify the ID of the editor you want to use, like this:

 

<telerik:GridBoundColumn DataField=”UserId” DataType=”System.Int32″ HeaderText=”UserId” ColumnEditorID=”GridTextBoxColumnEditor1

    SortExpression=”UserId” UniqueName=”UserId”>

</telerik:GridBoundColumn>

 

 

 

 

CSLA and the watch window

One of my biggest complaints about using CSLA has been the issue of Visual Studio’s failure to work correctly in the watch window with CSLA objects. 

I wrote a post a while back about my issues:

So for example I have a simple list called “projects” which is of type ProjectList containing ProjectListItems.

If I put “projects” in the watch window, for Value I get:

“Count = {System.TypeLoadException}”

If I put “projects(0)” in the watch window, I get:

{“The generic type ‘System.Collections.ObjectModel.Collection`1’ was used with the wrong number of generic arguments in assembly ‘mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’.” : “System.Collections.ObjectModel.Collection`1”}

Rocky’s response was:

This is a known issue. I’ve actually talked to the VS debugger team about this, and they didn’t have a satisfactory answer – and certainly not a solution. This issue has existed since 2005 when generics were introduced into .NET.

Well, after doing some digging I think I have come across a few work arounds.

If I were to use the Watch Window and put:

projects.Count

it would throw an error.  But if I put:

projects.Count.ToString

then I get the correct result.

Also when picking a specific item:

projects.Item(2)

I get the same exception.  However, if I use:

CType(projects.Item(2),Object)

I get the object as expected!

I hope this helps out others as this is really important when debugging an application.

 

CSLA Validation AmbiguousMatchException

Ran into this error today:

failed in property IsDeleted —> System.Reflection.AmbiguousMatchException: Ambiguous match found. at System.RuntimeType.GetPropertyImpl

I knew that we happened to have a property on our class called IsDeleted that shadowed a property in the CSLA base class, but I didn’t think it should be running into this problem.

After tracking down some reference info here http://msdn.microsoft.com/en-us/library/zy0d4103.aspx I found otu that the issue isn’t that we are shadowing, it’s that we are shadowing while at the same time changing the type. 

The documentation seems to indicate that both situations should fail, but in my tests, the only time I got the exception was when my shadowing property had a different type.  In this case, we were using a Nullable(of boolean) while the CSLA element was just a plain old Boolean.

I guess we are going to rename our property to make things easy on ourselves, but seeing as how this is codegenerated, it’s a little more of a pain than you might think.  But, oh well.

Here is some code that produces the error.  If you change the 2nd property type to a string it works ok.

imports Microsoft.VisualBasic
imports System
Imports System.Collections.Generic

public module MyModule
    sub Main
        dim target as new baseclass
        
        dim p as system.Reflection.PropertyInfo  = target.GetType().GetProperty("Prop")
        
        wl( p.GetValue(target, nothing))

        
        RL()
    end sub

    #region "Helper methods"

    sub WL(text as object)
        Console.WriteLine(text)
    end sub

    sub WL(text as object, paramarray args as object())
        Console.WriteLine(text.ToString(), args)
    end sub
        
    sub RL()
        Console.ReadLine()
    end sub
    
    sub Break()
        System.Diagnostics.Debugger.Break()
    end sub

    #end region

end module

public class BaseBaseClass
    public readonly property Prop as string
    get
    return "BaseBaseClass"
    end get
    end property
end class

public class BaseClass
inherits BaseBaseClass

    public readonly property Prop as integer
    get
    return 123
    end get
    end property

end class