DevelopMENTAL Madness

Tuesday, May 26, 2009

ASP.NET: System.BadImageFormatException

If you are running IIS 7 on Vista x64 you may get this error:

System.BadImageFormatException: Could not load file or assembly 'XXXX.XXXXX' or one of its dependencies. An attempt was made to load a program with an incorrect format.

By default IIS 7 won’t load x86 (32 bit) assemblies, make sure you set your application pool’s “Enable 32-Bit Applications” setting to “True”.

Internet Information Services (IIS) Manager > Application Pools > {Your App Pool} > Advanced Settings > Enable 32-Bit Applications

If this still doesn’t work. Try changing your build configuration platform setting for each project in your solution from “Any CPU” to “x86” and then rebuilding your solution.

Right-click Visual Studio Project File in Solution Explorer > Properties > Build > Platform

Labels: , , ,

Monday, May 25, 2009

Installing Windows 7 On My New G.Skill SSD

I got a new 128GB G.Skill SSD drive Thursday and I’ve been repaving my laptop with Windows 7 x64 RC. Overall this has been a really smooth experience. I admit most of my excitement is about my new hard drive and I chose Windows 7 because I read it is optimized for Solid State Drives and I wanted to get the most out of my new purchase.

The first thing was that Windows install time was about 30 min. This was my first confirmation that I was gonna love my new drive.

The first thing I installed was Visual Studio Team System. VSTS 2008 install time was about 10 min and I’ve been bragging about it to my co-workers since. But then installing the MSDN docs took about 30 minutes. Also SP 1 took pretty long, which didn’t seem any faster than normal, I didn’t actually note the start/end time. These two installations were an indication that not everything was going to be blazing fast. I’m finding that this is reflective of most things in my experience. I don’t know what the MSDN docs installer is doing besides copying files, but since SP 1 was also pretty slow I imagine that it’s the Visual Studio integration stuff that slows things down.

Oracle 10gR2 Client

The first hiccup I ran into was installing Oracle client software. I ran the Vista x64 installer and after starting the installer I was immediately informed that the installer required Windows. 6.1. Fortunately I found this post which directed me to run the installer from the command-line like this:

setup.exe –ignoreSysPrereqs

MS LifeCam

I bought a new web cam about 2 weeks ago, so I was pretty sure I wouldn’t have a problem with this at all, but the 2.5 client install disk wouldn’t run. Instead I was prompted by Windows to get an update from Microsoft and it downloaded and installed the 3.0 client for me.

I was really impressed by the experience because after the install failed I was pretty bummed. I had purchased the web cam for my upcoming trip to Cancun so we could video chat with our kids while we were away. I only have one laptop and I immediately thought I was going to have to stick with Vista.

But Windows immediately detected the problem, checked the Microsoft site for an update and pointed me to the download link.

Dell nVidia Drivers

This was the only driver that had any problems out of the box. When I say problems I mean, it didn’t support the widescreen resolutions and I had to go to dell and download the Vista x64 drivers. But once I downloaded the drivers from Dell the installation was smooth and was done in about 30 seconds.

Toad 9.0.1.8 and Oracle 10gR2 Client

I had a little trouble here. I’m running the x64 version of Windows 7 and ran into the “can’t load oci.dll” error. There are two reasons for this problem. First, Toad is an x86 client and so it can’t load the x64 dlls. Second, Toad is looking for ORACLE_HOME under HKLM\Software\Wow6432Node\Oracle and the x64 client installs under HKLM\Software\Oracle. Turns out you need to load the x86 version of the Oracle client along with Toad and this should take care of things.

Where the heck is it?

There were a couple things that alluded me from the start. Where are the folder options? And, how do I map a network drive? The fact that these were missing really annoyed me, since they have been right in the same place for so long – in Windows Explorer, right where they belong. I haven’t looked yet, but I’m hoping there’s an option to put them back.

Folder Options

Control Panel > All Control Panel Items

I couldn’t find how to navigate to this window and I don’t know yet what category this is under, but the nice thing is if you just type in “Control Panel\All Control Panel Items” into your Windows Explorer address bar you’ll get there.

Map Network Drive…

To map a network drive I found the command under the “My Computer” context menu:

Start Menu –> Right-click “My Computer” –> Map Network Drive…

First Blush

Windows 7

My overall first impressions of Windows 7 are good. Other than the video drivers, my experience hasn’t been any different than normal complications you’d experience when running a 64-bit Windows client. I tried running XP x64 when it was released and ended by giving up, so I’ve been pleasantly surprised. I’ll continue to update as I run into other problems in order to help those who run into the same problems.

G.Skill SSD

This is just awesome! Everything screams: boot/reboot, opening applications (including Visual Studio), installing applications, Windows Explorer, file deletions, extracting large ISO files (Visual Studio, Office 2007) and the list goes on and on. I can multitask I/O-intensive operations without batting an eye. Before I had to try and keep heavy I/O lifting to one item at a time. Now I can run multiple operations at the same time. I couldn’t be more pleased.

Labels: ,

Windows Critics: Get a life

I was working on a Windows 7 post about my installation experience and I ended up in a rant. So I decided that I should move my rant to a separate post where it belongs.

Two criticisms that I have heard leveled at Windows 7 are:

  • It’s too soon (3 years) to roll out a new OS.
  • It’s just a Vista service pack

I’d like to take a minute or two to answer those from my own perspective. First to the criticism that it’s too soon. The first time I read a post to this effect the author actually said it was too short a time frame to rewrite the OS. I really have to say this is a ridiculous assumption that operating systems by any vendor (or any software for that matter) is rewritten for every release. Rewrites are the exception to the rule when it comes to software, hardware, manufacturing…you name it.

Now, to disregard the word “rewrite” for a minute let’s look at the actual time frame. Here’s a list of the release dates for the main line of Windows Client releases:

  • Windows 1.0 - 1985
  • Windows 2.0 - 1987
  • Windows 3.0 - 1990
  • Windows 95 - 1995
  • Windows 98 - 1998
  • Windows ME - 2000
  • Windows XP – 2001
  • Windows Vista – 2006
  • Windows 7 - 2009

With the exceptions of Windows 95 (a major overhaul) and Windows Vista (a complete rewrite). All Windows releases have been within 3 years.

There’s been a lot of talk about how Windows 7 is just Vista SP 3 and I have to say there really is a lot that’s like Vista. The fact that I’ve had no unsolvable compatibility issues and the similarities in the UI support it. However, the same things could have been said about Windows 95, 98 and XP. Windows 7 has improved upon the Vista performance issues enough to run on XP hardware and netbooks. I’m not going to go into a feature list, but there is also enough new features and improvements that it justifies a new release.

I only started using Vista after SP 1, because it was a complete rewrite and I believe the initial criticisms of Vista were certainly justified. But since SP 1, Vista has been extremely stable and easy to use. My favorite example is running Vista as a standard user instead of an administrator. I don’t ever run as an administrator anymore. I started doing this in XP, but it was always a pain. Vista has made this extremely easy. When you need admin privileges in Vista you get a prompt for the admin password by the UAC. If you enter the correct password you never see the prompt again. Of course the UAC is annoying, the idea was to get users to stop running as administrators – the biggest security hole there is.

I understand if people don’t like Vista, but what annoys me the most is when it becomes illogical. That anything Microsoft creates is proclaimed junk before it’s even tried. The day is too short to go into all the complaints there are about Windows. But at the end of the day when you consider that I can run Windows on ANY hardware instead of being locked into a limited configuration or having to bend over backwards by writing my own patches to the operating system (I realize Linux has come a long way, but if we’re gonna judge based on all past performance this is a fair comparison) I think people should just get off their high horse and accept that Windows does an incredible job of meeting the needs of most users. If it doesn’t meet your needs then use something that does and get a life.

Labels: ,

Thursday, May 21, 2009

Lost in Translation: Oracle 10g2 client hell

This is a post I’ve been meaning to write for a while. I had quite a bit of trouble getting the Oracle client working properly since I started with my current client. I’ve never used Oracle before and so it’s been pretty frustrating since I’ve wanted the opportunity to work with it for a long time. But it turns out that the solutions have been pretty simple. Here’s a list of some of the problems I’ve run into and their solutions:

  1. Use Admin install – When it comes to software/services that open up ports to the outside world I’m a fan of installing only what I need. So I was disappointed when our DBA told me that my first problem was that I needed the Admin install and that Instant client didn’t have everything I needed. But I’m thinking I’ll try Instant Client again now that I’ve resolved my other problems which I think were the cause. If I ever get around to it, I’ll update this post.
  2. Make sure you have Vista installer – I was given an installer for Oracle client that was stored on my client’s LAN, so that was the one I used. But it turns out that the installer wasn’t compatible with Vista. Oracle has a specific client for both the 32-bit and 64-bit versions of Vista. Make sure you’re using the right installer.
  3. Make sure ORACLE_HOME environment variable matches the path to your client installation (the parent folder of your bin directory). You need to make sure the correct values are in the following places:
    • HKLM\Sofware\Oracle\ORACLE_HOME – this should be the path of your oracle home folder (the parent folder of your bin directory, but not including “\bin”). If you accepted the defaults during installation it should be something like: C:\oracle\product\10.2.0\client_1
    • PATH environment variable – this should be the full path to the “bin” directory. Using the same setup as above this should be: C:\oracle\product\10.2.0\client_1\bin.
    • Also, you may need an ORACLE_HOME environment variable. You can add this and assign it the same value as the registry key above.

Errors

Can not load Oracle client library oci.dll from home

I had this problem trying to load TOAD and when I finally thought about it things made sense. TOAD couldn’t find the bin directory based on the paths in PATH and ORACLE home. Make sure you check #3 above to verify all this is correct.

I also had a variation on this error when I was running a 64-bit OS. You’d think you should install the x64 Oracle client if your OS is 64-bit. But since TOAD is a 32-bit client you’ll need to install the x86 Oracle client. (See #2 above)

Can not load Oracle client. Check your PATH environment variable and registry settings

This was the error I got from DevArt’s dotConnect client for .NET Entity Framework. Unfortunately, the problem here was still causing me headaches even after I got the paths right. I also had to make sure that I had the Vista client installed. Once I did this, I no longer had this problem.

Labels: ,

Visual Studio Testing: Code Coverage Property Window Crashes

Problem: If you are using Visual Studio testing tools and you open your testrunconfig file to update or turn on code coverage it closes/crashes immediately.

Workaround: If your solution contains a Silverlight project (not Silverlight Class Library, these are ok for some reason) or a WSSF project (Web Services Software Factory) you can unload the project (right-click project in Solution Explorer, select “Unload Project”). Once you have done this your code coverage will work and you can open the property window for Code Coverage in your testrunconfig file.

Labels: , ,

Wednesday, May 20, 2009

ASP.NET MVC Globalization/Localization: Referencing Resource Files in Your View

I’ve been using ASP.NET MVC since Preview 1 (Nov 2007). When I need to reference a Resource File (.resx) in my View, I just do the following:

   1: <%=Resources.MyResourceFile.MyResourceKey%>

Until today, I took that for granted. I received an email this morning referencing this post on ASP.NET. The post was about using Resource Files in an MVC View. I replied to the original post in February 2008 and then forgot about it. Today, I was asked how I got this to work. Since I hadn’t ever given it much thought – it just worked – I dove in a bit to answer the post and here’s what I got.

Create Your Resource (.resx) File

There are 3 ways to create a Resources file in an ASP.NET application (MVC or WebForms):

  1. Add New Item: Right-click anyware –> Add –> New Item…
  2. Add to App_GlobalResources:
    1. Right-click your project –> Add –> Add ASP.NET Folder –> App_GlobalResources
    2. Right-click App_GlobalResources –> Add –> New Item…
  3. Add to App_LocalResources:
    1. Right-click a folder –> Add –> Add ASP.NET Folder –> App_LocalResources

Local Resource Files

1 and 3 are essentially the same, I’ll refer to the result as a local resource file.When you create a local resource file all you need to do after you’ve added a view string values to the file is change the “Access Modifier” setting to “Public”.

VSResourceFile

The only difference (as far as I can tell) between 1 and 3 is that the default value for Access Modifier for 1 is “Internal” and for 3 it’s “No code generation”. There may be some differences with regard to WebForms, but honestly I never noticed before.

Global Resource Files

Number 2 is just as easy, but there is a little more to explain, and here’s why: you can’t change the Access Modifier for a Global Resource File. If you create a Global Resource File and open it you’ll notice the option is disabled.

VSGlobalResourceFile

The only option for a Global Resource File is “Internal”. It reads public on the toolbar. But if you look at the designer.cs file you will see that the class and all its properties are marked as “internal”.

However, you can still easily use a Global Resource File, with just one caveat. Intellisense doesn’t quite work the way you would expect (or maybe you would). The namespace will show up on intellisense, the class name will not, but once you have correctly typed the namespace and class name you’ll get intellisense for all your keys.

Here you see the namespace in intellisense:

VSIntellisenseNamespace

Here you see nothing comes up for the class:

VSIntellisenseClass

But here you see the keys are picked up by intellisense once you enter the class name correctly:

VSIntellisenseProperties

The funny thing is that this is not always true. Sometimes you will get intellisense for the class name and sometimes you won’t. Either way you can either use Local Resource Files or as suggested by Steven Sanderson in his book Pro ASP.NET MVC Framework (Apress) you can create a separate Class Library Project for resources and just make the visibility public.

I’ve seen extension functions written for access to resources and frankly this seems the simplest way. Not to mention you get compile checking and intellisense support. I really don’t like having to type in string keys, I make too many typing mistakes to trust myself in that way.

Labels: ,

Thursday, May 14, 2009

LAMP.NET (Linux Apache Mono.NET PostreSQL)

As an ASP.NET developer I’ve always worked for companies which had little or no support for any environments other than Windows. But the situation is reversed at my current client. Most development is done in Java or PHP with an Oracle back end.

As a Microsoft developer I am in the minority here. The project I am working on is an ASP.NET rewrite of a rare classic ASP application within the organization. During ramp up, we decided that ASP.NET MVC would be a good fit (an a whole lot of fun).

The project is going well and there is a company conference coming up where I’ve been asked to speak on MVC. But since .NET developers are the minority I thought it would be interesting to more attendees if I were to include a demo of using MVC with Mono. As I was thinking about the title of the presentation I was trying to think of a way to indicate that I would also be addressing use of Linux and Apache in the hopes of generating more interest (nobody wants to be the presenter who only gets a couple of attendees to show up for their session).

Since Mono was first developed for Linux the LAMP (Linux Apache MySQL PHP) stack immediately came to mind. As I thought about it I considered the fate of MySQL being included in the Oracle/Sun acquisition/merger. Additionally, I’ve always been more interested in PostgreSQL than MySQL (I’ve never really used either, but I’ve installed both at one time or another). So I tried to think of an acronym. Initially I considered LAMP 2.0, but that didn’t seem accurate since it would indicate a new release or an update, this is just a different stack.

Then after a few minutes in the shower (my second favorite place to think) the acronym LAMP.NET came to me.

I’ve already confirmed via Google that this is possible, including using a System.Data.Linq implementation for Mono. Now, I’ve just got to put together a virtual machine with the integrated pieces of the stack.

Because someone will mention it, yes I considered Oracle since that is the database of choice where I’ll be giving my presentation. I may still use Oracle, but I just can’t see much response to a presentation addressing LAMO.NET ;).

Labels: , , , ,