IIS Error Message – An attempt was made to load a program with an incorrect format.

If you receive the following error message when running a website (usually after deploying onto a 64-bit machine):

Could not load file or assembly ‘PROJECTNAME’ or one of its dependencies. An attempt was made to load a program with an incorrect format.

It could indicate that your web app (or one of its dependencies) was built for x86 and 32-bit applications are turned off in your application pool.

  1. Open IIS Administration Tool
  2. Click on sites
  3. Click on the site you’re trying to run
  4. On the right side, click on “Advanced Settings”
  5. A dialog box pops up with information about the site in it
  6. Look for the name of the Application Pool
  7. Close this window
  8. Click on “Application Pools” in the tree on the left
  9. Click on the Application Pool from the screen you just looked at
  10. Click on “Advanced Settings” on the right
  11. Look at the value for “Enable 32-Bit Applications”
  12. Make sure this is set to True (it is False by default)

You could also recompile your project for x64, but any dependencies you have might not work.

Issue with Joomla! – Administrator links redirecting to site root

I was setting up a Joomla! site for a client when I kept having an issue with the Administrator site. Every link in the administrator areas would redirect me to /index.php. I just about went crazy trying to find the answer.

It turns out that the $live_site variable in the configuration.php file had a value in it. I set this variable to be a blank string and everything started working as it should.

Refactoring some common VB.NET Code

One of my tasks at work is to maintain a few VB.NET applications written before I started working here. I’ve had the opportunity to learn a lot about large websites using VB.NET.

I thought I’d take a few moments to point out some common refactoring that you can do to shorten your code when dealing with If statements and boolean assignments.

Let’s start with a line of code that appends some text to an existing string if certain conditions are true.

This is simple enough, but it’s a bit redundant. Let’s look at another way of expressing this.

This uses the &= operator which just tells VB to append whatever follows to the variable on the left. We use IIf to determine what value to set based on the state of the checkbox.

Another common situation is using the value of a variable to determine the state of a boolean property. Here is some code to illustrate the “old” way:

This has some redundant code in it that is begging to be refactored. Let’s take a look at how we can accomplish this same amount of logic in a single line of code:

This tells VB to set the Visible property to the boolean value of the result of the expression to the right of the first = sign. VB will then evaluate the expression Mid(C1, 40, 1) = “Y” to come up with either True or False, which it will then assign to the Visible property. So, if Mid(C1, 40, 1) = “Y”, then the Visible property will be set to True.

Instead of using “Flags” (Dim myFlag as String = “Y”), try using Boolean values instead. “Y” and “N” are strings and must be manually converted to a boolean when setting properties. I’ve never seen a control use a “Y” or “N” as a property setting. They use True and False.

Sometimes, you need a short representation of true and false that can be easily cast to a boolean. In these cases, use an integer of 1 and 0 to represent true and false. One easy way to remember which is which is to remember that “non zero equals true”. That would also include -1 to equal true.

If you need a flag with multiple values, create an Enumeration like so:

Then, just use it in your If statements:

Check out Microsoft’s documentation on Enumerations. They are very useful.

http://msdn.microsoft.com/en-us/library/8h84wky1.aspx

VB.NET brings with it so many improvements to the Visual Basic language of days-gone-by. It’s worth it to get out there and experiment a little. Try something new. Don’t settle on what you remember doing from your old VB 6 days.

Remote Debugging Issue with ASP.NET – Unable to attach to the process

I have been trying to get remote debugging working on one of our servers so we can share the development work on a WebAPI and I kept getting the following error message on my Visual Studio 2013 Attach to process dialog:

“Unable to attach to the process. The RPC Server is unavailable”

It turns out that all I had to do was add C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe to the Firewall allow list.

I knew it had to be something with the firewall, but I was trying to discover which ports the remote debugging RPC was using so I could open them. All I had to do was add the whole process and everything worked.

Now I can happily debug the code on my server.

random musings

Follow

Get every new post delivered to your Inbox.