Sunday, June 28, 2009

Things I hate about my Mac

It's not quite a year since I moved to Mac. My reasoning was simple. A Mac IS a PC, so I'm not choosing either/or, I am saying, I will buy a PC, will I also choose to have a Mac at the same time ? My Mac has 20 gig of RAM and 8 cores. It's a pretty sweet box. I generally love using the Mac, too, there just seems to be little things where the OS seems to work with you, instead of against you.

The whole point of my blog is to point out things that I've found to not work as I'd expect, in all aspects of my computing life, especially where I know the solution, and hopefully I can feature in the search results of people trying to solve the same problems I have solved. What I'm basically writing about today, is VMWare Fusion and Boot Camp. VMWare Fusion is a piece of software that lets me install virtual machines on my Mac, and to basically run OSX and have windows running in a window. This is how I've used my Mac for most of it's life, which means I can use Safari, Pages, XCode, etc. as needed, but still go over to Windows when I need to write some Windows code, open a newer format Office file, etc. This has not been without issue, VMWare loses it's internet connection frequently, and while I've been given step by step instructions for what to type into the console to reset it, I am new enough to Mac that I am still working my way up to power userhood, I don't fully follow what it is that I'm doing, so I needed to keep looking it up. The support also takes the form of a public forum and it took me a while to work out that the people who were incredibly rude to me ( I assume for being a Windows user ), were actually not employees of VMWare. This made me feel better, because I know some people who work at VMWare, and I've found them to be really great folks, in real life. I must say, the guy who told me how to get around the internet dropout issue, also did not work for VMWare.

The main reason I use VMWare and not Parallels, is that the question I asked when buying was "who has the best 3D support ?". As my apps are all WPF, I need good DirectX support. VMWare also works with Boot Camp drives, so I had tried to set up a boot camp partition in the past, but had failed in my efforts to do so, so I had kept using an old PC for final testing, 3D was definitely sluggish under VMWare.

As I was going to the US in May, I took my Mac in to the Mac store, and told them I'd buy a hard drive from them, if they set up Boot Camp for me with Windows XP. I made clear that I am well capable of doing such things, given the time to work it out, but my one attempt at Boot Camp had not worked out, and I plain do not have the time to dedicate a day to making this thing work. While I was away, I emailed to check progress, they told me the XP CD I had given them was broken. I assured them this was not the case, and gave them some suggestions ( they claimed the CD was not booting ).

I got back, and picked up my Mac. When I tried to start it, it would tell me that there was no bootable media. As you can imagine, this upset me. Now, all my source code is backed up off site, but it's invariably the case, even with a Time Machine, that some data is lost when a HDD dies. To cut a long story short, my Mac was returned to me in a state where it kept trying to boot from my Windows CD, and would not boot from anything else. Once I worked this out, I found that the machine would indeed claim that my boot CD was corrupt.

I managed to convince the Mac to boot back to OSX ( I confess I don't recall how, this took place over 2 days and was a whole lot of stress ). So, I reformatted my new hard drive, and tried to install again. Same error. I verified the CD again. Fast forward a few hours of me doing this, and variations on the theme, and we get to my first point. I had asked the Mac store to create three partitions, I hoped to create a multi boot hard drive that booted XP ( for my day to day life ), Vista ( for testing only ) and Windows 7. It turns out that you can only install an OS for Boot Camp, on a drive that has only one partition. Once I formatted with one partition, the whole process worked effortlessly, with the CD I had given the Mac store. I called them and explained all this, for the benefit of the next person to walk through their doors and ask for some help.

So, I next tried to repartition my drive after windows was installed. This utterly broke my machine again, and I had to reinstall Windows again. For a time, my Windows would boot, but I could not recover the space I had moved to other partitions. At the same time, Acronis True Image could no longer back up my drives, as it could not recognise them. I wrote to their tech support, and they responded to say 'We understand you cannot back up from your drives. If this is true, let us know and we will mark this issue as closed'. I sent an angry reply, and by the time they followed up two weeks later, I had moved to Ghost, which is a great piece of software, and which worked when True Image would not. So, my second point is, buy Ghost, not True Image.

Apparently, the Boot Camp instructions tell you to never use repartitioning software, this was the point at which I realised that what I asked the Apple people to do for me, and they agreed, was in fact utterly impossible. Of course, I've heard these people tell prospective clients that Macs never have viruses, so I should have known better than to think they were experts.

I tend to update my Mac once every few months, I don't really keep track of when things come out, I just update as I think of it. So, I recently ran the update, and got told that there was an OSX update. I installed this, and then found that VMWare no longer worked, I would start a WPF app and immediately be told that the 3D was broken. It turns out that ATI video cards combined with the new OSX update, doesn't work with VMWAre. VMWare say that they knew this was the case in advance ( but chose not to email their clients to tell us ), and that they blame ATI and Apple ( despite Parallels apparently working fine with this update ). I've followed up on this on the VMWare forums, as far as I can tell, no VMWare employee has responded to me, but some guy who likes to insult me has basically blamed ATI and said that I should never install any update without doing a full system backup first. This is probably good advice. I just didn't see it coming that VMWare was so fragile, or that they wouldn't bother to tell their clients that their system is about to break.

So, my days of running Windows and Mac at once are over for now. I also found that running a Boot Camp partition in VMWare is not wise, it seemed to mess it up a bit, in fact, at one stage, my XP was so confused, that it would just reboot over and over, it took three hours of going between safe mode and normal to get my PC back. I would love to set up a shared drive to put data on, that is visible to boot camp and VMWare, once this ATI issue is resolved. I am assuming when it is fixed, they won't bother to email their clients to tell them. I suspect that the end result will be that I'll fall out of love with VMWare, get used to using boot camp, and just not use VMWare again. Which is a shame, it was very cool when it worked.

Tuesday, June 23, 2009

Changing tables in SQL Server 2008/good UI design


I was using SQL Server 2008 client tools to make some database changes today ( you'll recall, if I install SS 2005, it reports success, but does not install client tools ). I usually prefer to create tables in script, so I can easily execute the script again when I deploy, but this was a simple one, and I figured I'd just use the table designer. I created my table, saved it, and realised I missed a column, so I went ahead and modified the table. Set up my column, hit save, and got the following dialog:

So, an empty table, and the program feels I need to be told that I can't change it, because it would require dropping the table. I don't see that this is even true, can't I add a column using SQL, so long as I provide a default value ( or the table is empty ), and there's no need for the DB to drop the table and recreate it ?

Assuming for a moment that I did have data in the table, and this action WOULD cause me to lose data, why not ASK me before proceeding, instead of locking me out ? And, if I need to change a preference, why not provide a way to open the preferences in the right section ? I NEVER tell a user in my software that they need to set a preference to do what they requested, without opening the preferences on the right page, to show them where it is.

I guess this tells me what I knew all along. Never use the tools, always hand write code, it's the only thing that you can trust.

ASP.NET custom validators do not fire

An ASP.NET custom validator allows you to perform ( not surprisingly ) custom validation on user input. In theory, you can specify both a client and a server side function to call.

I have three checkboxes, they are not generated by a checkboxlist, because I want more control over their layout, AND I want to attach some js events on specific options. So, I created a custom validator like this:

<asp:customvalidator runat="server" id="selectOne" controltovalidate="address1" clientvalidationfunction="IsOneSelected" onservervalidate="CheckSelection" errormessage="*" text="*" display="Static">

Note that address1 is not one of my checkboxes, the custom validator will not allow me to validate a checkbox. I've tried removing this property, because some blogs I've read, suggest this. Then I write a validator method like this:

function IsOneSelected(source, args)
{
alert("got here");

var valid = false;

var demo = document.getElementById(demoCD);
if (demo)
{
var Trial = document.getElementById(trial);
if (Trial)
{
var Webinar = document.getElementById(webinar);
if (Webinar)
{
if (Webinar.checked) valid = true;
if (Trial.checked) valid = true;
if (demo.checked) valid = true;
}
}
}
args.isValid = valid;
}

The alert is obviously a temporary measure. Apparently, the js editor has support for enforced bracing standards, and it defaults to K&R braces, so I kept getting this:

function MyFunc(){

}

I hate that, but I can't be bothered finding it to turn it off ( as you can probably tell, I don't write js that often ). What worried me more was that my script block changed itself from language="javascript" to language="jscript". But, I digress.

It turns out that the client side event only fires if the control you are validating has been changed. So, in theory if I hook up the control to a textbox that needs to be filled, that textboxes validator will help out if it's not, otherwise, this one will fire and I'll get my validation on the client side, right ? Well, I get my alert, but even if I hard code the validator to ALWAYS fail, the postback always occurs, my validator never stops a postback.

Now for the fun bit. MS apparently respond to complaint about this by pointing out that validation should always occur on the server, so even if the client side fire fails, there should always be a server side that fires. I agree with this, although in our case, there's nothing malicious anyone could do by circumventing the validators, it's still good practice not to trust anything that has been on the client side. Here's the issue. No matter what I do, I can *never* get my server side validator to fire. It simply does not work.

Now, I have run the examples that are on MSDN, and they obviously work. There is something else going on here, some reason why it won't work in my page. I guess I could trawl through the script, and see what that reason is ( actually, this gives me a good excuse to install firebug ), but I don't have time, I will just add an OnClientClick to my submit button and do my validation there. If anyone knows either what I did wrong ( possible, obviously ), or what circumstances cause a custom validator to do nothing, even when it fires, please let me know.

Update - Wow. My OnClientClick does not fire, either. Only the server side click event will fire, looks like that is my only option for validation.

Further Update - Although I did initially try to make the validator part of my validation group, I suspect my use of validation groups is part of the problem. However, that does not explain why my OnClientClick event would not fire.

WPF crashes on XP when using MediaElement

The MediaElement has been the bane of my life for some time now. In our first release, we actually used the Windows Media Player in a dll, because we had issues with performance. I did ask about this many times on MSDN forums and never got a real answer. A lot of other people were asking, too, so let me answer that question: even when you're playing a video in a form that has no real 3D, you're still creating a video on a DirectX surface, because that's how WPF works. So, it's not surprising really when a MediaElement is not as smooth as Windows Media Player, which just throws frames at the screen. The resolution of a DVD is around 800 x 600, (although HD is bigger, so is your LCD TV bigger than the average monitor), if your video is much bigger, remember that doubling the width of your video ( so if you go 1600 x 1200 ), gives you four times as many pixels that need to be scaled and drawn. It took me a while to work this out, but once I got our videos rendered in a sensible resolution, they play just fine in the media element ( I did a project where playing one video was unreliable, because of high resolution, I didn't generate the videos, and when I checked the resolution, it all made sense ).

I use a Mac ( I need to post about Boot Camp, actually ). As a result, I probably rebuild my Windows more often than most, as it's easy to build a new VM without even touching the old one. As a result, I have more experience than most with the fact that if you install Windows XP, SP2, and then install .NET 3.5 and run a WPF app that has a media element in it, one of several things will happen:

1 - The app will blow up on start, with a message that the XAML is invalid
2 - If you try to show still images on the MediaElement, it just won't do anything at all.

It seems to me that if I install a framework, it should work from there. It also seems to me like if I need to install a specific extra component, that I could get a meaningful error message to tell me what is going on. The first time this happened to me, I spent a half day trying to work out why my code was broken. I don't believe that winforms ever had this sort of issue. I presume there's a reason why WPF requires WMP10, but if that's true, why can't it try to tell me ? I can see how Microsoft has had legal trouble for bundling stuff in the past, but I am either going to install WMP10, or I am going to not use the application I just bought ( assuming now I am an end user ). How does making it confusing, help anyone ? What if the install for WMP10 fails somehow ( remembering my post the other day on installers ) ? This is just going to cause work and headache for support staff, and general frustration for end users.

Of course, it works fine out of the box in Vista. The only downside is, then you're using Vista.

Saturday, June 20, 2009

Visual Studio has encountered a breakpoint....

OK, this one is new to me. I had selected a solution from the MRU, to open, and I got this error:


Clicking debug, indeed goes into the debugger, after telling me it's loading a ton of symbols, it tells me ( not surprisingly ) that it has no symbols for the code from within the IDE that has crashed. Has anyone seen this before ? I thought I'd seen it all, but this is news to me.

Editing XAML crashes the editor

Today I am playing with some personal stuff, just looking to improve my WPF skills. I found out this week that if you restyle a slider, you need to remember to put in the XAML for the areas you click outside the slider, to change your selection. However, I have a file with a styled slider, and because of the effect I want ( I have buttons in the background and I want to be able to click them ), I want to remove those areas from this particular style. EVERY time I open my XAML and delete the one that is below the slider, VS 2008 uses 13% of my processor ( always 13% ) and it locks up until I kill it. I am going to have to edit my XAML in notepad and then reopen the project.

And, that worked fine. The editor couldn't handle me removing some XAML ( as in, I select it, and remove it, the XML is valid before, and after the operation ) and it locks the editor every time. Remove the XAML in notepad, and reopen the project, it opens fine. So, my XAML was legible to the IDE before the operation, and also afterwards. I am assuming that some sort of control tree is maintained from the XAML to generate the preview, and that this somehow doesn't like having to deal with this ( invisible ) element being removed.

I believe Blend is less hostile to the idea of people hand editing XAML than it used to be ( the first versions I saw didn't even support searching in text, which was by design, because you were not supposed to use it if you wanted to edit code ). I am falling in love with Expression Design's ability to open an Adobe Illustrator file and let me export XAML. It often fails, but what it does is impressive enough that I am happy to fiddle with it to make it work. I still worry that the theory that Blend is what you use to create XAML, may be a reason that the tools in VS 2008 are still so poor, tho.

Update: This is the first project where I've used resources, I don't know if this is a factor, but I am finding more and more simple edits which kill the IDE and which therefore need to be done in notepad. How is this possible ? Surely the thing would be, if the control tree can't take the edit, just rebuild it. I am changing my resources file, so the IDE is not even rendering any sort of preview at the time.

Friday, June 19, 2009

ASP.NET traps for young players

No other area of programming seems to have as many inexperienced, beginner 'programmers' taking on contract tasks that they have no idea how to perform, than ASP.NET. I guess everyone wants a cheap website. There's a few ways that the framework does not help.

When you create a default page, it will have a page load event in it. As a result, a lot of people write all their code in the page load event, and never add a page prerender event. Because of the order of the page lifecycle ( that is, page load, then events fire, then page prerender ), the prerender is often the only event you really need to handle, and it's the one that any data bound page should handle. This leads to several issues.

First is the "I push a button and it doesn't work, I push it again and it does" scenario. This means they bound to a data source, then the event changed the data source, so, on refresh, the changed source is loaded and bound to, but the first time, the data was loaded before it was changed. Then there's the 'my control loses it's selected value' problem ( which should ideally be fixed with a !IsPostback block, but would also be fixed in terms of reading the value in code behind by reading the value first, then data binding ).

The next thing I don't understand is, if I write a site in VS, and use the built in web server, it will allow me to write code behind like this:

if (!someTest())
{
MessageBox.Show("The test failed, please open a file");
OpenFileDialog ofd = new OpenFileDialog();
ofd.ShowDialog();
}

This apparently WORKS in Visual Studio. So, every day, when people in a certain continent clock in for work, programming forums worldwide get the 'This works on my local machine, but when I deploy it, it gives me this error on the server, what does it mean ?' question. Now, it's true that this is a problem with the so-called programmer, and it's true that the error message explains the issue in plain English, but, as far as I can see, the MVP program exists to give people incentive to provide Microsoft tech support by answering these sort of questions, so I assume that having these people write code is part of Microsoft's business model. I am guessing they skim the cream of the programmers in these low wage countries for their own benefit, I don't know. Either way, why would you create an IDE that allows you to write code that is plainly not going to run on deployment, under any circumstances ?

And don't get me started on how AJAX fits into this mix. Most people using the ASP.NET AJAX library, both think it IS AJAX, and think that Microsoft invented AJAX. They certainly have no idea what AJAX is, or what it means, I see questions every day that say 'I want to use AJAX to do xxx', where xxx has nothing to do with AJAX, although it may involve javascript. It's become the new XML, if you write a website, you need to use AJAX, where-ever you can. As the AJAX library does include some controls that don't really need AJAX to exist, the line is blurred even further. The ASP.NET AJAX library is also horribly inefficient, when I worked on a website in ASP.NET that used AJAX, I rolled my own code, because our site had far too much traffic to pay the price of the library. I am glad, because it means I was able to learn how to hand code AJAX, and I believe anyone who uses a library, should have some idea of what it does, so they know what performance cost is associated with their actions.

Of course, in .NET, it's not deemed important to even make the decision between a vector or a list, so I guess performance doesn't matter nowadays.....