Tuesday, January 30, 2007

The type initializer for * threw an exception

The type initializer for *insert your favorite class here* threw an exception

This was driving me crazy, there's not a whole lot of info out there about this error, I should've used my psychic debugging powers (yes, I have those too =op) before

my scenario is a web service (.net 2.0) calling (deep down) into some code that does reflection to instantiate some classes, the exact same code works just fine under a web application, that's what's bizarre, how's a web service different to a web app on regards to permissions and security?

anyway, almost from the beginning I suspected it had to do with permissions, but being a web service, and the same code running fine under the web app made me leave that as a last option, so I looked and didn't find any real answer, then decided to configure a different user (with more permissions than the default asp_net) in IIS to run my web service, it ran just fine after that

ok, now I know the problem is permissions but I'm not happy with the "fix", so I'll keep looking and trying for a more elegant solution

free tip for those of you who may not know this one
enter "The type initializer for * threw an exception" in google... it's a beautiful thing, Google takes wild cards as part of a search, it works with multiple wild cards in one phrase too

Monday, January 29, 2007

formatting 0, 1 as yes, no or whatever

This is something we all have done at some point, convert a 0,1 value into yes, no, on, off, etc string

turns out there is a function in the BCL that can do this, string.Format will do the job

Console.WriteLine(string.Format("{0:yes;;no}", 0)); //will output "no"
Console.WriteLine(string.Format("{0:yes;;no}", 1)); //will ouput "yes"

and just for the heck of it
Console.WriteLine(string.Format("{0:yes;;no}", -1)); //will output "-yes"

...one of those little thingies

Tuesday, January 16, 2007

xna programming: pre-requisites

A few moons ago (WOW, it has been a while) I promised I would write a small game and post all my experiences and source code here, we did the game design, set the goals and started writing the game, then after getting sick, the holidays, updates to the XNA framework, etc, kinda stopped working on the game. anyway, I decided to pick it up and started studying xna tutorials again to see what kind of things I had done wrong due to my lack of knowledge, it seems I wasn't doing so bad so I can actually update the tools (since there is an official xna release now), modify a couple things on my code and I'm good to go

however there are a couple (big) things you need to download and install before we can continue
- Visual C# 2005 Express, you might want to NOT download the MSDN help for it though, that's an extra 2GB or so, VC#2005 Express can be downloaded here, and if you have any firewall issues you could download an offline installation (CD) here
- DirectX Software Development Kit, which includes XACT, a tool that will help you create and work with sounds
- XNA GSE (Game Studio Express), this is the thing that will allow you to create a xna project and conect all the dots so you can easily write xna apps, however beaware of the following:
  • Only supported on Microsoft® Windows® XP SP2 (all editions) at this time. Windows Vista will be available only in a future beta release of XNA Game Studio Express.
  • Hardware requirements are identical to those for Visual Studio 2005 plus a graphics card that supports DirectX 9.0c and Shader Model 1.1 (Shader Model 2.0 support recommended).
  • This release requires Microsoft Visual C# 2005 Express Edition to be installed before proceeding. You can install Visual C# Express from the Visual C# Express Download Page. However, other members of the Visual Studio 2005 line of products, for example Visual Studio 2005 Professional, can co-exist with XNA Game Studio Express on the same computer.
  • Installation of the XNA framework is not necessary on systems with XNA GSE installed
once you get all that working, take a look at the basic tutorials out there, get familiar with the API, play with it, my code won't be about teaching you C# like some of the tutorials on the provided links, I will assume you are already familiar with the language, although you might learn a technique or two but I won't be explaining C# coding, just the use of the XNA API and the overall design of the game

'til next time

Saturday, January 13, 2007

dummy interview question

is this code:
a1 = new SomeClass();
a2 = new SomeClass();

equivalent to:
a1 = a2 = new SomeClass();

(explain why)

The trick is how you ask the question, if you asked "what's the difference between option a and option b?" you are already telling them there is a difference.

Friday, January 12, 2007

Thursday, January 11, 2007

Tuesday, January 09, 2007

suggestion for google reader

I can start items and share items, that's great, how about you allow me to highlight stuff?

Thursday, January 04, 2007

just got my old new thing

now if I could get this book autographed J

got some reading to do J

Wednesday, January 03, 2007

first geek joke of the year

I tried posting more stuff yesterday but blogger.com was down, I couldn't even leave comments to other blogger blogs =o(

anyway, happy new year everyone!!

Tuesday, January 02, 2007

first post of the year

I'm in El Paso right now, it's been snowing all morning in Juarez and here, hopefully my flight won't be delayed, and what's worst, I'm flying through Denver...
anyway, I have internet thanks to my Cingular 8125 =o), we'll see how it goes today, at least I'll be reading a lot of blogs and updating my reading list