Local SharePoint Deployment + Unit Testing == Frustrating Mix

by Jon Fowler 24. February 2011 22:02

I’ve been working on a small SharePoint project this week. I have a single machine setup -  I’m developing in Visual Studio and deploying to a local installation of SharePoint

I set about writing the code, unit testing it and then deploying it into SharePoint.   However when I came to re-run the unit tests (after deployment) I got the following error:

Exception: System.MissingMethodException: Method not found

This was slightly baffling exception. The method existed…I’d just added it.

After a couple of sanity checks; I realised the tests weren’t using the local version of my assembly. It was reading it from the GAC. The act of deploying the solution to SharePoint had installed the assembly on my behalf.

I uninstalled the assembly from the GAC via the VS command prompt using:

Gacutil /u “assemblyName”

This fixed the problem but causes a re-occurring issue every time I deploy to SharePoint.

 

A couple of options that may help around the re-occurring issue (Granted none of these are ideal) :

1. Add the assembly reference to the test project as a file reference rather than as a project reference. <Yuck>

2. Remove the assembly from the GAC as part of a pre-build event of the test project. This will work but clearly will make your deployed SharePoint solution screwy.

3. Increment the assembly version number in AssemblyInfo.cs after you deploy to SharePoint. <I could imagine this being frustrating for a team setup and someone checks the version number in by mistake.>

 

If anyone has a better workaround or a way to avoid the problem then let me know

Tags:

Sharepoint

Xml Validation error when inserting paragraphs in multi-line text box controls in Word 2007

by Jon Fowler 15. November 2010 20:06

Recently whilst developing a VSTO document template, I was presented with this error whilst attempting to re-open a saved document.

‘The Office Open XML File <documentname>.docx cannot be opened because there are problems with the contents.

Unspecified error. Location: Part: /word/document.xml, Line: 2, Column: 1054’

Word offered to recover the unreadable content; but subsequently saving and re-opening resulted in the same error. I unzipped the docx file and opened the contents into an editor to discover what was breaking it…

Word 2007 allows developers to use textbox controls to position/format specific text regions within a document template. The control provides a handy way of accessing this region from code behind.

The textbox control also provides multi-line capabilities; but in the form of new lines rather than ‘Paragraph’ breaks. You can see this by turning on symbols within word:

TextBoxControl

Notice, within the text box control, pressing return inserts a newline rather than a new paragraph. Outside the control it inserts a new paragraph.

However, this protection provided by the Word UI is not enforced when programmatically setting the text. It allows the following to happen:

image

This has no noticeable effect whilst in the document. However, once you save and re-open you’ll have stumbled onto a nasty bug with no obvious way of back-tracking to the cause. The representation of the paragraph in xml actually acts as the closing tags for the textbox xml block, causing the above error.

To avoid the error, I simply changed the text string; separating newlines with ‘\v’ [rather than StringBuilder.AppendLine()]. If I’d been unable to do that then I would have investigated the word API for a method to format the text.

To fix the broken document you can either

  1. Manually fix the broken xml file
  2. Allow Word to recover the document, remove the paragraph spacing and resave the document

This bug appears to be fixed in MS Word 2010.

Tags:

VSTO

Strategy Pattern

by Jon Fowler 3. February 2008 16:16

I finally got a chance this week to finish a screen-cast on the strategy pattern. I'd been planning on doing this way back in December but life's been rather hectic since then.

Anyhow here it is: Strategy Video 

Pattern Summary

  • The Strategy pattern defines a family of algorithms, encapsulates each one and makes them interchangeable.Strategy lets the algorithm vary independently from clients that use it.

Design Principles applied:

  • Identify the aspects of your application that vary and separate them from what stays the same
  • Program to a super-type (interface/abstract class), not to a concrete implementation
  • Favour composition over inheritance

This video attempts to explain the strategy pattern. Apologies if it causes any confusion; this is my first attempt at presenting; criticism will be appreciated :-) If it does leave you confused please post a comment and maybe I can improve on it in the future.

'The most dangerous strategy is to jump a chasm in two leaps' 

From feedback received, it was clear that applying polymorphism to specify the 'Play Music' behavior has led to some confusion. Even though the individual felt they understood polymorphism, I think they had never seen it used in conjunction with an interface. Therefore I done a quick 5 minute video discussing polymorphism.

Tags:

Object-Orientated Design Principles &amp; Patterns

by Jon Fowler 1. December 2007 18:42

I was planning on doing a series of blogs about OO design patterns. It certainly is a hot topic in our offices with many differences of opinion on how you should implement software. 

My aim here is highlight the patterns I've discovered (in a 2nd hand sense :p) for other developers new to object orientated best practices.

The communication media most preferred now seems to be video; (I suppose most people would rather watch a presentation than read the presenters book) so I'm attempting to produce a few screen-casts covering OO patterns and principles. I intend them to be for beginners.

Here's a list of books that interested me:

Head First Design Patterns - Eric Freeman & Elisabeth Freeman

I found this a very good beginners guide that explains the patterns really well but also the repercussion of not applying good OO principles.

Design Patterns: Elements of Object-Orientated Software - Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides

Excellent as a piece of work: hard going for the beginner. Now that I've learnt the principles and patterns I can quickly make use of the formal definitions in this book. But I personally don't believe its the book to sell patterns to a non-believer. But it is a brilliant collection :)

Patterns of Enterprise Application Architecture - Martin Fowler

Taking things a step further with more specific patterns and best practices for the realm of enterprise applications

If my videos make you wish you'd become a painter then please comment with some constructive criticism and I'll try and improve my presentation style :) That's partly my reason for creating the videos.

 

Tags:

Hello

by Jon Fowler 1. December 2007 12:31

Welcome to my blog. I thought I'd introduce myself and the contents of this blog. This is my first experiment at blogging.  I imagine this blog will remain a place for me to discuss ideas rather than my daily activities.

I am a software developer working for Black Marble in Bradford,  UK.  I plan this blog to be relatively technical in the spirit of all thing programmer-related.

My motivation is only to share ideas with my fellow colleague's. If you don't know me then I pray not to sound arrogant, ignorant or foolish. If you do know me then..its too late, I'm not listening to you, I know I'm right :)

I must admit now I'm writing I feel a little uneasy with the concept of releasing my thoughts onto T'internet. Generally, I only have three thoughts and only one to discuss on a work blog server without fear of being fired :)

But we'll see how it goes...

Tags: