C# and Friend Assemblies Made Easy

friendassembly_small.pngIf you are familiar with C++, you’ll know about “friend classes” within that language. If you are not familiar with them, they are a neat way of exposing otherwise private methods to trusted classes. Class A has a bunch of private members, that are obviously hidden to other classes, but there is a problem with this model. Class B is a unit test class that tests class A. Because it is doing unit tests, it needs to delve deep inside class A to check what is going on. By making class B a friend of class A, the former is then granted access to the latter’s inner workings.

So what does this have to do with C#? Well C# partially fixed this with the “internal” keyword. Internal members of a class are visible to other classes within the same assembly, but are effectively private as far as classes outside the assembly are concerned. Internal members are very different from protected ones by the way. In the latter case, they are only visible to subclasses (whether in the same assembly or not). However, largely due to a limitation with Visual Studio, internal members used not to be the full answer to the needs of unit testing. The C# compiler supports compiling multiple projects into one assembly, but Visual Studio has a strict one to one project/ assembly mapping. So unit test classes used to have to reside within the same project as the product code (which wasn’t practical if the project’s assembly was a executable, rather than a dll.) The other alternative was to expose all the members that the unit test classes needed to access by making them public.

I talk in the past tense in the previous paragraph as this problem was fixed with the release of C# 2.0. This introduced the idea of Friend Assemblies. To explain, let’s go back to our class A and B. Class A resides in assembly A.dll. Class B resides in assembly B.dll. Normally class B would have no access to the internals of class A. Add the “InternalsVisibleTo” attribute to class A though, specifying B.dll as the trusted assembly and now class B can access those internals. Further, unlike with C++ and friend classes, private members in class A remain private; only internals are exposed via this method.

If both A.dll and B.dll are unsigned, the extra code is just:

which is a pretty neat solution.

Things get really messy though the moment signed assemblies are used. The reason is that one must put the public key (not the nice short token, the full-blown humongous key) in the attribute. So it becomes something like:

(I’ve wrapped the public key across many lines for clarity. In reality, it must be on one line)

The whole horrible nastiness of the matter doesn’t stop there though. To get that public key, one must find the sn.exe tool, plough through its dozens of obscure options, and then run the right one against the required assembly (or run a sequence of two even more obscure commands against the original key file). Then one can cut and paste the output of the command into the attribute in Visual Studio. This is what we in Britain politely term a “complete faff”.

Having banged my head against the wall performing this operation recently, I decided that a simply little utility was required to do all the work. So I wrote an app called FriendAssembly, which I’m sharing here.

Continue reading “C# and Friend Assemblies Made Easy”

MacBook Air: Style Over Substance or Another Winner for Apple?

It is one of the worst kept secrets in recent years: Apple were due to unveil a slimline Mac laptop at this year’s Macworld expo. And Steve Jobs dutifully did reveal it. It costs a small fortune; has a low speed CPU; has no built in DVD drive. However it is claimed to be the slimmest laptop in the history of the universe and only weighs around 3lb (less than 1.5kg).

macbook_air.png

So what does one get for $1799 (or around $2400 if you live in Britain, but it is OK, we are used to US companies ripping us off. Adobe charge double for their products here, so 33% more expensive than the USA ain’t that bad)? A 4200 RPM (ie sloooooow) 80Gb hard-disk, a 1.6GHz Core 2 Duo (the substantially cheaper, but heavier MacBook offers a 2.0GHz CPU) and a super-thin, super-light case. The Macworld site has a good summary of its specs.

Obviously the Mac fanboys are already discussing buying it. But should the ordinary person buy one? In my view, this is a step too far down the style-over-substance path by Apple and it would be a bloody stupid idea to buy one. If you want a Mac laptop, buy a MacBook Pro ($100 more for so many more features). If you want a lightweight laptop, buy an Asus Eee PC and save yourself $1300 in the USA or £1000 (around $2000) here in Britain.

Problem Solving the Microsoft Way, or How to Get Silverlight Onto Every Desktop

beijing.pngProblem: Silverlight is new; hardly anyone knows about it, so hardly anyone will use it (why bother when they already have Flash?)

Solution: Provide users with exclusive access to over 3000 hours of live and on-demand video content via Silverlight streaming. And not just any old content either, we are talking the Olympic Games here. Microsoft have secured a deal to provide the online coverage of the Beijing Olympics in August this year and all that coverage will use Silverlight, requiring everyone who wants to watch the stuff to install the Silverlight (version 2 apparently) plugin.

This is a clever move by Microsoft, and a brilliant news for RIA developers concerned at the lack of market penetration of Silverlight. After the games, that penetration rate should have jumped from near 0% to a very significant percentage of the world’s computers.

More details on Somasegar’s blog

Has Adobe just killed SWX?

adobe.pngAdobe today announced a new open source initiative called BlazeDS, which sees the previously proprietary AMF protocol file format made open source. Why is this a big deal? Well up until now, Flash-based RIA developers wanting to pass data between the client and a back-end server have had to choose between three unappealing technologies: XML/JSON, Adobe’s official remoting technologies and unofficial third party tools based on “hacking” Adobe file formats. The first suffers from serialization/ deserialization and verbose data format overheads. The second is just plain expensive (and only works with Java back-ends). The third is of dubious legality. BlazeDS changes all of that.

BlazeDS is based on the AMF file format used in Flash Remoting, and in the (until today) dubious legality of products like AMFPHP. With the release of BlazeDS and the transformation of AMF into an open file format, Adobe have made AMFPHP legal, which is superb news for RIA developers. Its worth thanking Microsoft here therefore. Why? Well ask yourself why, other than through a fear of Silverlight stealing the RIA market from Flash, would Adobe be given away a previously valuable asset?

And so back to the subject of this post. Has Adobe just killed SWX? Until today, SWX lacked (as far as I could tell) the ability to pass complex objects back and forth between server and client, but it more than made up for this by the server providing the data as native SWF files. However now that AMFPHP is fully legal and SWX remains in the legal grey zone, to me the choice between AMFPHP and SWX becomes a no-brainer. I can see no reason now to use SWX.

I invited Aral Balkan to respond to this post. He didn’t disappoint and provided a very detailed response on his blog.

Microsoft scrap plans for Silverlight 1.1 (and call it Silverlight 2.0 instead)

“Big Blue”, the SIlverlight logoIt appears that it has finally dawned on Microsoft that adding major new features to Silverlight (.NET support, “proper” controls that support layout management , sockets, data-binding, templates and networking and support for cross-domain networking) and then just issuing it as a minor release (1.1) wasn’t such a clever idea after all. So look out for a beta of Silverlight 2.0 early in 2008.

Read more about it on Somasegar’s blog

Apple loses its shine as Leopard brings it out in spots

osxleopard.pngApple have, in recent years, turned the Mac from a specialist machine used by those focused upon graphic design and video to a functional object of desire for developers, designers and general users of all types. Hardware prices are comparable with PCs, the OS both looks good and is rock solid and it seems to lack the problems that plague the Windows world…

… Then came Leopard. Many reports abound of it being a nightmare to install, of it eating battery power, of frozen keyboards and of glitch-ridden applications. In fact, previous public advocates of the Mac have taken to apologising to their audience in advance when doing presentations due to the high risk of a problem occurring during a presentation.

So has Apple’s bubble burst? Have they created a product so bad that people will flee from OS X to Vista? Probably not, but it shows the danger of trying to innovate too fast. I have recently being listening to a set of podcasts by the innovation guru Phil McKinney. One of his key messages is to do with the innovation funnel, whereby hundreds of ideas are whittled down to one or two innovations. It strikes me that Apple – normally the Kings of Innovation – simply bit off more than they could chew with trying to develop Leopard, the iPhone and the iPod touch at the same time. Perhaps it’s simply a case of too many killer innovations spoil the apple stew.

Brighton Isn’t Just for Flashers; it’s Good for Geek Dinners too

pacman1.pngDo you live in or near Brighton?  Are you (at least accused of being) a geek? If so, you may be interested in the Geek Christmas Dinner organised by the  Sussex Geeks and Brighton Geek Girls.  If a meal with a  bunch of geeks floats your boat, then book early for the £20 a head, limited space event here. Apparently Aral  Balkan will be speaking. Let’s hope he does a better job than at Flash on the Beach 😉

Flash on the Beach Day 3 with interesting “from the [Adobe] horse’s mouth” Q&As

fotb21.png

I thought I’d write up day three in a different style to the other days (mainly because I’m running out of ways of expressing “useful/ interesting session” when describing each one). Also for me there was one session on day three that made attending the event essential: the Adobe “Town Hall” session first thing in the morning. Such sessions can be great for teasing info out of a company (especially one as secretive of future plans as Adobe) and for getting good answers to questions that tend to stump local agents.

Continue reading “Flash on the Beach Day 3 with interesting “from the [Adobe] horse’s mouth” Q&As”

Flash on the Beach Day 2

fotb21.png

Day 2 of the conference was a huge improvement over day 1. I was able to pick a set of sessions that were useful rather than just interesting. Technical glitches caused problems, but there was less amateurism on display.A session by Adobe’s Ted Patrick on Flex worst practices got the day off to a good start. Ted’s speech was more about how to avoid bad practices rather than a ‘train wreck’ list of them. Test driven development with ASUnit got a mention as a way of avoiding many problems, along with agile practices (no mention of scrum though) and the use of subversion. All of it was preaching to the converted from my point of view, but great to hear.

The next session was the low point of the day. Dave Yang was covering mobile devices. He arrived late and the technicians couldn’t get various devices to work with the projector. So we had a short session involving lots of shaky camera-pointed-at-device type demos. A shame as this is an important area for me.



Aral Balkan
was up next with his SWX talk. This was a classic piece of tempting fate. At the start of his speech he touched upon how he had moved away from unreliable Windows to his lovely reliable Mac. Later in his speach his lovely reliable Mac had to be rebooted as it refused to connect to the wireless network. Let’s just say it made me smile.


The end of the day was wrapped up with a stunning set of OpenGL particle processing animations by Robert Hodgin. All in all a good day.

robert.jpg

Flash on the Beach Day 1 Part 2

fotb21.png

The reality of the 5th struck me halfway through the afternoon: the car park at Lewes station shuts at 5pm and day 1 of the conference shuts at 5pm too. I contemplated possible quantum solutions, but to no avail. Luckily the Flash on the Beach organisers came to my rescue. The 4-5pm session on Tuesday, by Joshua Davis hadn’t looked very interesting, so John Davey kindly swapped it with the Monday one, and so I was able to leave early without missing anything important to me. Not sure how the organisers knew I needed them swapped, but thanks anyway.



One of the the two sessions I attended in the afternoon was Carole Guevin‘s session on Self Promotion, which was OK, but nothing exciting. The other was a very impressive speaker, Hoss Gifford, singing his own praises. He ran through a bunch of projects that he had been involved with. and went into what had gone on behind the scenes. Neither was particularly informative to a software developer, but both were thought provoking.

I’ll end this post with a thought for you: do you know everything? If not then you ignorant. This of course means we are all ignorant, so why does the word carry so much negative baggage?

Flash on the Beach Day 1

fotb2.png

It is lunchtime on day 1 of the Flash on the Beach event in Brighton and my main thought so far is ”what sort of two bit conference is this? They don’t even provide lunch!” Poor quality organisation aside, so far it has been reasonably good.

The keynote was better than I expected. It was very amateur in execution but it contained some interesting bits and pieces about AIR and CS4.

The first session I attended was by Dave Williamson. It was on the subject of localisation. It was a frustrating session, for the subject is an important one and Dave raised some interesting ideas that had not occurred to me. But it needed lots of examples and there were very few and what was there were badly done.


The other session of the morning was an introduction to AIR. This was by Mike Chambers, a product manager for Adobe. This was both professionally presented and informative.

And so we get to the ”no food” lunchtime and half of day 1 is done.