Monday, November 8, 2010

Error setting image source in silverlight from a memory stream

Have you received the following error? "catastrophic failure exception from hresult 0x8000ffff e_unexpected" while trying to set a bitmap image source from a memorystream?

I battled this all weekend and wanted to share. My basic scenario is to use the fileopendialog in Silverlight. Pick a jpg, for a profile picture. Show the picture then upload the picture to Azure Table Storage.

I'm using a WCF service.

The error probably isn't in the way your putting the retrieved memory stream into your bitmap image. It's how your converting you stream to a byte array when you first open it up.

I'm not going to try to get into lots of code here. Here's the basic file open code. Mine might look different, but if you get you code open, and are having success putting your image up, don't worry about the differences.

What I found out when I started looking is that in putting the stream into the bitmap sets the position in the stream to the last byte. Converting the stream to the byte array at that point runs fine, but all bytes are set to 0. Storing and retriving that byte array causes the catastropic fail.

You can put a break point on the code after the conversion and see the bytes are all {0}. Also check the stream.Position. I'll lay odds it's at the end.

If this is the case add the line of code highlighted in red. It sets the position back to 0, and the conversion code starts at the beginning.

private void cmdFileOpen_Click(object sender, RoutedEventArgs e)
OpenFileDialog openDialog = new OpenFileDialog();
openDialog.Filter = "JPEG Files (*.jpg;*.jpeg)*.jpg;*.jpeg";

if (openDialog.ShowDialog().GetValueOrDefault(false))

using (FileStream stream = openDialog.File.OpenRead())

BitmapImage bi = new BitmapImage();

imgProfile.Source = bi;
stream.Position = 0;

// Now read s into a byte buffer.
byte[] bytes = new byte[stream.Length];
stream.Read(bytes, 0, bytes.Length);

//Get the service reference for the wcf service.
UserSVCClient client = App.GetUserClient();
client.UpdateProfileImageCompleted += new EventHandler(client_UpdateProfileImageCompleted);
client.UpdateProfileImageAsync(App.UserInfo.UserID, bytes);


Friday, August 1, 2008

Agile Estimating & Planning Class - Completed

Ok, so now where do I go. I just praised Bryan and Chris for having the best IT related class I've ever been in and now I've just completed another class which is just as good, if not better. But to tell you all that would make me seem well....

OK, so how to describe the Agile Estimating & Planning Class?

First the class is for more "advanced" scrum users. Or better said, people in this class are much more likely to have done scrum and have a higher probability to understand the basics of scrum. Makes the class a lot easier.

Why go to this class after CSM and CSPO. After all planning and estimating are covered in every scrum class out there. At least is was covered in both my CSM and CSPO classes in some level of depth anyway. I guess about 1 - 2 hours in the other classes. This is much more immersive in nature. 8 full hours to take in the concepts. And WELL WORTH IT. I'm a firm believer that a lot of the success of scrum in in the nuances of the process. 1 hour in a scrum class just isn't enough to get into the nuances. 8 hours gives you a much greater foundation.

For me this class related more info that I haven't grasped out of the books like I had the CSM and CSPO classes. I won't go into detail about what I learned now. Later as I have a chance think it out some.

The real strength of this class can be attributed 100% to Mike Cohn's obvious deep level understanding of the material and a high energy passion for the subject. One of the other students said it well. "Class literally flew by". We were on our lunch break before I realised it. And I mean, I thought we still had 2 hours before break time.

For me, most of what we learn in Agile/Scrum is just common sense, and in a lot of ways I've been "Agile by Accident" for a very long time. But what I've always struggled with was how to estimate software projects. I know the old ways, and I know they fail miserably. So in the end, I really haven't ever (or almost never) have been willing to waste the time. Now I have a complete tool kit around how to estimate, and estimate with solid accuracy.


Monday, July 28, 2008

Agile Estimating & Planning Class

This week I'll be heading down to San Diego to attend Agile Estimating & Planning Class. This one is being put on by the Scrum Alliance and features Mike Cohn. I'm pretty excited to be getting to this class.

Where most of Scrum is absolutly intuitive to me, there are a lot of questions I have around estimating and planning in the Scrum world. Primarly centered around how to do it, and how to measure how your doing so you can improve.

I'll run down the class on Thursday.

Oh, and according to Mike we all get Planning Poker Cards. Is that just too cool or what?

Thursday, July 24, 2008

CSPO Class Completed

OK, so just woke up after an 8 hour drive from San Jose, after the end of class. So if this is semi-incoherent, sorry, I'll clean it up later.

This CSPO class was presented by Bryan Stallings and Chris Sterling from SolutionsIQ, via the Scrum Alliance.

Class was excellent. Quite possible the best IT related class I've ever been in. And with all the years I've been around this game, that's saying something.

Bryan and Chris present a quiet professionalism that I don't see any where near enough. Both possess a unique ability to combine real life examples of Scrum at work, with the presentation of course materials.

They run the class as a mini 4 sprint scrum project. Complete with sprint planning, burn downs, sprint board, etc, etc. Very effective way to present Scrum.

Course materials were excellent. From the slide deck to the large posters on the walls with salient information. Everything, despite early appearances, is well thought out and done with purpose. My comment about early appearances is only that early in the class, we're asked to deal with a class exercise, the point of which ends up being to drive home how important preparation and planning is.

The course proceeds through a series of short lectures w/slide deck and back up materials and plenty of class interaction. The exercise are too the point, expectations and instructions are well communicated, and time is adaquite. Well time is adequate if the team uses the time wisely.

As a team they also work very well together. Hand off is smooth, and it's evident either could teach any portion of the class, and could handle a class alone if necessary.

All in all, I highly recommend this class, or for that matter any class these two put on.

Saturday, July 19, 2008

CSPO Class This Week

Heading up to San Jose for CSPO class. This one is being put on by Bryan Stallings and Chris Sterling from SolutionsIQ, via the Scrum Alliance.

Having been through CSM Class about 5 weeks ago I'm pretty convinced this will be 75% the same material. All about Scrum, etc, with a bit pitched in for the Product Owner instead of the Scrum Master. Even if this is the truth, I still believe there's a lot of valid information to hand out.

If you watch the courses the ScrumAlliance holds, there's somewhere in around 10 CSM classes to each CSPO class. While I understand this is simply a matter of demand, it's unfortunate. I see the CSM role as being critical to the entire process. However, I see, as the "single ring-able neck", the CSPO role and management's interest in that role being well trained as a key indicator as to management's willingness to proceed with an enterprise wide Scrum adoption.

More on this after class.

Thursday, July 17, 2008

Where to now?

Ok, so in the last two posts I bored you with my background, and some of the technologies I've dealt with over the years.

In the end though I've been around the block a few times and I've done the VBITS conference speaking kind of things, you probably won't know my name. I tend to be heads down, deep in the technologies, and do more private mentoring than shouting out loud.

I'm seriously enamored with a couple of things. First and foremost in my frontal cortex is Agile development practices, with a serious concentration in Scrum. I was able to go through Certified Scrum Master class a month ago and am rolling it out into my organization slowly, but steadily. Next week I'll be in Certified Scrum Product Owner class, and the following week in a 1 day "Agile Planning and Estimating", class presented by Mike Cohn. (Ought to be a CSE, Certified Scrum Estimating) . I'm starting to ramp up involvement in the Scrum Alliance.

I will be using this as my bully pulpit for my thoughts on Scrum. To a certified cowboy coder like me, who has hated all things process, this has hit me like a thunder storm. Scary, but oh so refreshing. One of my very best buds tried to get me to look at Scrum a couple of years ago, but my head and heart were just dead set against more process. I've been kicking my self and apologizing to him for a couple of months now.

Next is AJAX. I've done remote asynchronous calls from browser to server side methods without a full post back for years. But with the mash-up of technologies called AJAX, this is so much easier, more robust, and is going to be a huge enabling tool for web development in the future. I don't want to deprecate the use of the MS AJAX Toolkit. As a java script library, it's a very nice set of tools, but the true power of AJAX lays in the in the asynchronous nature of the technology.

Next on my list is WCF. I've been in an org for years that hasn't had a real need for an SOA, or the time and resources needed to deal with SOA and all the work it takes to put it together. Enter WCF and the encapsulation of all the plumbing necessary to do the grunt work, and let my dev team work on building business solutions.

Have a couple of books I'm working through. One great, and well one that's not worth the ink and paper it took to print is. The great one is "Programming WCF Services: Building SOAs with Windows Communication Foundation" from Juval Lowy.

So swing buy from time to time to listen to me rant. Technology, development, process are all on the table. Heck might even do a movie or book review or 2.

Wednesday, July 16, 2008

Where Have I Been?

Ok, so lets see, in the 9 years in the Air Force I spent 90% of the time deployed, and hit 85 countries. Let's list them all. Ok, just kidding, I know you don't really care about all the countries I've been in.

So I'm a programmer at heart, and have been around 32 years. Lets look at the journey through those eyes.

We'll isn't that special. Attempted to stick an html table in, and I get an extra line break in my post for every table element. Ok, so lets try a list.

  • COBOL - Limited, collage classes
  • FORTRAN - Limited, collage classes
  • Pascal - Limited, Worked with during the Air Force
  • Delphi (Object Pascal) Limited, 2 small projects to learn it
  • Python, Limited, tweaked some code to better display some game maps for an MMORPG
  • LUA, Limited, tweaked some UI code to take a horrid game ui into something playable.
  • PHP, Limited, and don't get me started on this and the rest of LAMP. More on this in a future blog when i feel like ranting some.
  • C/C++/VC++, Limited, and yes I know if any C++ guys are around they will take offence o me combining all of these together. Sorry gang.
  • DBase I/II/III+, A lot of work here over the early years. Nice when the DB and language are in one spot.
  • Excel/Lotus 123/Lotus Symphony/Silk, Actually have done over the years a lot of work in thier macro langagues.
  • VBA, ya, ya, I know....
  • Oracle
  • DB2 AS400
  • HP3000 Image Database

Ok so thats the list of langagues and database's I can play in, but prefer not to. Now on to stuff I'm around more.

  • Basic/VB, Feels like I've been doing BASIC for most of my life. Oh wait, 32 years since my first BASIC program on an HeathKit H8/H9. So I guess I have been at it for the majority of my life. A few BASIC classes in the Air Force. Several Games for the Commador Vic20 and C64. Then into VB3/4/5/6/7/ Have done some pretty serious work in the VB realms. Multi-threaded VB5 with function call backs.
  • C#, After so many years of VB when .net arrived, I just couldn't stand the idea of upgrading yet one more time, so made the switch to C# and have been like a pig in slop ever since.
  • SQL Server 4.2 - 2005 (just waiting on 2008), pretty much been a
    SQL server hound for as long as it's been a viable tool. It's my DB of choice.
  • AJAX... Let me rephrase. AJAX not (though they are cool) the AJAX tool kit. Asynchronous XML and Java Script is just well one of the very coolest technology mashups to come along in a long long time. We were doing remote work with broswers to the server for years before, but the AJAX wrapper around it, is just sweet.

This is a pretty good list of what and where. Next entry I'll talk more about what I'm enamored with. That list is pretty small, but very current.