Paul's profileIT BytesBlogListsGuestbook Tools Help

IT Bytes

IT Musings
June 26

Cross Domain Policy file gotcha on a development environment

I hit a little gotcha today when using Silverlight to talk to a Service. My solution has a separate web and wcf projects. So, without thinking, it didn't suprise me that the Silverlight app running in the web site moaned about security when trying to talk to the service (http://projects.nikhilk.net/WebDevHelper is a great add-in for IE if you want to inspect the http requests on a development machine). So I placed a clientaccesspolicy.xml in the service and everything worked fine. Later it struck me that in this instance (for various reasons) the service should actually exist in the web site rather than a separate project. So I moved the service over and didn't bother to move the policy file, after all I will no longer be going cross-domain. So I was initially puzzled as to why I was getting the security faults again. The problem stems from my use of a virtual directory on my dev machine. So my web site is at something like; myBox.myCompany.com/devSite/default.aspx. However, when Silverlight looks for the domain policy it looks for at the root of the domain so; myBox.myCompany.com and unsurprisingly it cannot find the policy file there. So I just had to copy the file to the root of default site and everything was fine.
June 23

MacBook with broken case...fixed!

My little white MacBook has been through the wars...well not really. I look after it very well, so I was very angry with the case started to split apart. Also about the same time the machine would often refuse to go to sleep and would sometimes just switch off with no warning. All of which seemed to be down to the Bluetooth module playing up. Basically it was looking like time for the knackers yard for this little PC. So it was with some interest that a collegue told me that Apple had actually admitted that the case problem was a design fault and would fix it out-of-warranty. So after a long, if polite, conversation with Apple Support (complete with dictating various Forum URLs saying about Apple relenting) they gave me a ticket number and a number to call for repair. When I took it in I asked if they could check that the Bluetooth module was correctly seated. Today I got the Macbook back complete with new case part AND a new bluetooth module, which was nice. So far the machine seems to working as good as new. So for once, thank you Apple for making me feel like you actually care about your customers. Thanks again, keep up the good work.


"Bad class token" when running (N) unit tests with TypeMock

Had a strange problem today, some of the automated build tests were failing with "Bad class token". However, when I went onto the build machine and ran them via NUnit GUI they worked fine. The difference is that we'd normally run the tests via Type Mock to ensure all the mocks work correctly. When I ran NUnit GUI via TypeMock the tests would fail...well actually sometimes they'd work, sometimes they wouldn't. Yes that's a lovely position to be in <gulp>. The obvious cause to these problems was that I'd just upgraded Visual Studio 2008 to SP1. So I manually rebuilt the whole solution and everything seemed to spring back to life again. Odd problem but hopefully now someone else won't have to sit around scratching their head like I had to!
 
[Edit]
I blogged too soon. Turns out I still have the problem, but only with automated builds, if I build by hand (on the build server) then everything runs fine...weird.

[Edit]
Turns out I "just" needed to upgrade TypeMock to the latest version.
 

June 22

How to add a Silverlight project to an existing Web Project

Whenever you play with Silverlight via Visual Studio you soon learn about the link between the Silverlight application and the web site's ClientBin folder. However, what happens if you already have a web site project and want to add a new (or existing) Silverlight project to it? Well you either manually copy the xap over after every build (no thanks) or just go the web site's properties and select the Silverlight tab and add your project to it. Easy...I hope that's not tempting fate.
June 06

How to make Vista shutdown when you press the big “off” button

I finally cracked today and had to find out how to change Vista’s default go-to-sleep when you press what looks like the off icon. I’d dismissed the Power Options because when it talks about the, “power button” it literally means the physical power button. However, if you customize the power options and select advanced you can change it…

image

The button then goes a very dark red.

May 22

nHibernate CreateQuery gotcha

As an nHibernate newbie I wasted a bit of time trying to get the Hibernate Query Language (HQL) CreateQuery function to work for me. Even the simplist query failed to work, e.g. I have a class MyEntity and I wrote something like;
session.CreateQuery("From MyEntity as myEntity")
 
then nHibernate would give me errors such as "in expected", or "uknown token as". I'd read a bit about problems where the mapping may not have been processed yet but that couldn't be the case because I'd previously successfully loaded a MyEntity. However, it did prompt me to ask the SessionFactory for the metadata about MyEntity. What I spotted was the EntityName included, now obviously, the fully qualified name of; MyNamespace.Bla.Yada.MyEntity. Therefore the correct syntax is;
session.CreateQuery("From MyNamespace.Bla.Yada.MyEntity as myEntity")
 
I've yet to find a way to add namespaces to the query but at least the thing works now!
 
 
 
April 30

How to remove items from a bound list box or how to avoid "Operation not supported on read-only collection."

Today I got a rude error message from my application when I attempted to do a very simple operation, that of removing an item from ListBox; "Operation not supported on read-only collection."

The problem stems from the fact that I’d bound my ListBox to an ObservableCollection, once bound the Items collection becomes read-only. A know some others have had the same problem so I thought I’d blog about my solution.  Utilizing a function, I’d previously blogged about, to find the ListBoxItem from a button click I then do a little casting and the item is removed;

private void buttonDelete_Click(object sender, RoutedEventArgs e)

{

    ListBoxItem selectedItem = FindAssociatedListBoxItem(sender);

 

    // if we have found an item then remove it

    if (selectedItem != null)

    {               

        MyColl myColl = this.ListBoxProducts.ItemsSource as MyColl;

        MyObject selectedObj = selectedItem.DataContext as MyObject;

        myColl.Remove(selectedObj);

    }

}

April 22

WebDD 09 - a quick blog

Last Sat' I attended WebDD 09, here is my brief summary;

What's New In Silverlight 3? - Mike Taulty
Mike is a good speaker and knows his Silverlight onions so I thought this one would be worth attending even if I have read about the majority of the changes. Overall it was a good session and it's good to see live demos of the changes. One of the demo's failed but Mike was determined to provide an answer why and was forthcoming a couple of couple of hours later (and on his blog).

What's good in .NET 4 and Visual Studio 2010 - Alex Mackey
The idea behind this session was to preview the, "new stuff". However, I came away from this session a little disappointed. I was hoping for some insights but what I got was really a summary from publicly available blogs and CTPs. Still it was ok and it's quite a nice idea for someone to collate these remours into one place but to paraphrase Alex, 'I've not looked deeply at X because it's likely to change' so perhaps this session is too early to watch too?

I want it on that one, that one and that one! And it all needs to be synched! - Andrew Westgarth
Andrew presented the deployments options in II7. I was interested to see the Deploy utility, that seems to be an implementation of a Powershell host, and I especially like the idea of easily keeping production and test sites in sync. However, that was really the interesting part of the session and the rest felt like it was just repeating itself. I think this was probably due to the fact that almost all the demos failed and probably took all the momentum out of the session.

An Introduction to jQuery - Andy Gibson
I took a chance on this one since I have been dabbling with jQuery so I should be beyond an introduction now but I thought I might learn something I'd missed. Overall the session was a decent introduction to jQuery, although since I understand it you'd really have to ask someone who was new to jQuery, and it was reassuring to hear some things I'd guessed at rather than knew for certain.  For a WebDD I would have liked to have seen an intermediate/advance session rather than a introduction.

ASP.NET MVC best practices - Sebastien Lambla
Sebastien provided a witty and interesting session on what was wrong with the out-of-the-box MVC framework and how his teams worked around them. I really liked this session even if the demo gods caused a blue-screen and other demo failures. I just felt he could have quickly introduced the Windsor framework as I could see a number of people were confused by its sudden use but that's only a tiny point. Suffice to say that I've added his blog to my reader

ASP.NET 4.0 - Mike Ormond
Mike is a another MS session stalwart and presented a good session on ASP.NET 4. Although all the nice things about ASP.NET Ajax WPF style binding was good to see I felt like shouting hallelujah at the control provided over Client IDs, something I've been campaigning for on forums. For me ASP.NET is a terrible framework but I concede that v4 looks to finally have started to consider professional developers so maybe I'll be enticed back...maybe.



April 21

Parallels Desktop 4 - disappointing

About a month ago I decided to upgrade my Parallels Desktop 3 to 4. I needed to do a fair amount of Windows Development work and 4 was hailed as providing large increases in performances and this, together with a years subscription to anti-virus, was good enough reason to upgrade. Oh dear, unfortunately disk space is a rare on my laptop so I didn't backup my v3 disk and just upgraded to 4 feeling sure I would have no need to go back. 4 is so disappointing;
1. Vista performance - everything about using Vista feels sticky and glitchy whereas before it was absolutely fine.
2. Application performance - launching applications feels slow. Everything seems to run as if there is no concurrency. Launch two applications and you may as read a book before you get any sensible response. V3 was great.
3. Switching back to OSX - this was great in V3, a quick ALT-CMD-ENTER and I was out of full-screen Windows and back to OSX in pretty much an instant. In V4 I struggle to even get back to OSX let alone in a speedy fashion.

Overall I'd give V4 2/10 since it does run the applications but it's pale impression of its older brother. Oh dear, oh dear.

[Edit] - Hopefully I may have found the problem. In the VM configuration is a 'Show Advanced' option, selecting this provided access to the CPU options. For some reason it was set to use only one core from my dual CPU. Selecting this seems to have improved things, I'll update this blog entry should it prove to fix the above problems.



April 13

How to use a button within a List Item

One of the problems with Silverlight is that the templating mechanism is really good but you can quickly get a bit stuck. I ran into one such example when I had created a nice DataTemplate for a ListBoxItem that contained a button. When the button is clicked I wanted a specific action to take place in the context of the containing list box item, i.e. I wanted the list box item to be selected because the user has pressed a button within the item.

<DataTemplate x:Key="MyDataTemplate">

     <Grid>

       <Button Content="Edit" Click="Button_Click" />

     </Grid>

</DataTemplate>

 

The problem is that the Button_Click event will fire but none of the event args will explain which of the potentially many buttons has been pressed. WPF uses tricks such as binding the button’s tag to an ancestor element but SL2 doesn’t (I believe) offer this feature. One solution is to skip the button click event and simulate the button via some mouse down events and event bubbling but that seemed too dirty for me. So I thought I could walk the control tree and find which ListBoxItem the button was within. You have to be a bit careful here because templating/themes can introduce a different logical tree so you must walk the tree looking for a ListBoxItem rather than assuming a specific number of hops. BTW, in theory the ListBoxItem itself may have been “styled” out too so you should degrade gracefully if you can’t find the ListBoxItem.

So I wrote some code to loop and walk the FrameworkElement.Parent properties. This didn’t work since the .Parent returned null at the ContentPresenter boundary, i.e. before the ListBoxItem. Still not sure exactly why that is, but I needed a quick solution so I turned to the Visual tree instead. This proved to be the solution…

private void Button_Click(object sender, RoutedEventArgs e)

{

 

    Button buttonSender = sender as Button;

    // which item is containing the button?

    DependencyObject currentElement = buttonSender;

    ListBoxItem selectedItem = currentElement as ListBoxItem;

    DependencyObject theParent = VisualTreeHelper.GetParent(currentElement);

    while (selectedItem == null && theParent != null)

    {               

        currentElement = theParent;

        selectedItem = theParent as ListBoxItem;

        theParent = VisualTreeHelper.GetParent(currentElement);

    }

 

    // if we have found an item then ensure it is selected

    if (selectedItem != null)

    {

        selectedItem.IsSelected = true;

    }

 

}

 

 

Thanks to Keith Mohoney's Post for the information about the Visual Tree Helper

March 31

Silly gotcha when using sample data in Blend

I was working on a list box project and wanted to use Blend to edit my container styles when I was faced with the age old problem of providing Blend with some useful data. So I created a nice little collection class wrapping my target object and asked Blend to use it as a datasource, ensuring that the collection would initialise itself in its constructor. Hurray I had a nice design view with sample data. However, when I switched back to Visual Studio it complained that the resource xaml containing my datasource definition was invalid, the dreaded AEG error. After a great deal of head scratching I realised that somehow Blend had successfully added an x:Name attribute to the resource but my collection class does not derive from any Element and therefore does not have an x:Name. Once I realised that I (ahem) hacked a quick derive-from-user control onto the collection class and we're up and running again. So watch out, just cause Blend doesn't complain doesn't mean it hasn't generated some dodgy xaml.
March 26

Great talk about ADO Data Services

Just finished watching a really could talk from Mix09 about ADO.NET Data Services. I've been wondering about where the business rules really fit with ADO.NET DataServices and the Entity Framework. This has gone a long way to helping me understand it, I really recommend it.
 
 
 
 
 
March 24

Problems with Win Mobile GPS Sample freezing?

It's been a while since I last used the GPS Sample for managed code provided in the mobile SDK. So I compiled it and added a reference to it in my project confident I'd have GPS data very soon. I added the gps class to a second form, launched the form and yah I had GPS data. However, when I closed the form the application froze/hung. After examing the code I could see where it was going wrong but I wasn't sure why. Essentially the sample create a basic message loop by taking out a lock on itself and going into a loop where is uses Wait For Multiple Objects to get the notifications from the GPS driver. One of the notifications it waits for includes "close". However, the code that issus the close notification then takes out another lock. This should be a good idea because it waits for the lock the loop has got to be given up before it continue cleaning up the component. The problem is that the loop never seems to get the close notification so the application is now stuck waiting for a lock it will never get. Now I'm not a 100% what the problem is but it would seem that it's probably something to do with threads. Therefore I moved the GPS class into the main form and exposed the data to the secondary form. This seems to have done the trick. As I say I don't understand why this is since the loop certainly recieves the notifications about GPS changes so why not the close? Hopefully I'll realise what the problem is soon, but in the meantime at least I seem to have a workaround.
 
March 20

How to read Car number plates in Google Street Maps

Just had a quick play with Google Street Maps and was interested to see how peoples faces and car number plates are automatically blurred. However, what I also noticed is that the blurring only detects such features in the "current" frame. E.g. you see a car and then move towards it, the car is now at a good resolution and the plate is blurred. However, if you move back a step and then use the zoom button you can easily read the plate. So if your car in visible I would recommend you try this trick and then use the report a problem button to ask for it to be blurred (or removed).

March 11

Tip: Virtual PC slow?

I just discovered that when I remote desktop to a machine that is hosting a Virtual PC and try to use the VM from the "player" then the user performance is terrible. You try to move the mouse pointer and it stutters which results in you spending 10mins just to trying to get the mouse-pointer to click a button! Don't despair there is a workaround. Simply enable remote desktop access to the VM and remote desktop directly to the VM. The UI performance is fine, in fact you wouldn't know it was a VM.
 
March 08

Using IIS in Vista to access your Visual Studio web site project

Developing in Vista certainly presents the odd challenge. Recently I've started to develop applications using Live Mesh and I wanted to test out Delegated Authentication which involves running a web site under IIS. Now I'm not used to IIS 7 so after the initial shock of a new UI I setup the required virtual directory and ran my web site. However, I kept getting a rather strange error message;

The requested page cannot be accessed because the related configuration data for the page is invalid.

At first I took that to mean I'd corrupted my web.config file but no that all seemed fine. I eventually tracked down a Test Settings button in IIS. This showed a big warning triangle saying that it couldn’t ensure the site identity would be authorised to access the disk folder. Once I’d set an appropriate user to access the folder everything worked fine.

To access the Test Settings button;

Open IIS->Navigate to your site->Basic Settings (in the right pane)->Test Settings->Click on any line with a warning triangle and read the explanation.

February 27

Visual Studio freezing/crashing with Team System Foundation Server

Finally made the switch from Visual Source Safe to Team System Foundation Server today but as luck would have my machine didn't enjoy the experience. My colleagues machine was running fine, the speed difference in opening a solution or checking in/out was impressive. My machine would just sit there endlessly waiting for the check-in to work until finally I killed it off. It then occurred to me that I hadn't connected to the Foundation Server in my Team Explorer. Once connected everything seems to be running fine. So my tip is, ensure you've connected via Team Explorer before you attempt to use the Source Control.

February 24

RIP IE6, goodbye old friend

To start off I'm not an IE6 hater. Much of what is written today vilifies IE6 but for me it's been a steady, if limited, platform. However, even I concede that it no longer fits the bill. I could second Calling time on IE6 reasons of it's limited CSS support or it's now poor JavaScript performance but the final straw for me is the lack of bug fixes. Sure Microsoft will fix the critical (aka security) issues but anything else it just isn't interested in. E.g. Want to use IIS compression and content-disposition? Yes please, but wait it doesn't reliably work in IE6 :( (Edit: note to Systems Admins, you should move away from IE6 too for the same reasons, the users should have the best experience including decent caching, compression, parsing, rendering and bug fixes - all things IE6 doesn't give you)

So I'm joining throngs of the ivory tower W3Cers and fed up web designers...



Although to balance out the post, Firefox, Safari and Opera can all be royal CSS pains in the....too!


Navigon TMC review

I "recently" purchased a dedicated Navigon SatNav (2100) with TMC as I thought my Pocket PC Navigon software was good if the TMC was a bit of a damp squid. Today I had to go on a fairly long trip around the south-east portion of the M25 and then up the M1 to Scunthorpe. The routing was, as usual, great but since I was the passenger I could keep a watch on the TMC signal. This isn't a very scientific experiment but these are my findings. 

First off the TMC signal was non-existent until we got past Rickmansworth, then we got a good 5 mins worth of signal. Lost it for the majority of the M25 until we got close to the M1. The M1 has a couple of longer signal windows, a couple towards Milton Keynes with the best around Derbyshire. A final little window near Scunthorpe itself. So although the coverage was sparse it was enough to give the unit time to download a reasonable amount of traffic information and it did report problems on the adjoining roads (fortunately nothing bad on the route itself).

So overall the TMC works but only in specific areas, if anyone reading this knows of these zones then please let me know, if you have anecdotal evidence of areas it works then please post a comment and perhaps we can compile a working map.

 
Thanks for visiting!


Please wait...
Sorry, the comment you entered is too long. Please shorten it.
You didn't enter anything. Please try again.
Sorry, we can't add your comment right now. Please try again later.
To add a comment, you need permission from your parent. Ask for permission
Your parent has turned off comments.
Sorry, we can't delete your comment right now. Please try again later.
You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
Complete the security check below to finish leaving your comment.
The characters you type in the security check must match the characters in the picture or audio.