<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Andy&#039;s blog &#187; Programming</title>
	<atom:link href="http://blog.norman.cx/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.norman.cx</link>
	<description>Yet another rambling weblog</description>
	<lastBuildDate>Sun, 04 Jul 2010 17:33:43 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>&#8220;Every day is a school day&#8221;</title>
		<link>http://blog.norman.cx/2006/12/01/microsoft-sql-event-log/</link>
		<comments>http://blog.norman.cx/2006/12/01/microsoft-sql-event-log/#comments</comments>
		<pubDate>Fri, 01 Dec 2006 17:06:14 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.norman.cx/?p=16</guid>
		<description><![CDATA[Today's lesson was on Microsoft SQL Server. I was struggling to debug a problem inside a stored procedure that buried deep with a nested set of other stored procedures. I was getting frustrated and thought to myself "it would be so nice if I could dump stuff to the Windows Event Log from within this stored procedure".]]></description>
			<content:encoded><![CDATA[<p>One of the guys I am working with at the moment uses the phrase &#8220;every day is a school day&#8221;. He&#8217;s not wrong, rarely does a day go past when I don&#8217;t learn something new about some bit of computing technology (typically finding out a new way that some piece of software is broken).</p>
<p>Today&#8217;s lesson was on Microsoft SQL Server. I was struggling to debug a problem inside a stored procedure that is buried deep with a nested set of other stored procedures. I was getting frustrated and thought to myself &#8220;it would be so nice if I could dump stuff to the Windows Event Log from within this stored procedure&#8221;.</p>
<p>I got so fed up in the end that I went off to see whether event logging from Transact-SQL was actually possible. It is, using the <code><a href="http://msdn2.microsoft.com/en-us/library/ms186244.aspx">xp_logevent</a></code> stored procedure (which lives in the master database).</p>
<p>This is the code that I am using:<br />
<code><br />
declare @message varchar(255)<br />
set @message = '@primary_contact_type ' + cast(@primary_contact_type as varchar(30))<br />
EXEC master..xp_logevent 60000, @message<br />
</code></p>
<p>Two things to know to make this work:</p>
<ul>
<li>you have to declare the <code>@message</code> variable, you can&#8217;t just pass a string constant to the <code>xp_logevent</code> call</li>
<li>your database user needs the relevant permissions on the master database to make the call</li>
</ul>
<p>The <code>xp_logevent</code> stored procedure makes a COM call to log the message, so you probably wouldn&#8217;t want to leave the call in any production code (unless you put in a switch to turn it on and off when you needed). </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.norman.cx/2006/12/01/microsoft-sql-event-log/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Don&#8217;t get too attached to gacutil.exe</title>
		<link>http://blog.norman.cx/2006/01/20/dont-get-too-attached-to-gacutilexe/</link>
		<comments>http://blog.norman.cx/2006/01/20/dont-get-too-attached-to-gacutilexe/#comments</comments>
		<pubDate>Fri, 20 Jan 2006 10:19:17 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.norman.cx/?p=15</guid>
		<description><![CDATA[If you have ever got involved with putting .NET assemblies into the GAC (Global Assembly Cache), then you will have come across gacutil.exe
There is a problem with gacutil.exe, it isn&#8217;t part of the .NET framework and therefore isn&#8217;t installed on machines that have had the framework installed on. It is actually part of .NET SDK [...]]]></description>
			<content:encoded><![CDATA[<p>If you have ever got involved with putting .NET assemblies into the GAC (Global Assembly Cache), then you will have come across gacutil.exe</p>
<p>There is a problem with gacutil.exe, it isn&#8217;t part of the .NET framework and therefore isn&#8217;t installed on machines that have had the framework installed on. It is actually part of .NET SDK and you aren&#8217;t supposed to distribute it with your own applications.</p>
<p>If like us you don&#8217;t realise until late on in your project that gacutil isn&#8217;t redistributable then you are faced with a number of options for registering your assemblies with the GAC:</p>
<ul>
<li>use the features in your installer (not an option for us as we were using a very old version of Install Shield)</li>
<li>illegally redistribute gacutil</li>
<li>write your own code to call the GAC API</li>
</ul>
<p>I&#8217;m ashamed to say that we took option 2 as we were pushed for time and resources. At the time I couldn&#8217;t find C# code to call the GAC API and we didn&#8217;t have anyone around that could write a C++ version for us.</p>
<p>I have since found this C# code, which is supposed to achieve the task of registering with the GAC:</p>
<p><code>using System.EnterpriseServices.Internal;</code></p>
<p><code>  string path = Directory.GetCurrentDirectory() + "\\";</code><br />
<code>  Publish publish = new Publish();</code><br />
<code>  publish.GacInstall(path + "MyAssembly.dll");</code></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.norman.cx/2006/01/20/dont-get-too-attached-to-gacutilexe/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dealing with &#8220;class doesn&#8217;t support automation&#8221; with ASP Classic and .NET COM interop</title>
		<link>http://blog.norman.cx/2005/11/12/dealing-with-class-does-not-support-automation/</link>
		<comments>http://blog.norman.cx/2005/11/12/dealing-with-class-does-not-support-automation/#comments</comments>
		<pubDate>Sat, 12 Nov 2005 00:34:58 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.norman.cx/?p=11</guid>
		<description><![CDATA[I had a problem today when trying to call a C# component from Classic ASP. When I called a method in the C# component I got the error &#8220;class doesn&#8217;t support automation&#8221;.
This was very puzzling because I had already prototyped this to make sure that I could sucessfully call C# from Classic ASP (using both [...]]]></description>
			<content:encoded><![CDATA[<p>I had a problem today when trying to call a C# component from Classic ASP. When I called a method in the C# component I got the error &#8220;class doesn&#8217;t support automation&#8221;.</p>
<p>This was very puzzling because I had already prototyped this to make sure that I could sucessfully call C# from Classic ASP (using both VBScript and Javascript). The C# assembly and class were marked as <code>COMVisible</code> and I had used <code>regasm</code> to register the DLL with COM.</p>
<p>Through a process of elmination I worked out that the problem was that the method had some boolean parameters that I wasn&#8217;t initialising with boolean values in my ASP code. I hadn&#8217;t completed my ASP page, so the variables being passed to the booleans were in fact set to empty strings.</p>
<p>So the error message is very misleading, as it has nothing to do with the class you are calling not supporting automation.</p>
<p>Once I initialised my booleans correctly the problem went away, which made me a very happy bunny <img src='http://blog.norman.cx/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.norman.cx/2005/11/12/dealing-with-class-does-not-support-automation/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Don&#8217;t try and create circular project/assembly references in VS.NET</title>
		<link>http://blog.norman.cx/2005/11/10/dont-try-and-create-circular-projectassembly-references-in-vsnet/</link>
		<comments>http://blog.norman.cx/2005/11/10/dont-try-and-create-circular-projectassembly-references-in-vsnet/#comments</comments>
		<pubDate>Thu, 10 Nov 2005 18:36:46 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.norman.cx/?p=7</guid>
		<description><![CDATA[I ran into a problem today, with VS.NET and references between projects. In the development project that I am working on at the moment we have two main C# classes that are called by various classic ASP pages and client side code.
Because both of the classes have attendant helper classes and they are logically separate [...]]]></description>
			<content:encoded><![CDATA[<p>I ran into a problem today, with VS.NET and references between projects. In the development project that I am working on at the moment we have two main C# classes that are called by various classic ASP pages and client side code.</p>
<p>Because both of the classes have attendant helper classes and they are logically separate (and also being coded by two different people) we have them in two separate VS.NET projects. Until today it all worked fine.</p>
<p>Today however we broke things. Class A was already calling Class B, but in a change today we decided that Class B then had to call back into Class A.</p>
<p>Until today the project for Class A had a reference to Class B, not the other way around. When we tried to add a reference to Class B&#8217;s project back to Class A&#8217;s we got an error complaining that it could not be done because it would create a circular reference.</p>
<p>I guess the problem is that the two projects get compiled to two separate assemblies and that one can&#8217;t be built before the other because they both embed meta data from the other.</p>
<p>We scratched our heads for a while, it didn&#8217;t help that it was at the end of the day, and came up with the following options:</p>
<ol>
<li>move the two classes into the same project (this would be less than ideal two people need to work on the code at the same time and it would also stop us from shipping one of the components without the other)</li>
<li>abandon the VS.NET build process for these two components and build them together into the same assembly using the commandline tools (still has the problem of not being able to ship them separately and complicates the build/debug process)</li>
<li>create another class that sits above A and B that makes calls into A and B (A still then needs to call B, but at least B doesn&#8217;t then have to call A)</li>
</ol>
<p>At the moment it looks like we are going to go with option 3, which means some more work for me tomorrow. I hope I can do it cleanly without duplicating code from A and B into the third class.</p>
<p>So, something to look out for in my next .NET project (in our defence this project wasn&#8217;t really designed with .NET in mind).</p>
<p>Edit:</p>
<p>I have found another and I believe, better solution. I have created a interface in a separate project (that matches Class A&#8217;s current public interface). Class A can then implement the interface and pass a reference to itself cast as the interface when it calls Class B. Class B can then call back to into Class A via the interface.</p>
<p>Class A and B then need reference to the project with the interface, but crucially Class B doesn&#8217;t need a reference to Class A.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.norman.cx/2005/11/10/dont-try-and-create-circular-projectassembly-references-in-vsnet/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Avoid passing .NET XmlDocument objects to methods</title>
		<link>http://blog.norman.cx/2005/11/04/avoid-passing-xmldocument-to-methods/</link>
		<comments>http://blog.norman.cx/2005/11/04/avoid-passing-xmldocument-to-methods/#comments</comments>
		<pubDate>Fri, 04 Nov 2005 08:54:20 +0000</pubDate>
		<dc:creator>andy</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://vault.norman.cx/html/norman.cx/wordpress/?p=5</guid>
		<description><![CDATA[I have decided that when using the .NET framework's XML classes it is a bad idea to pass XmlDocument objects to methods. It is a much better idea to pass the document's root XmlNode object instead.]]></description>
			<content:encoded><![CDATA[<p>I have decided that when using the .NET framework&#8217;s XML classes it is a bad idea to pass <code>XmlDocument</code> objects to methods. It is a much better idea to pass the document&#8217;s root <code>XmlNode</code> object instead.</p>
<p>The reason for this is that at some point down the line you might, as I have today, decide that you need to use one of your methods on a sub-set of a document. If your methods are setup to receive <code>XmlDocument</code> objects then you suddenly have a lot of code to refactor to allow you to pass an <code>XmlNode</code> object from an arbitary level in the document instead.</p>
<p><em>&#8230;insert useful example here&#8230;</em></p>
<p>Passing the <code>XmlNode</code> object is just as easy as passing the document and you can still access the document via the <code>XmlNode.OwnerDocument</code> property anyway.</p>
<p>Update:</p>
<p>I discovered a serious problem with this approach today. The <code>XmlNode</code> object that represents the top level of the <code>XmlDocument</code> returns <code>null</code> from its <code>OwnerDocument</code> property! Doh!</p>
<p>How annoying is that? I can see how logically the node that represents the document itself doesn&#8217;t really have an owner document. However it seems a very pureist way of looking at it and it isn&#8217;t a very useful design decision for someone using the class.</p>
<p>So all the methods on which I carefully replaced the <code>XmlDocument</code> parameters with <code>XmlNode</code> parameters have now had to gain an <code>XmlDocument</code> parameter as well, otherwise there is no way to insert new nodes and elements.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.norman.cx/2005/11/04/avoid-passing-xmldocument-to-methods/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
