Archive for the ‘programming’ Category
Generating Option Strict On Using CodeDOM
Quick Excel Macro: Remove All Pictures
I pasted some content into Excel, and while I did want the formatting, I didn’t want the pictures it included. This meant I couldn’t use Paste Special.
Solution? A quick macro to remove all shapes from the sheet after I pasted:
Public Sub RemoveAllShapes()
For Each e In Shapes
e.Delete
Next
End Sub
Snagit Accessory Installer
I’ve used Snagit from TechSmith for a year or so now and despite not being free it is without a doubt the best screen capture software I’ve used and I recommend it to anyone that asks me about screen capture software.This post actually isn’t about any of it’s screen capture capabilities but part of their installation. Snagit allows you to install what are called “accessories” (aka plugins) to add additional capabilities to the software. In fact, I’m writing this post with their WordPress.com accessory.
Plugins are certainly not a new concept by any stretch of the imagination, but what impressed me about TechSmith’s implementation is the installation process. Plugins aren’t normally a user-friendly concept because they usually involve putting files in special locations or doing special configuration.
TechSmith take away this complexity by registering a file extension (*.snagacc). These files are effectively a Zip file containing the DLLs and any dependencies of the plugin as well as a “manifest” containing information about the plugin. This file extension is registered to Snagit and the result is that simply double-clicking the *.snagacc file does all of the copying and configuration necessary for that plugin.
VSTO Deployment Error: The required version of the .NET Framework is not installed on this computer
I’ve been going crazy to try and solve a problem with a VSTO package I was publishing. Users were receiving the error “The required version of the .NET Framework is not installed on this computer” even though they had the correct .NET Framework version. It turns out that there is a file missing from the .NET Framework 3.5 installation in Windows 7 Beta/RC that causes any packages published from a Windows 7 Beta/RC machine to display this error.
For more details and the workaround read:
Arrowhead Anti-Pattern
It is a common belief that methods should have a single entry and exit point. While this is a noble goal you need to be very aware that you can detract from the readability and comprehensibility of your code simply to uphold that belief. While a single exit point is not an anti-pattern striving to achieve a single exit point can result in deeply nested “arrowhead” code which is an anti-pattern.
My basic advice to you is that you should only strive for a single exit point from your method when it aids in the readability and comprehensibility of that method, if it doesn’t then don’t get caught up in having a single exit point.
Validating XML files against an XML Schema (XSD)
UPDATE: You must set the ValidationFlags property to XmlSchemaValidationFlags.ReportValidationWarnings and you must add the event handler before calling Create on XmlReader, otherwise the event won’t be raised.
Validating XML files against an XML Schema (XSD) has changed slightly in .NET Framework 3.5 because the XmlValidatingReader has been obsoleted as have XmlReader’s constructors. The correct way to validate an XML file now is to:
- Create an XmlReaderSettings class, set the ValidationType to ValidationType.Schema, set the validation flags to report warnings, and add your schema to the Schemas collection.
- Add a handler for the ValidationEventHandler event, unusually this event is raised from the XmlReaderSettings class not the XmlReader class.
- Use the Create factory method on XmlReader passing in the path to the XML file and the XmlReaderSettings object you created above.
- Iterate through all of the nodes in the XmlReader (validation is done as the reader processes each node).
- Close the reader.
- Remove the event handler.
Here is an example:
Dim settings As New XmlReaderSettings() settings.ValidationType = ValidationType.Schema settings.Schemas.Add("http://tempuri.org/MySchema.xsd", "MySchema.xsd")) settings.ValidationFlags = XmlSchemaValidationFlags.ReportValidationWarnings Try AddHandler settings.ValidationEventHandler, AddressOf ValidationEventHandler Using reader As XmlReader = XmlReader.Create("MyInstance.xml", settings) While reader.Read() End While reader.Close() End Using Finally RemoveHandler settings.ValidationEventHandler, AddressOf ValidationEventHandler End Try
...
Private Sub ValidationEventHandler(ByVal sender As Object, ByVal e As ValidationEventArgs) ... End Sub
Unity 1.2 Hands-on Labs and Advertising Injectable Dependencies
Hand-on Labs for Unity 1.2 are now available (via J.D. Meier). Unity is a very simple and lightweight dependency injection container.
One of the features of Unity is the ability to define type aliases that allow you to define the full type name once and then use an alias to refer to it elsewhere in the configuration. For example:
<unity> <typeAliases> <typeAlias alias="IClipboard" type="MyApplication.Services.Clipboard.IClipboard, MyApplication" /> </typeAliases> </unity>
While working through the examples in the hands-on labs it occurred to me that this is a good way of advertising the different dependencies that can be injected. By defining a type alias for each of the dependencies that can be injected (both mandatory and optional) then developers wanting to extend your application can easily see the available dependencies.
For example:
<unity> <typeAliases> <!--Mandatory--> <typeAlias alias="IClipboard" type="MyApplication.Services.Clipboard.IClipboard, MyApplication" /> <typeAlias alias="IStore" type="MyApplication.Services.Store.IStore, MyApplication" /> <!--Optional--> <typeAlias alias="ILogger" type="MyApplication.Services.Logger.ILogger, MyApplication" /> </typeAliases> </unity>
Inside the Microsoft® Build Engine: Using MSBuild and Team Foundation Build
I’m proud to say that after many months of work Sayed Ibrahim Hashimi and I have completed work on Inside the Microsoft® Build Engine: Using MSBuild and Team Foundation Build (PRO-Developer). It is being published by Microsoft Press and is due out on 7th January 2009.
Documentation Is There For A Reason
Michael Kaplan’s post “y? Because it’s documented that way!” raises a good point about undocumented behaviour. Basically, just because it works doesn’t mean you should, unless it’s documented that is. If you rely on undocumented behaviour you are exposing yourself to a higher level of risk when the API you use is revised.
Whether one looks at the Custom Date and Time Format Strings used by things like DateTime.ToString(string) or the strings in GetDateFormat or the strings in GetTimeFormat, it is clear that some characters (like H and M) have specific meaning attached to the cased variants.
In my book, since only the lowercase y is used here, the uppercase behavior is undefined — if it works then have fun but you really shouldn’t; if it fails then you kind of asked for that failure….
And more importantly, if the meaning changes in the future then that is also something requested in the improper use. and the nature of H vs. h and M vs. m kind of underscores this.
Installing SQL Server 2005 On Windows Vista/IIS 7
While doing a SQL Server 2005 installation on Windows Vista I received a warning during the System Configuration Check stating that IIS was required although I already had IIS installed.
After some searching I found the following knowledgebase article http://support.microsoft.com/kb/920201 which describes how to resolve the warning.
