RSS Feed
Jun 15

Debugging WCF Services In Visual Studio 2008 in 32-bit Mode on a 64-bit Architecture

Posted on Tuesday, June 15, 2010 in Programming

This is for my own reference, (and for the sake of anyone Googling) since this has been driving me crazy for months. Feel free to ignore if you’re not a geek. Feel free to correct it if you are.

When building a WCF project for the x86 architecture on an x64 machine/OS (like, say, Windows 7), you will get a BadFormatException when you try to debug it. This is because WcfSvcHost.exe will run in the mode defined by your architecture, regardless of your particular build environment. Microsoft says that this is working as intended. I say boloney, but I’m a VS version behind now. (I haven’t tested VS 2010 yet.)

Here is a link to part of the solution.


corflags /32BIT+ WcfSvcHost.exe

However, the signature of this assembly is now broken, and won’t load. So to bypass that:


sn -Vr WcfSvcHost.exe

to remove strong name signature verification.

DANGER:
Don’t do that unless you know what you’re doing! That opens up a huge security risk. Do not do that in a production environment! Only do it on your dev box!

Why not just build the app in x64 or (even better) Any CPU? Because I can’t get Oracle.DataAccess in 64-bit.

Mar 2

Programming Praxis: Goldbach’s Conjecture

Posted on Tuesday, March 2, 2010 in Programming

Since I mentioned in my last post that I live in fear of the tech interview, I decided to do something about it rather than live in fear. To that end, I subscribed to a website called Programming Praxis, which publishes short programming problems to sharpen your saw on. (Well, I’d actually been a subscriber for a while, but it’s just now that I’ve actually took the time to do my own saw sharpening.)

Geek Content Ahead. Feel Free to Ignore.

Today’s Praxis is on the Goldbach Conjecture which states that any even number greater than 2 can be expressed as the sum of two primes. The challenge is to write a program that will take in an even number, and spit out the two primes that can be added together to make it.

I realize my solution is extremely naive, but it’s the first time in a long time that I’ve actually worked on programming problems other than “get data from database a, transform it somehow, and put it in database b.” Also, for extra difficulty (and speed, although my algorithm is the real speed hangup in this case) I wrote it in C.

For the one or two people still reading, here is my extremely naive solution, cobbled together while watching West Side Story on TCM.


#include <stdio.h>
#include <stdlib.h>

void show_usage();
unsigned long *create_sieve_to_number(unsigned long number);

int main (int argc, const char * argv[]) {

    if (argc != 2) {
		show_usage();
		return -1;
	}

	unsigned long number = atol(argv[1]);

	if ((number % 2) != 0) {
		show_usage();
		return -1;
	}

	unsigned long *sieve = create_sieve_to_number(number);

	for (unsigned long i = 2; i < number; i++) {
		if (sieve[i] == 1) {
			for (unsigned long j = i; j < number; j++) {
				if (sieve[j] == 1) {
					if (i + j == number) {
						printf("Solution found: %d + %d\n", i, j);
						return 0;
					}
				}
			}
		}
	}

	printf("no solution found!  pick up your Fields Medal!\n");

	return 0;

}

void show_usage(void) {
	printf("usage: goldbach [even number]\n");
}

unsigned long *create_sieve_to_number(unsigned long number) {
	unsigned long *sieve;

	sieve = (unsigned long *)malloc(sizeof(unsigned long) * (number + 1));

	for (int i = 0; i < number; i++) {
		sieve[i] = 1;
	}

	for (unsigned long i = 2; i < number; i++) {
		if (sieve[i] == 1) {
			for (unsigned long j = i * i; j < number; j = j + i) {
				sieve[j] = 0;
			}
		}
	}

	return sieve;
}

Edit: See what happens when you’re watching TV when you’re doing your homework? The flags marking numbers as prime can be a bool (or even a bit) and most certainly does not have to be an unsigned long. Yay for massive, massive wastes of memory! (But hey, I was watching West Side Story…)

Feb 23

The Dreaded Technology Test

Posted on Tuesday, February 23, 2010 in Programming

A recent post on Coding Horror about “Non-Programmer Programmers” kind of terrified me. Not because I think that my job is going away, and not because I think my skills aren’t up to snuff, but because the technical interview terrifies me like nothing else.

Jason, with performance anxiety? Yes, it’s true!

As a performer, I come from the world of improv, where the mantra is “Just make it up! What you say will always be correct!” Naturally, this level of bullshittery, while it might get you through a real interview, will never do in a technical interview where you will be eviscerated if you don’t know the systems you claim to know. (Or even some detail of a system you really do know, but had never previously used.) Now I’ve never put something on my résumé that I did not actually use, but in some cases, it’s just been a while and I need a few minutes with my friend Google to get back up to speed.

Part of the problem is that the tech interview is like flying an airplane. Once you stall once, it’s really hard not to crash and burn. You just get more and more flustered until you can’t even answer questions about things that you do know extensively.

I had an interview like that just before I interviewed for my current job. It was October/November 2001, and as you could imagine, New York City was on edge and not in a hiring mood, especially in the “dot-com” world which had gone bust. I interviewed downtown with a famous phone company for a unix administrator job. I can’t remember what question started the stall… I think it was something about rpc, or what port something listened on… But after that, I was dead in the water. They asked me a bog-simple RAID question that I totally blew. As they escorted me out of the building, one of the managers sypathetically said to me, “It must be hard getting a job in this economy…” Shellshocked, I agreed.

Reading that article on Coding Horror, and remembering that interview, kept me awake far too late last night. Again, I’m reasonably confident that my job’s not going anywhere, and I’m confident in my abilities, but one has to plan for these things.

Then today, sitting in the office that I’ve occupied for almost nine years now, I remembered a tech interview that was tough, but I knocked out of the park. (In particular, I remember totally killing a question about DNS.) Naturally, its the one that got me the job I have today. And they seem to like me after all these years, to the point where they actually let me write production code.

Scary though the tech interview may be, if I keep my skills up, keep my cool, and remember how to pull out of a stall, I should be okay. Besides, the “weed out” questions on that Coding Horror article are laughably easy. And if your tech interview feels like the Spanish Inquisition, did I really want to work for you in the first place?