Category Archives: Code

Cool XML stuff

A bunch of XML Tools from the good people at Got Dot Net. The particular one I needed was XSD Inference, which creates an XSD from an XML document. I needed it to use with some code to validate XML against XSDs in VB6. It seems XSDs created from XML with some tools (I’m looking at you, XMLSpy — though maybe it’s fixed in later versions) won’t work properly using VB6/XML Parser 4 (which is what I’m using, at least for some of my stuff).

Please insert the Visual Studio .Net Prerequisites disk for visual studio.net

I’ve done this before, it should work: I’m running .NET on this box. I was installing .NET onto our build box here, and I kept banging my head up against step 1:

You have inserted the incorrect disk. Please insert the Visual Studio .NET Prerequisites disk for Visual Studio .NET

Hmmmm says I, it certainly seems to be labelled “Visual Studio .NET Prerequisites disk for Visual Studio .NET”. Oh, hang on, it says “Visual Studio .NET 2003 Prerequisites disk, Microsoft Visual Studio .NET Tools for the Microsoft Office System 2003”. Surely that’s the same thing? I’m installing off the “Visual Studio .NET 2003 Enterprise Architect” disk, they’re both yellow, this all seems right.

But it was not right. What I instead needed to do was grab the DVD that has all this stuff on it: it’s version includes the prerequisites right in the VS2003 install directory. Silly me. I should have known there were many versions of VS.NET. Some of them will install.

Misc stuff

Cool links I’ve found recently:

Super (MOV to AVI conversion).

VB to Java converter. That is, it compiles VB6 code into a Java class. Latest update here. Q+A. (No, you can’t download it yet, they’re still working on it.)

Oh, guess who’s on about giving away Digital set top boxes again? Yup. I do like this argument, actually: It is not the Government’s job to champion new technology. It is the Government’s job to provide universal infrastructure and manage the task in a financially responsible way.

XML Notepad, which after a looooong time not being available, is back, and upgraded. (Requires the .Net Framework 2).

Vista and Visual Studio

Which Microsoft development environments will be supported in Windows Vista?

Not the ones you might think.

  • SUPPORTED: VB 6 — ah, my old friend
  • NOT SUPPORTED: Visual Studio .Net 2002
  • NOT SUPPORTED: Visual Studio .Net 2003
  • SUPPORTED, BUT WITH “COMPATIBILITY ISSUES”: Visual Studio .Net 2005

Good grief.

So, forcing the upgrade path for those older .Net versions? Or is it that they just can’t be bothered making it all work?

Meanwhile, Australian pricing for Vista is out. $751 for Vista Ultimate?! Yowch. Mind you, who really pays for a full version of Windows? Most people would be getting upgrades from previous versions, or OEM copies. Like Office, the full pricing is always exhorbitant.

QueryInterface for interface xxx.yyy failed

My .NET web service – which wraps some legacy COM objects – wasn’t working. Development under VS2003 using .NET 1.1 worked fine in my dev environment, but in test env it just kept whinging:

InvalidCastException: QueryInterface for interface xxx.yyy failed

That’s a pretty basic failure – it couldn’t even obtain a xxx.yyy interface from the COM object. I figured it was a IIS security problem: a .NET desktop app using the same set of COM libraries worked fine.

The thing was, when I set the user account to operate annoymous web users under to local Administrator, it still didn’t help. Perhaps, I thought, this isn’t a permissions problem. Web users are now, after all, Gods.

Perhaps, Glen suggested, I was running .NET 2.0 and .NET 1.1 simultaneously?

No.

It turns out missing part was the

<identity impersonate="true" />

line out of the web.config file in the directory in which my webservice lived. Also, the lack of a web.config file in the directory in which my webservice lived caused a little bit of a problem. I didn’t realise that at the time, but found out that the impersonate setting can also go in one’s machine.config file also – but that has global implications. So I stepped back to putting it in my web service’s own web.config file.

Why does the Web Setup Project fail to include important little files, like my .asmx and web.config files? What is the point in having a wizard that just makes a installer that doesn’t install a working system? And the dependancies tree! God, just let me specify – or figure it out for yourself – the order in which to register the COM objects.

But guess what? All of that is unnecessary, if only your Installer derieved MyEventLogInstaller is set up thusly:

	[RunInstallerAttribute(true)]
	public class MyEventLogInstaller : Installer
	{
		private EventLogInstaller myEventLogInstaller;
		public MyEventLogInstaller()
		{
			//Create Instance of EventLogInstaller
			myEventLogInstaller = new EventLogInstaller();
			// Set the Source of Event Log, to be created.
			myEventLogInstaller.Source = "Josh's Web Service";
			// Set the Log that source is created in
			myEventLogInstaller.Log = "Application";
			// Add myEventLogInstaller to the Installers Collection.
			Installers.Add(myEventLogInstaller);
		}
	}


– with the RunInstallerAttribute being the super important part. Or perhaps it should read RunInstaller. But don’t worry, neither of them actually cause the installer to run them. As such, all you need do is issue the command

installutil "MyStupidWebService.dll"

after the installation program is done and you’ll be cooking with gas.

Simple, huh? No need for that nasty web.config file after all! Especially with it impersonating a dud security context.

Oh! And remember to issue a regsvr32 comcomponent.dll command also!

A dead giveaway that you haven’t run installutil is if you get an exception like this:

System.TypeInitializationException: The type initializer for "MyStupidWebService.Global" threw an exception. ---> 
System.InvalidOperationException: Cannot open log for source {0}. You may not have write access. ---> 
System.ComponentModel.Win32Exception: Access is denied
   --- End of inner exception stack trace ---
   at System.Diagnostics.EventLog.OpenForWrite()
   at System.Diagnostics.EventLog.WriteEvent(Int32 eventID, Int16 category, EventLogEntryType type, String[] strings, Byte[] rawData)
   at System.Diagnostics.EventLog.WriteEntry(String message, EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData)
   at System.Diagnostics.EventLog.WriteEntry(String message, EventLogEntryType type, Int32 eventID, Int16 category)
   at System.Diagnostics.EventLog.WriteEntry(String message, EventLogEntryType type, Int32 eventID)
   at System.Diagnostics.EventLog.WriteEntry(String message, EventLogEntryType type)


because installutil will create an entry for Event Logging, if you’ve developed the appropriate installer. And because the person running installutil has decent privileges, it will actually work, as opposed to your web service trying to do it when it’s running in a securely locked down account.

C# module entry point

I’ve made a C# Web Service. Now I need a deployment project for my Web Service. After installing, it turns out that my Web Service needs to set the security on a registry key to allow the ASPNET user Full Control. Fine. I’ll need some sort of hand-written code to do that, because security is something the installer doesn’t cover. Stumbling around the help and web, I find I need to View | Editor | Custom Actions to create a Custom Action (right-click On the Install event/action, select Primary Output from JoshsPrimaryOutput; on the properties of this new Custom Action set InstallerClass to false and set EntryPoint to JoshsEntryPointFunction). Build.

I get the error:

Unspecified module entry point for custom action ‘<name>’ in JoshsPrimaryOutput.dll

Which the help… helpfully tells me to fix it I need to

…specify a valid entry point within the DLL.

Fine, makes sense. I’m not stoopid, I’ve been a C++/Windows programmer for a very long time. I know DLLs, I know entry points, this holds no fear for me. C# has DLLimport. It seems to be missing DLLexport. I’ve just spent several hours searching online help and the web for an answer, so now I turn to you, our esteemed readers.

How do I specify a module entry point in C#?

Scott Meyers’ five top fives – EVER

I’ve been waiting for the full set to be published, before dumping ’em here:

Headlines via PHP/RSS

This utterly rocks, and I can’t believe I didn’t go looking for something like it before: MagpieRSS lets you show RSS headlines on a PHP page. I’m using it on my old toxiccustard.com page to show the latest headlines from my diary and the site’s News and Guide to Australia pages (which all run WordPress). It includes caching so you won’t burn up your (or anybody else’s) bandwidth by grabbing the feed continually.

The importance of accessibility

Raymond Chen on why accessibility is not just for disabled people. It’s also of huge benefit to automation, for testing and integration purposes (including such diverse uses as screen scraping and speech recognition).

You bet. It’s the lack of consideration for this kind of thing that gives me my pathological hatred for web sites developed entirely in Flash, or some other mutant horror of leading-edge technologies. Too often you’ll find some whiz-bang heavy commercial ad-merchant has somehow got in control of the site design for some company that should know better, and rendered the whole site unusable…

  • with the keyboard
  • by the blind
  • let alone the blind using keyboards
  • by anybody without IE6
  • or who has a popup blocker
  • or likes to use the web in silence
  • or is trying to get around the fact that the site has no RSS or web services or any other hooks, and is trying to screen-scrape/parse the HTML

Of course I can’t stop these idiots putting pages up. And they take no notice of anything anybody says about them. But in most cases I don’t have to do business with them.

One of the side-effects of sticking to accessibility and restraint in the technologies you use is that the designs tend to be more future-proof. While some web sites are breaking under Firefox, I reckon a lot more will break under IE7 when it gets pushed out to millions of XP users.