I am currently working on an application where I want to have a search feature that allows people to search for businesses within a certain distance of their home (or anywhere else they care to choose). I have some old UK postcode data knocking around, and was going to use that. For those not familiar with them, UK postcodes are made up of two parts, a major (also known as â€œoutwardâ€) part, and a minor (or â€œinwardâ€) part. The major part is one or two letters followed by one or two digits, and the minor part is a digit, followed by two letters. Examples of valid postcode formats are M25 0LE, NW11 3ER and L2 3WE (no idea if these are genuine postcodes though). Coupled with the postcodes are northings and eastings. These odd-sounding beasties are simply the number of metres north and east from a designated origin, which is…
Dot Net What Not Posts
Of course, we professional programmers never make mistakes, ahem. Thatâ€™s why we never need to use debuggers, ahem.
Well suspend belief for a moment, and assume that I had a bug in the code I was developing. You know the feeling, you stare at it, you write unit tests, you stare at it some more, and still canâ€™t work out why on earth Visual Studio is claiming that there is an error in your code, when itâ€™s so obvious that there isnâ€™t. You even get to the point of talking to your computer, pointing out the error of its ways…
I was underwhelmed at being awarded two separate recognitions for my contribution to the community.
Read on and be as underwhelmed as I was!
Sadly, whilst building a solution yesterday, my machine started behaving in a very weird manner, with applications not responding, the taskbar disappearing and so on, followed by the dreaded blue screen of death. When I checked the event log after pulling the plug out (I hate doing that!) and rebooting, I found lots of errors, which led me to a Microsoft Connect article (now sadly removed) where someone was reporting a very similar problem.
To my amazement, the very last comment by a Microsoft employee in response to this bus report was â€œThis is known issue, this bug was resolved by mistake, we are already addressing this issue.â€
Surely they didnâ€™t mean that did they? Someone tell me I read that wrong!
As the non-existent avid reader of this blog will know, Iâ€™m far more interested in learning new technologies than I probably should be, given the limited amount of time I have to learn them properly! With that in mind, I shouldnâ€™t be looking at yet another, but this one does have a very immediate benefit (honest).
I have been an ASP.NET developer for quite a number of years, and can knock out a complex web site fairly quickly. However, as with most of my other programming until recently, this has always been along the â€œthrow it all in the code-behindâ€ anti-pattern. Iâ€™ve come a long way in the last six months or so, and am now very comfortable using MVVM in WPF, and separating out my code into logical classes as all the Good Programmers do.
Logically therefore, my web site development should follow the same lines. I read up on both MVC and MVP, and came to the conclusion that as an experienced ASP.NET developer, MVP made a lot more sense to me. I couldnâ€™t honestly see any technical benefit of one over the other, mainly as the MVC proponents seem to raise the same old â€œwebforms are evilâ€ arguments, without any real justification (to me at least, they obviously feel justified). My own feeling was that MVP wins out because it completely isolates the view from any action, meaning that the view is as dumb as it can get, which makes unit testing a doddle. I was won over towards the Passive View version of MVP, as this has even less code in the view than the other flavours.
This is not to say thereâ€™s anything wrong with MVC, just that I feel more comfortable with MVP.
This post details my initial exploration of WebFormsMvp.
I had the need today to add my own property to a WPF user control, and have that property available in the Properties panel of the Visual Studio designer, so the property could be set at design-time. The purpose of this was that my user control had a toolbar, and I had come across the need to use the control, but not show the toolbar. Simple eh? Well, not quite!
I had been having some serious grief with Visual Studioâ€™s unit testing tools. VS was complaining that some tests did not exist, and others called methods that didnâ€™t exist. Both claims were total lies as all methods in question existed, and could be found by using the â€œNavigate toâ€ feature in VS.
I had two basic errors when I tried to run tests. One was of the form “Method TestProject.SystemsRepositoryTest.CreateNewCamera does not exist” when the method did exist. I could right-click the test in the Test Results window and choose â€œOpen testâ€ and it would take me there. However, when trying to run the test, VS claimed it didnâ€™t exist.
The other error I got was of the form “Test method TestProject.SystemsRepositoryTest.GetAllCameras threw exception: System.MissingMethodException: Method not found: ‘System.Collections.ObjectModel.ObservableCollection`1
Thanks to these problems, I have wasted loads of time debugging things that could have been fixed with unit testing. It has been frustrating to say the least!
Well, I finally found the answerâ€¦
I opened the bin/Debug folder in the test project in Windows Explorer and deleted everything in it. I then rebuilt the test project, and my tests ran fine.
For some odd reason, it looks like rebuilding the test project wasn’t actually changing the DLLs in the folder, so it was using old versions, in which the methods didn’t exist. Deleting them all forced VS to grab fresh copies of the referenced DLLs, and rebuild the test project’s DLL.
I donâ€™t know if this is a bug in Visual Studio 2010, but it doesnâ€™t seem to be a feature that I would have added in by choice!
A common scenario is to have a button on a view that is bound to a command on the viewmodel. You can also have an ABCCommandCanExecute() method on the VM that tells the view whether or not the button can be clicked.
This is all fine until you want to ask the user to confirm the action that will be performed when they click the button. For example “Are you sure you want to reformat your hard disk, dial up all the people in your contact list and reformat their hard disks, and then destroy the world?” It’s kind of rude to do this without confirmation first.
The problem is that when you use WPF binding to bind the VM’s command method to the button’s Command property, you lose control over the execution process, and so can’t inject a message box into the flow.
When you use Linq to create a query against an entity framework model, a common scenario is to use the .Include() extension method to make sure that any child objects are also loaded. This is mainly useful when the results of the query are to be sent over WCF, where the client is disconnected from the source of the query, and so cannot go back to the database to pick up any child objects as needed.
This works fine for simple queries, but falls apart when you want to do anything clever, like joins or shaping.
I was having some trouble with WPF data binding yesterday, where the binding looked correct, but the data wasn’t being shown. It turned out that I had forgotten an .Include() on the original query (this data is being sent across the wire through a WCF service, so I can’t use lazy loading), but along the way, I discovered a really useful blog post on how to debug WPF data binding.