Insightful, profound, generous, witty, genius; all words that might be used somewhere in this blog.
Wednesday, February 25, 2009
Linq to Entities. The full horror...
As it turns out, This might be great long term advice but IMHO right now. If you want a solution that works. Go with Linq to SQL. The offer is more mature and the clincher is that the Entities DLL's have a major fault inasmuch as they have been compiled without the attribute that enables them to run in medium trust environments so, GoDaddy for one will not allow these DLL's on their servers.
Tuesday, February 10, 2009
Incredible lightness of being
Not carrying the weight of a laptop in my bag or having it on my lap cooking my legs is a real luxury.
Saturday, January 31, 2009
The pain of session variables in LINQ
One of them is in how errors are reported in a totally misleading manner.
Consider this little snippet of code.
var q=from t in MyEnities.SomeEntitySet
where t.ID==(int)Session["userid']
select t;
if (q.Count() > 0)
q.Count threw an exception that said:
LINQ to Entities does not recognize the method 'System.Object get_Item(System.String)' method, and this method cannot be translated into a store expression.
This drove me mad for hours because I tried everything such as verifying that the session existed, that the variable was real, was of the right type and was of the value I expected. All to no avail.In the end I solved the problem by first saving the session value into a local variable which I then used in the LINQ expression.
It seems to me that this has to do with the order of how things are evaluated within a LINQ expression and may even constitute a bug in the language. Why? well because it seems obvious now that the direct value from the session variable is somehow used before the cast operation by the LINQ parser and so an exception that seems to have no real relation to actual circumstances is thrown.
I hope that this helps to trap similar errors for people hunting for hours on Google like I did.
Wednesday, January 28, 2009
Fire and forget storyboards...
I have fallen deeply in love with Silverlight and it's evident, in Silverlight 2 at least, that one cannot do everything in XAML and there is still an element of code needed to do a job.
Because of the lack of triggers in the same sense as those that exist in WPF, Silverlight can be a pain when we need to create dynamic animated effects. However I had an idea that leans heavily upon the joys of garbage collection and anonymous methods to provide a fire-and-forget style storyboard which can do animations and handle its own events.
One little job I recently accomplished with this was to create some animation effects that had two stages; for example, to fade one element out and replace it with another.
The joy of this technique is that we can build a storyboard and the associated animation details dynamically, set it running and then just forget it while it does its thing. After the events have fired the whole thing -should- be reclaimed and garbage collected. (He said, wondering about shooting himself in the foot.
Here's some XAML...
<UserControl x:Class="FireAndForget.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300">
<Grid x:Name="LayoutRoot" Background="White">
<Ellipse Fill="red"/>
<Button Content="Click Me" Width="100" Height="25" Click="Button_Click"/>
Grid>
UserControl>
And here’s the button click code..
private void Button_Click(object sender, RoutedEventArgs e)
{
Storyboard sb = new Storyboard();
DoubleAnimation da = new DoubleAnimation();
da.BeginTime = TimeSpan.FromMilliseconds(0);
da.Duration = new Duration(TimeSpan.FromMilliseconds(1000));
da.From=1;
da.To = 0;
sb.Children.Add(da);
Storyboard.SetTargetProperty(da, new PropertyPath("(UIElement.Opacity)"));
Storyboard.SetTarget(da, this.LayoutRoot.Children[0]);
sb.Completed += delegate(Object o, EventArgs ea)
{
Random rnd=new Random();
((Ellipse)this.LayoutRoot.Children[0]).Fill = new SolidColorBrush(Color.FromArgb(255, (byte)rnd.Next(255), (byte)rnd.Next(255), (byte)rnd.Next(255)));
sb = new Storyboard();
da = new DoubleAnimation();
da.BeginTime = TimeSpan.FromMilliseconds(0);
da.Duration = new Duration(TimeSpan.FromMilliseconds(1000));
da.From=0;
da.To=1;
sb.Children.Add(da);
Storyboard.SetTargetProperty(da, new PropertyPath("(UIElement.Opacity)"));
Storyboard.SetTarget(da, this.LayoutRoot.Children[0]);
sb.Begin();
//done!
};
sb.Begin();
}
Good eh?
Tuesday, January 06, 2009
Oh the shame!!
Today, my pals at work had a great laugh at my expense. I was quite happy to show them my new pages on my site, yeah, the ones with the Silverlight banners.. and after a couple of seconds, they laughed so hard that one of them fell off his chair.. Seriously.
So my Silverlight efforts are too "bling bling". My site has a 1970's look 'n' feel. My banners are crass and I have no taste in, well, in anything much!
I live and work in the country of my own country's traditional enemy. I speak their language and accept their customs. I even listen to their ever-so twisted version of history with good humour. I suppose that I'll just have to accept the fact that my site is "moche". Anyone want the code?
Sunday, January 04, 2009
Silverlight fulfilment!
I must say that Brinkster have really made leaps and bounds on the quality of their hosting and particularly their support.
I use GoDaddy for some of my sites because, well, let's face it, they're cheap and cheerful but for all my mission critical stuff I use Brinkster. Even though it costs just a little bit more it's worth the money for the level of support that these guys give.
You can see the new silverlight XmplXaml page by following the link..
Silverlight frustration
The application, which I call XmplXaml, uses reflection to discover the properties of an object and provides a simplified view of the various collections and the types they can contain. So, rather than a class hierarchy you can see the Xaml hierarchy of tags. Running this application on PathGeometry for example, gives a rather nice view of the different PathSegments we can use and their relation to the root object.
So, now to the contunuing frustration part.. My bobpowell.net site is hosted on Brinkster and has been for many years now. I uploaded my new applications only to find that they haven't enabled silverlight on their servers. AARRGGHH!
I will either have to rename all the XAML files to XML, a soloution I am not happy with because I like the idea of doing everything directly from Visual Studio, or to get my old pal Jared over at Brinkster to have his team set up the silverlight MIME types properly. Failing that, I'll have to move my site to a server that supports them. That would be a shame because I like the Brinkster setup.
Here's a little screen-shot of my utility to be going on with...

Thursday, January 01, 2009
Misinformation is driving me insane!
Try any simple search for information and you'll be swamped with good looking content that, after you read a few lines, turns out to be for Silverlight 1.0 beta versions and has absolutely no relevance to anyone using the technology on front-line applications today.
I call upon all authors and bloggers to clean up their blogs and remove every article that still turns up with old and confusing information about uselessly dead beta versions.
Oh.. happy new year too!
Monday, December 29, 2008
Killer iPhone app
My absolute favourite application on the iPhone is Stitcher. It's a neat little app that finds and stitches together podcasts into one long custom radio show.
Being a Brit, I like to listen to UK podcasts from the BBC and the Guardian. Also, having lived in the US for a while I like radio shows such as Car Talk and Science Friday from NPR. The Stitcher application lets me listen to all of these while I am charging around the streets of Paris on my Triumph Bonneville.
Check out Stitcher at http://www.stitcher.com or in the App store on your iPhone.
New content
To be honest, I have been so aware of the fact that there is an incredible plethora of information on these subjects available that I wondered about any contribution that I might make being just so much noise. However, after searching for information that was relevant to problems I was working on and finding nothing but out of date and indeed, misleading blather, on the last-but-one beta, alpha or RTM, I am encouraged to imagine that I may actually have something to say if I concentrate on "la derniere cri" as it were.
Watch these spaces, or, if you're lazy, subscribe to my RSS feeds.
Saturday, December 27, 2008
Embed a silverlight control into an ASP.Net page
I have produced a video using Camtasia that shows how to achieve the task in what seems to be the simplest manner. I hope you like it.
Incidentally, One of my clients is a company that has me creating educational video content for their development teams. I don't have quite the same equipment as they have, a studio and dedicated engineers, but I think that I will do more of these.
To see the video, just follow this link...
Thursday, December 25, 2008
Grumpy old man?
I am a grumpy old man. I am also proud of being one, in the same way that my darling wife is proud of being a crone.
What do I moan about? I moan about my idiot children who have decided that smoking is a cool thing to do. I moan about the way big business has no room for the little person and how there is no real concept of personal service any more unless it's the service of sycophants that expect to be paid for the honour. I moan about shitheads like Robert Mugabe or those blasted Chinese who commit genocide upon Tibetans and who are ignored because the west loves to wear Nike shoes. I moan about the duplicity of governments who have elected officials who refuse to obey the will of the people that elected them. I moan about religion that pollutes the minds of people so much that they would kill innocent children in the name of their useless gods.
Secretly however, deep inside, I am happy. I am happy that I am fortunate enough to be able to feed my idiot children, even if they don't appreciate it yet. I am happy that I have my health and that I have a very low probability that someone will stick a gun in my face in the near future. I am happy that I can vote for my officials even if I know that they still won't really do what I want them to.
I sincerely hope that wherever you are, even if you're a grumpy old sod like me, that you can enjoy this mid-winter festival free from oppression, hunger and looming death. If you can't, rest assured that I am thinking of you and wish that things could be different for you.
Merry Yuletide.
Tuesday, December 23, 2008
Life, the universe and everything.
Frank Drake's now famous equation has been seen, for many years, as a possibility but recent developments in the study of the statistical possibilities of the incidence of life suggest that a much more conservative figure should be expected. Several ideas recently postulated, say that the possibility of life on a potentially suitable planet is only about 0.01 percent. If we take the best case, saying that liveable planets exist in every solar system then we could expect about a hundred million planets should exist in our galaxy with some sort of rudimentary life, some of which would grow to harbour intelligent life.
If we take a very dim view that only one in a hundred solar systems has anything like a Goldilocks zone, perhaps we could imagine a million life bearing planets in the galaxy.
Whatever the outcome, there is still only one possibility. That is that mankind must go out to space, not just as occasional visitors, but en-masse to struggle and probably to die out there but certainly to colonise the universe as much as we can.
In our four million year or so existence we have conquered just about all there is to conquer, at least in a physical sense, upon the earth. In all that time we have also shown that we do our best work when faced with adversity and a frontier to challenge. Having no frontiers remaining on earth will cause humankind to expand to completely fill the boundaries that we have and then to perish in decay.
So many people these days are concerned with the environment and with the destruction we are wreaking on the planet as we grow our technologies. We moan and whine about global warming or carbon footprints but few people see that this planet is nothing more than a stepping stone for the species and that, as the very top of the top of the food-chain, we own the darn planet and we can do with it as we please. If we need to make so much mess on the planet that we have to escape it at all costs then this will do no more than save the human race from the other, more awful possibility that we will one day be wiped out in our complacence and laziness in our own little Zen garden, unable to prevent the sun from evaporating our oceans or an asteroid from erasing us as the Dinosaurs were snuffed out from history.
I love Tigers and Rhinoceroses and frogs and Pandas but really, I don't give a monkeys, if you'll pardon the pun, for any of them if preserving them means that we must endanger our own future. DNA is nothing but software that runs on amino-acids. We can disassemble it at the moment but in a few years we will have an assembler for the stuff too. We can only hope that the democratisation of the gene assembler is used to make things as benign as a new Panda or to raise the Mammoth or the Tyrannosaurus from the dead. You can be sure that before Jurassic park is a reality, a world blighted by pathogens released by religious fanatics will be more likely.
Mankind must have a frontier, men must die to cross it and, as a race, we will never survive if we do not make the supreme effort. Screw the oceans, the fish, the trees and the dammnable Pandas! Grind them all under the wheels of the rocket launchers! Let's get out of here!
Tuesday, November 25, 2008
Has HowStuffWorks lost it?
While the fact that they do work may upset some more militant members of the union, this seems to be a sad comedown for a site that had always delivered good content.
How stuff works seems to have explained all the cool stuff in the world and is scraping the bottom of the barrel to find new material to justify its daily feeds.
I guess until the new Large Hadron Collider is eventually up and running and we finally understand the deepest secrets of the quantum universe, we'll have to be content with things like "How snot works" and "How toilet paper works" and "How dog poo works"
Oh how the mighty have fallen!
Friday, October 03, 2008
Not quite getting it
You can imagine the hilarity that resulted from that!
Wednesday, September 24, 2008
Agile Methodists
I stumbled upon an image of a group of developers participating in the stand-up meeting which, I seem to recall, was on Kent Beck's site and was struck by the similarity between it and images I have seen in Mormon pamphlets, the ones that are obviously an image treated with a Photoshop style aquarelle post-process, that makes the image look as if it was the work of an impressionist painter.
I was startled to make the association between agile methods and religious fervour but re-reading the agile manifesto, which I always thought of as a sort of Marxist text, I see now is more of an evangelical thing.
Suddenly, the pieces fell into place and I felt a chill run up and down my spine when I realised that the morning meeting where everyone speaks a little about what they did the day previously, what they intended to do today and if they were having difficulty on some level or other, was a definite ringer for a witnessing.
Occasionally, meetings get a more conventionally religious overtone when a charismatic developer decides to expound upon hot theories during the sacrosanct fifteen minutes and extends it to forty five while people shift themselves into more comfortable leaning positions on walls and the backs of chairs.
There may even be a burgeoning market for cardboard cut-out pulpits!
Wednesday, September 17, 2008
Is Apple's software quality slipping?
Aside from being locked to their view of the world, a situation that will be rectified very soon when I jailbreak the thing, I was astounded to find that the Apple reputation for thinking of everything and being easy to use falls far short of expectation.
I am a biker and do my daily commute on my Triumph Bonneville so I got a Bluetooth helmet kit and subsequently discovered that the iphone doesn't have an auto-answer function for when the headset is connected. Furthermore, for a touch device not to support handwriting recognition or voice command dialling yet have the processor power to do serious graphics is inadmissible.
I've hadthe thing for a week now and I am getting used to it's little foibles but to be honest, it shouldn't have any!
Posted from my IPhone...
Wednesday, August 27, 2008
Reflector
Personally, I am "gobsmacked" as they say in the UK that Microsoft hasn't done the right thing and paid Lutz handsomely for this system so that it could be included in Visual Studio as a tool. This isn't the first time I've been similarly gobsmacked at the stupidity of Microsoft when dealing with community projects of this type. The previous grave error on their part was to not buy nDoc for a decent price instead of proposing that P.O.S. Sandcastle as a viable alternative.
It seems to me that when it comes to community, Microsoft seems to have lost touch with what community is about. As a long time advocate of community and peer-to-peer education and assistance I believe strongly that some things used by the community are just too good to let fall into the hands of third-party entities that would exploit them in the wrong way.
I imagine that when Reflector was first seen, there were those in Microsoft that were aghast at the idea that all the source code of the framework became open to anyone who wanted to view it. I also remember it as a wakeup call to companies that had no protection for their own code. Despite this initial reaction, Microsoft never made an effort to obfuscate the system DLL's and now, I don't believe that a single developer on the planet who programs for Windows can get through the day without using Reflector somewhere.
As community projects or run by small entrepreneurs, a self-starter tool of such enormous impact as Reflector, nDoc or even nDepend, present no competition to to Visual Studio and do nothing but enhance it. When taken over by a third party, these tools immediately become looming compettitors that may adversely affect the market and reduce resources when Microsoft suddenly realises that they have to build competing functionality into Visual Studio.
A couple of million bucks is a drop in the ocean for Microsoft. Imagine what they themselves would spend in order to try to create something as universally useful as nDoc, Reflector or nDepend. On the other hand, for them to purchase these tools and add them to the Visual Studio system would be an incredibly useful and sane thing to do. Instead, they allow such important work to fall into the hands of third parties that really are potential competition to them.
Microsoft, Wake up! Look at the communities that you say that you value, use the resources in them to enhance the product, don't allow something like this to happen again! It's just plain idiotic.
Thursday, July 31, 2008
The compiler can choose to ignore the fact that a better parameter match exists and use a lazy evaluation of a method in a derived class. Apparently, this doesn't break the rules of OOP or of polymorphism. It just prevents "brittle base class" syndrome.
Personally, although I can see a certain validity in the arguments of MS gurus like Eric Lippert I still feel as though the wool has been pulled over my eyes somewhat. How I missed such a simple thing as this for the last eight years is a mystery to me. I must be getting old.
Ahh well. I suppose I had better brush up on my VB syntax because despite the fact that the language is verbose and redundant they have a kick-ass compiler that is proven to be better at
loop optimisation and now I discover that it handles an important compiler principle in a logical and intuitive way.
Thursday, July 24, 2008
Still bugs in the C# compiler.
Speaking with a friend who works for Microsoft he quickly said it wasn't a bug and gave me a line about explicit casting and method selection in the compiler but I think that the example is really simple and is a clear breach of overloading principles.
I have a base class with a virtual method which contains an integer parameter. In a derived class I include both an override for the original method plus an overload for the same method but this time having a float parameter.
The main function calls the derived class and even when the parameter is cast explicitly to int, the int overload is never called.
This is true in the 2005 and 2008 versions.
To prove a point I wrote the exact equivalent functionality in VB.net and it works as expected.
Here's the code.
class Program
{
static void Main(string[] args)
{
DerivedClass dc = new DerivedClass();
dc.AMethod((int)1);
dc.AMethod(1f);
Console.ReadKey();
}
}
class BaseClass
{
public virtual void AMethod(int i)
{
Console.WriteLine("Base class integer parameter!");
}
}
class DerivedClass : BaseClass
{
public override void AMethod(int i)
{
Console.WriteLine("Derived class integer parameter");
}
public void AMethod(float f)
{
Console.WriteLine("Derived class float parameter");
}
}