March 2009 Archives

Silverlight DataBinding and MethodAccessException

I started playing around with Siverlight earlier this week. From what I've seen so far, it looks like a very nice environment - it has (most of) the power of WPF for building user interfaces, and (most of) the power of the .NET Base Class Library to implement whatever it is that your application needs to do.

There are a few gotchas, though - especially if you have any experience with WPF. There are some subtle features that are missing, that you don't realize how nice they are until they're gone (such as binding to a static property, for example).

I encountered one such incident of this when trying to get data binding working. I first wrote my Model class, which looked something like this:

namespace SilverlightTestApp
{
    class Model : INotifyPropertyChanged
    {
        public Model()
        {
        }

        private string firstName = string.Empty;
        public string FirstName
        {
            get { return this.firstName; }
            set
            {
                this.firstName = value;
                this.OnPropertyChanged("FirstName");
            }
        }

        private string lastName = string.Empty;
        public string LastName
        {
            get { return this.lastName; }
            set
            {
                this.lastName = value;
                this.OnPropertyChanged("LastName");
            }
        }
        
        /* INotifyPropertyChanged Implementation */
    }
}

So far, so good. I then wrote some XAML to bind display this information in the UI:

<UserControl>
    <Grid Margin="5">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <TextBlock Grid.Row="0" Grid.Column="0">First Name:</TextBlock>
        <TextBox Grid.Row="0" Grid.Column="1" Text="{Binding Path=FirstName}" />
        <TextBlock Grid.Row="1" Grid.Column="0">Last Name:</TextBlock>
        <TextBox Grid.Row="1" Grid.Column="1" Text="{Binding Path=LastName}" />
        <Button Grid.Row="3" Grid.Column="1" HorizontalAlignment="Right">
            <TextBlock>Click Me</TextBlock>
        </Button>
    </Grid>
</UserControl>

In the code behind, an instance of the Model class is set as the DataContext of the UserControl, and in the click handler for the button a MessageBox is display with the name entered.

Looks good, right? Except when I run the program I get a MethodAccessException. No matter what I did, I could not figure out how to fix this error. The only thing I did know is that it had something do with my bindings, since if I took those out the error would go away. A search on the Internet didn't help much, either.

Then, on a hunch, I changed the Model class to be public instead of private, and that fixed it! Apparently in Silverlight binding only works with public classes (which isn't the case in WPF). My guess is that this is due to security - since Silverlight only runs in the browser (at least today) in a partial trust environment, Reflection (which is how binding retrieves the values it needs) on non-public members must not be allowed.

While this was frustrating, it was a good learning experience. It seems like I need to keep security in mind more with Silverlight development than with WPF.

Review: Resident Evil 5 (Xbox 360)

The main game that came with my Xbox 360 bundle is Resident Evil 5. I actually finished the single player game pretty quickly - I started playing on Friday night, and I finished it just before bedtime on Sunday. Overall, it's a pretty good game (although I had never played a Resident Evil game before, FWIW). That's not to say that I'm done playing it, however. There are plenty of other things to do.

The game has definitely shifted more towards a standard action game than survival horror - I don't know if that is a good thing or not. I'm not a huge fan of horror movies or games, so I guess for me personally that's a good thing. I could see long-time fans of the series upset by this change, though. There are plenty of big, bad monsters to destroy, though - just nothing where you jump out of your seat due to the events in the game (at least for me).

The events in the game are very much based on what has happened previously in the series. To make sure that I could actually understand what was going on, before I got the game I read up on the series itself. Both the GameTrailers Retrospective and Resident Evil Wikipedia page helped out a great deal. I could see being completely confused by the story if I hadn't done this research before hand. For better or for worse, newcomers to the series would be very confused regarding the events in the game.

One thing that sets RE5 apart from other action games is that you can't move and shoot at the same time. The left analog stick controls your movement, while the right analog stick controls the camera. Once you press the Right Trigger, though, that keeps you in place and now the left analog stick aims your current weapon of choice. While this is a drastic change from other games, at the same time it makes sense - your accuracy is greatly improved if you don't move when shooting in real life, for example. The game does help you out a bit here - most enemies come at you somewhat slowly, and tend to stop for a second or so when they get close. While that isn't necessarily realistic, it does make the game more playable. The controls didn't really bother me that much, once I got used to them.

The other big feature of RE5 is co-op play. The entire game is spent with the two main characters - Chris Redfield and Sheva Alomar. When playing solo, you play as Chris (although you can also play as Sheva once you've beaten the game). In co-op, each player takes one of the characters and you can work together to finish the levels. While I have mostly played solo, the times that I did play co-op were great - I could see that this is how the game was meant to be played. The AI did a passable job at assisting you, but it just doesn't come close to playing with someone else. It tends to go through ammo quickly, and heals you more often than is necessary. It's definitely good that a solo option is in place, though, for those who can't (or don't want to) play with another human. This is available both online and off, and while I haven't played local co-op, from the screenshots it seems like it wouldn't work very well (due to the smaller viewing area for each player).

Once you've finished the main game, there are still many things to do. There are 30 BSAA emblems hidden though the levels (the BSAA is the organization that employs Chris and Sheva). Once you get some of these, you can "buy" various items from the points that you earn for finishing levels - extra costumes for Chris and Sheva, figurines of creatures in the game, and a few other things too. There are also extra weapons to buy, and all weapons can be upgraded (once fully upgraded, you can purchase unlimited ammo for that weapon with points).

In addition, a new game mode is unlocked - Mercenaries. The objective of Mercenaries is to survive as long as possible, and killing as many zombies as you can in the process. This can also be played solo or co-op, however if you're going solo you don't have an AI partner tagging along this time. It's timed, and by default you only have two minutes (I think) to kill zombies. Scattered throughout each level is a time bonus which you can use to add time to the clock. There are also characters and levels to unlock here, too.

Overall, I'm really happy with Resident Evil 5. I could see not liking some of the changes if I were a long-time fan of the series, however given that I'm new to Resident Evil I didn't have any complaints about them. It's a great game, and it looks great too. It's definitely one that I'll be playing for a while. :)

Thoughts on the Xbox 360

Last week, my Xbox 360 finally arrived. It even arrived on the day it was released in stores, even though I pre-ordered it through Amazon. I opted for 3-5 day shipping via UPS, and even though it shipped out on Wednesday, I got it two days later. I have to hand it to Amazon - that was way more than I expected. Great job! :)

Unfortunately, I misunderstood what cables cam in the box, and I needed to buy the HD VGA cable separately. While that did add an additional $40 to the total cost, it's worth it - as I said before, I can get a much better picture on my monitor than on my TV. For sound, I had an adapter that I could use - 2 RCA female on one end, and 1 1/8" stereo jack on the other (although it turns out that the VGA cable comes with this adapter as well, which is a nice touch). I did need to buy a 1/8" to 1/8" female coupler in order to connect all that to my speakers. This all works quite well, though.

Since I bought the Resident Evil 5 bundle, I got a copy of Resident Evil 5 and Super Street Fighter II Turbo HD Remix. There were also a variety of Xbox Live Arcade trials included on the hard drive, which was nice.

While I was setting up my Xbox, I opted to start my one month Xbox Live Gold trial. While I haven't done much online yet, I really need to hand it to Microsoft - they've set up a great online system with Xbox Live. You can see what all of your friends on your friends list are doing, see what games they have, and compare achievements. PLus, all online games have built-in voice chat (there was a headset included with my Xbox, which I think is the case for most/all Xboxes too). While it isn't free ($50/year through Microsoft, although Amazon is currently offering 13 months for $40), it's definitely worth it in my opinon.

My GamerTag is Adeese, if you want to add me to your friends list, or play online with me sometime. :)

The main problem that I have right now is that I don't have many games to play. :) That will change in time, of course. I'm most likely going to get a subscription to GameFly, which is basically the Netflix of games (you can have so many games rented at a time, for as long as you want; send them back in the mail when you're done, and the next game in your queue is shipped to you). This is much more economical than buying all of the games that I want to play, since many I would only want to play once and never again (which isn't worth the $60 that most new games cost). If I do end up liking the game, there is an option to buy the game outright so I don't need to buy it separately - that's a nice touch.

Overall, I'm very happy with my purchase - Microsoft has done a great job putting the Xbox 360 together. While the Xbox 360 has had its share of technical problems (with another potential issue on the horizon, unfortunately), hopefully the worst is behind us. I also hope that my console won't fall victim to either of these issues, but only time will tell. If nothing else, hopefully Microsoft has learned its lesson, and will build the Xbox 360's successor better to avoid these issues in the future.

Win7HotKeys v1.0.2

Win7HotKeys v1.0.2 has been released. The following changes are in this release:

  • [BUG]Do not attempt to minimize or maximize a window that does not allow this operation

As always, if you have any questions, comments, bugs, etc. please let me know. :)

Review: Mirror's Edge for PC

I recently won a copy of Mirror's Edge for the PC, so I figured I would give it a try and see how it is. Given the reviews that I had read for the game, I didn't set my hopes very high. While it's not the best game ever, it was pretty good. I am glad that I didn't pay full price for it, though.

Hardware specs:

  • Pentium 4 3.0gHz
  • ATI Radeon 2400 Pro
  • 2GB RAM

At first, I thought that I wouldn't be able to play the game at all, since my PC doesn't meet the minimum requirements for the game. Thankfully, M was gracious enough to allow me to borrow her computer so that I could play through the game. It's a little under three years old, and playing at 1024x768 with most settings at "Medium", the PC couldn't always keep up with the game. If I played for a long time, the game would periodically freeze, and come back a few seconds later (generally at the worst possible time, naturally). I did get a few blue screens, but updating to the latest video drivers fixed that problem. There were still some hangs (generally when loading after dying), and every time that I exited the game it wouldn't properly reset my resolution.

Other than that, I didn't encounter any bugs in the game at all - it was very playable. The graphics were good enough, but I didn't get any of the nifty PhysX effects since I wasn't playing with an NVidia card. In any event, the graphics did their job, and weren't at all distracting.

The premise of the game is that you are Faith, and she is a runner. The idea is to keep your speed up, and then pull off some pretty crazy stunts - leaping between buildings, running along walls, etc. When it works, the gameplay is great fun. Objects in the environment turn red to indicate the direction that you can go, which helps to keep downtime to a minimum (a must in this game). There were still a few spots where I didn't know where to go, but these were few and far between.

In addition to running, there is also combat. From the beginning of the game, it encourages you to not fight the enemies, but rather run away from them. This is generally good advice, since against the tougher enemies you can go down in as little as two hits. While this is a great idea, the problem is that there are some enemies that you must kill before proceeding (generally indicated by a red glow on the mob, and sometimes a voice over from another indicator telling you that you need to fight them). If there is only one enemy around, it's not too hard - you have a variety of movies, including a one hit take down that also disarms your opponent if you time it right.

The problem comes when there are multiple enemies attacking you at once. Since you can die pretty easily, this makes your actions crucial. Your disarm attack is quite involved, and if another enemy is shooting at you while your disarm his friend, you can easily die before the animation is done. This can get quite frustrating, since late in the game it will routinely throw four, five, or more enemies at you at once. While this is doable, it does cause you to replay the same segment many times until you get lucky and kill all of the enemies perfectly without dying.

The story is good enough, but largely forgettable. It did enough to keep you playing, but nothing spectacular.

While the combat has issues, when the game works it is really amazing. When you get moving, and perform all of the movies perfectly, it's great fun and shows exactly what this game is capable of. Since there is going to be a sequel, hopefully they'll improve on the running, and downplay the combat. That would make one amazing game.