Archive for January, 2008

Debugging K2 [blackpearl] using the K2 Server Console

I’ve been trying to help the guys a K2 diagnose a problem with my workflow and it seems one of the trade secrets at doing this stuff is it is to put a ‘Console.WriteLn’ (Standard C# syntax) statement in the relevant place and use the K2 [blackpearl] server console to view the output produced.

So the first thing you need to do is to select a workflow event that you want to debug.

Figure 1: selecting an event to debug in Visual Studio

Figure 1 shows how to get to the C# code. You’ll need to identify which part of the code to put the ‘Console.WriteLn’.

Figure 2:  The K2 [blackpearl] server console

Next you’ll want to see the K2 [blackpearl] server console - to do this

  1. Stop the K2 [blackpearl] server service using the management console services page
  2. Run the K2 [blackpearl] server by navigating to the start menu and right clicking on the shortcut to the K2 [blackpearl] server.
  3. Select the ‘Run As…’ option (you can also locate the executable and do as described: here)
  4. Enter the credentials for the K2 [blackpearl] service account that you specified when installing K2 [blackpearl] on your server
  5. You should now see a window similar to that shown in Figure 2.

If you fail to give the correct credentials, or try to run as the ‘current user’ (i.e. You!) the server will probably not start and you’ll get an error message briefly, and then the server console will close.

Note: I am assuming a development server setup, where the K2 [blackpearl] server is local to the machine that I am running Visual Studio on, if your K2 [blackpearl] server is running on another machine you’ll need to run the K2 [blackpearl] console on that particular machine.

Figure 3: Example of a debug statement inside a workflow event 

Figure 3 shows some example debug code, and if you look carefully, you’ll see my debug being produced in Figure 2! :-D

The K2 [blackpearl] server console will be very useful to me in the future, and it can be used to diagnose failed deployments, authentication (Kerberos) issues and workflow logic issues (if you know what you are looking for…. but it’s not rocket science).


Disabled File Name entry

You may wonder when and how the file name options are ever disabled. Well I found one special case when you cannot specify a file name - when you upload from an XML attachment (InfoPath attached document field)

Figure 1: SharePoint Upload Documents (from XML attachment) wizard

Figure 2: Document destination page, with disabled file name edit control

Here’s the proof


Getting the file name of an InfoPath attachment

There will be a time, let me tell you :-) that you’ll want or need the file name of the document that one of your users has attached to your InfoPath form.

You’d think that this functionality would come out of the box… but no!

There’s no easy way of doing this, as I’ve had to knock up some simple C# code to go behind my InfoPath forms. See below:

    public void RetrieveFilename()
            // TODO: Verify correct XPath for this InfoPath form
            IXMLDOMNode opnXN =

            byte[] attachmentNodeBytes =

            // Position 20 contains a DWORD indicating the length of the
            // filename buffer. The filename is stored as Unicode so the
            // length is multiplied by 2.

            int fnLength = attachmentNodeBytes[20] * 2;
            byte[] fnBytes =new byte[fnLength];

            // The actual filename starts at position 24 . . . 
            for (int i = 0; i < fnBytes.Length; i++)
                fnBytes[i] = attachmentNodeBytes[24 + i];

            // Convert the filename bytes to a string. The string 
            // terminates with \0 so the actual filename is the 
            // original filename minus the last character ! 

            char[] charFileName =
            string fileName =new string(charFileName);
            fileName = fileName.Substring(0, fileName.Length - 1);        

            // TODO: Verify correct XPath for this InfoPath form
                = fileName;

            // The file is located after the header, which is 24 bytes
            // plus the length of the filename. 
            byte[] fileContents = 
             new byte[attachmentNodeBytes.Length - (24 + fnLength)];
            for (int i = 0; i < fileContents.Length; ++i)
            fileContents[i] = attachmentNodeBytes[24 + fnLength + i];

            // TODO: Add correct MOSS site URL
            string SiteURL = "http://my/sites/newse/newdoclib/" 
               + fileName;
            SPWeb site = new SPSite(SiteURL).OpenWeb();
            site.Files.Add(SiteURL, fileContents);


        catch (Exception e)// TODO: Write better error handler

        // The following function handler is created by Microsoft Office. 
        // Do not modify the type or number of arguments.
        [InfoPathEventHandler(MatchPath = "/my:myFields/my:attachedDoc",
           EventType = InfoPathEventType.OnAfterChange)]
        public void attachedDoc_OnAfterChange(DataDOMEvent e)
            // Write your code here to restore the global state.

            if (e.IsUndoRedo)
                // An undo or redo operation has occurred 
                // and the DOM is read-only.

            // A field change has occurred and the DOM is writable.
            // Write your code here.

Thanks should go to Pranab Paul for providing me the initial idea for this code snippet. Also note that you’ll need to add the various using statements for the XPath and XML classes to be available.


K2 [blackpearl] InfoPath Integration

My organisation likes InfoPath, as it is available on everyone’s client machine (Corporate Office 2003) it makes it a useful tool for filling in forms and the like.

I’ve been trying (and failing) to use InfoPath to enable users to upload a document (e.g. Excel, PowerPoint, Word or even CAD drawings etc.) and coax them into filling in some metadata as part of the process.

Figure 1: The InfoPath form in question

Figure 1 shows the first knockup of the type of form the management will be expecting the users to be filling in.

K2 [blackpearl] however, seems to have other ideas… K2 [blackpearl] allows me to specify a ‘K2 field’ which in this case is an InfoPath field containing the Unicode attachment [the document], and it will enable me to be uploaded to a SharePoint library without having to write any code!

Figure 2: The K2 [blackpearl] SharePoint documents wizard 

My workflow is started when the user submits the form shown in Figure 1 and Figure 3 in action. It is then supposed to take the attachment and add it to a SharePoint document library.

Figure 3: A user filling in my form and attaching a document

Figure 4: The error message! 

I am however, greeted with an error in my error log as shown in Figure 4.

I have no idea why it thinks my path is too long, or what I could have done to cause it to create this error message. Does anyone out there know what could cause this?

I’ll keep playing, and submit a support ticket with K2


Microsoft Enterprise Search Workshops

With all my talk about Searching, I thought it would be a very good idea for me or one of my colleagues to attend on the these workshops.

Further information can be found: here.


Needle in a haystack - the enterprise search conundrum

With over two million documents created for some of our more major projects, the question of how to search and indexing them is becoming more and more difficult to avoid.

Windows Search 2008 

As a MOSS orientated company, it’s easy to sway towards Windows Search 2008, in which Andrew Woodward [MVP] (among others) is a pioneer, so I read his blog whenever I can to see how this new technology is able to leverage our current search capability (also check out SharePoint user group UK [SUGUK] for examples and discussion about a demonstration he conducted this month).

Google Search Appliance

I’ve also been looking at the Google Search Appliance as if it lives up to what it promises, it in theory should be a plug and play search solution. This should certainly appeal to the people with the money as it is a hardware and software solution in one nice neat yellow box, we’ve affectionately nicknamed it the ‘cheese server’ as it looks like a slab of Swiss cheese from the front - but looks aren’t everything - it’s functionality, total cost of ownership and return on investment that matter!

On the surface it seems that both Microsoft and Google have produced similar products in very different packaging… having used neither product, I’ve so far been relying on the rest of the world to harbour any opinion over which would suit our customers best.

In typical Microsoft fashion, they’ve offered an express version of the Windows Search 2008 system for free, with no limit on the number of documents that can be indexed, this is presumably to take out the competition as Google have set hard limits as to how many search items can be indexed.

Thunderstone Search Appliance

I shouldn’t forget of course, another competitor company Thunderstone who have another rival product in their flavour of  ’search appliance’.

I’ll have to do a little more digging, ask some of the experts and perhaps have a play with some of them to see how they will interact with some of our more disparate systems such as Telelogic Doors, Meridio and Borland Star Team.


K2 [blackpearl] - the solution to JIT Debugger error and the mystery "Error Receiving Buffer"

It would seem, the chaps at K2 know about the problem, and it’s a little featurette (if such as word exists).

So if you are as unlucky as me to stumble upon this issue there are three things to check

  1. Your project might contain a corrupt SmartObject in which case you will have to identify and recreate it…
  2. The (kprx) visual studio project file might contain a closing tag on a seperate line, in which case you will have to open the *.kprx file in Notepad (or another text editor) and make the changes in the DataField nodes, where it is most likely for this oddity to occur. The most common reason for this issue is entering a description for an object in the project that contains a trailing carriage return
  3. The Windows Network Load Balancing service (NLB) is incorrectly set/installed or configured and reinstalling this component may fix the issue.

So… which one of these fixed it for me…. well Figure 1 illustrates this nicely. When you make the alteration, you may find that visual studio managed to put back the offending carriage return, if this happens, delete the item you have the description on, and recreate it without a trailing carriage return and all should be well.

Figure 1: Trailing Carriage Return leading to Serialization issues when deploying to the K2 Server

I hope this helps some of you guys out as it’s a tricky one


Next Version of SharePoint available in 64 bit architecture only!

If you want to do the background reading that I’ve done on the subject it will be worth your while looking at

  1. Steve Smith’s Blog - link
  2. Microsoft’s TechNet Service Pack 1 documentation - link, and also mirrored on this site here
  3. Gary Bushey’s Blog - link
  4. .. and on the SharePoint User Group UK - here

All of this has definitely got me thinking about what specification our next farm server needs to be… and I’ll be pushing the Hardware guys at my company all the way now to make sure we get 64 bit hardware to satisfy the requirements of the next release of SharePoint.

Microsoft outlays the reasons for using a 64 bit architecture - here, however for those like me out there who are being asked to tighten the purse strings on hardware are having to make use of older 32bit machines, who’s original task was to host SharePoint versions 1 and 2. This all in all means I’m going to have to be one damn good salesman when I have this discussion with the people with the money :-D

The great thing is that this shouldn’t affect developers too much, so I’m happy… why you ask… well I use VMware visualizations extensively and it’s great to know that you can host a 64 bit guest on a 32 bit host - see here. I’m not sure whether Microsoft Virtual PC supports something similar, but my guess is if it doesn’t now, it will do in the future. VMware versions 5.5 upwards support this feature.

There are some things that you need to be aware of though, your host machine will need a supported CPU (and motherboard in some cases), personally I’d make sure you have an Intel chip for the following reasons, your 32 bit CPU must support the EM64T standard along with support for Intel VT (Virtualization Technology or Vanderpool Technology).

AMD chips do support this feature, but I’ve only tried this so far with Intel chips. You need to make sure your AMD supports the AMD 64bit virtualization feature (AMD-V for short)


Starting K2 [blackpearl] Workflow using a SharePoint new item added event

I’ve got a workflow that initiated when a document is added to a library, it seems to work fine when a “new” document is created in the library, but fails to work when a document is “uploaded”.

My assumption is, (it could be a wrong assumption) because the error is related to missing meta data (Figure 3) that I use later in the workflow (as set up by the user when a document is created or uploaded to the library), that meta data is handled differently by K2 or SharePoint depending on whether an upload or new item added event has taken place.

As there is no particular event to catch when a document is uploaded, how should I be handling this situation?

I’ve selected “Item Added” as this seems to work with new documents (as shown in Figure 2) and it does kick off the workflow when a document is uploaded. 

What should I select to cope with uploaded documents?

Figure 1: The Workflow and SharePoint Event integration

Figure 2: Inside the SharePoint Event integration wizard

Figure 3: The Error message in a later workflow item requiring document meta data (the destination user)

Again, thanks for any advice you can provide me :-)


See for the K2 Underground post on this issue

K2 [blackpearl] JIT Debugger Error

Some background on this would probably help.

I’ve been working on this workflow for a few weeks now, and reached a limitation of either SharePoint, K2 or myself in that I couldn’t think of a nice way to convert a username e.g. SDSRESTROOM\MGALLEN to an email address.

I can’t use Active Directory for this, as I’m dealing with SharePoint users, so the dev team here came up with some simple .NET code running as a K2 server event that does a crude mapping of username to email addresses - this has it’s limitations though as we’ve not been able to get it to work with SharePoint groups yet. I don’t think the code is the problem though, as it seems to build okay, and it works as a .NET class library outside the K2 Development Environment.

Figure 1: Application Event Log

Figure 1 illustrates the error I’m getting when I try to deploy my workflow. Unhandled excepton occurred in K2HostServer.exe (System.Runtime.Serialization.SerializationException)

The interesting bit of the error is that it informs me that the “Debugger could not be started because no user is logged on”

Figure 2: The Workflow event that I added to cause chaos! 

A Server Event wizard, with some C# code behind that accesses the SharePoint site using the Microsoft.SharePoint assembly - if you want to do this yourself, you need to click on the project assembly icon in the K2 Designer and add this to your project - you can’t do it as if you were developing traditional SharePoint web part of C# class libraries.

It also hooks into some Data Fields that i’ve created through the K2 Object Browser.

Figure 3: The Code and the error at the bottom of the picture

“Error Receiving Buffer” is the error I get, which lead me to the event viewer output in Figure 1.

Any pearls (no pun intended) of wisdom for me on this?

Many thanks,


You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.