No Free Time

Because my therapist says I need to let things out

Archive for January, 2009

Explanation for a weird Visual Studio 2008 Silverlight 2 issue

Posted by andrewmyhre on January 22, 2009

I ran into a weird and annoying Silverlight/Visual Studio quirk today which cost me a little bit of time to work out the cause of, so here’s my story in case it helps anyone else out.

If you’re building a Silverlight Page/UserControl and you run it and instead of seeing your lovely application appear you see something like this:

 

 

(line 1, col 26): Unknown attribute xmlns on element WallContentView”]weird error

Sys.InvalidOperationException: Invalid XAML for control 'Xaml1'. [

 

And you notice in the XAML where you have included your control some blue lines:

 

 

021

 

And when you place your mouse cursor over the lines you see something incomprehensible, like this:

 

 

“]031

AG_E_UNKNOWN_ERROR [Line: 49 Position: 51

 

I did today. After trying essentially random and arbitrary things to solve the issue (deleting and recreating the control, renaming the control, removing sections of XAML and code from the control) I finally narrowed it down to this:

 

 

041

 

In my constructor I was causing an null reference error, but it was being reported as a XAML error! How bloody confusing.  And the reason this didn’t twig immediately is that I didn’t realise the XAML editor actually creates instances of the control tree and invokes the constructors of the controls in the process. Never occurred to me before, but makes total sense.

Anyway, so I fixed my code:

051

 

Rebuilt the solution and checked the containing control’s XAML:

061

 

No more blue lines – nice. Finally I ran my test page and lo and behold it worked!

Posted in .net, silverlight, visual studio 2008, xaml | Tagged: , , , | Leave a Comment »

The Sharepoint Development Experience – Part 1

Posted by andrewmyhre on January 15, 2009

I want to describe the development process involved in creating a web part for a Sharepoint site, hopefully to dispel the belief that it’s difficult and time-consuming. What I want to demonstrate is that it’s actually very simple – no more difficult than creating a custom control in ASP.Net 2.0 – provided you have set up your development infrastructure correctly.

Development infrastructure is where most of the pain associated with Sharepoint development really exists, which is why following this article I’m going to continue with a series describing how you can set up the various parts of your infrastructure to enable friction-free development.

This post, however, will show you exactly how friction-free it can be. I’m going to show the steps to build a basic web part and deploy it to your sharepoint solution in a repeatable and reversible way. I’ll also give a tour of how to customise the look-and-feel of a Sharepoint website using the Sharepoint designer. The purpose of this is show to illustrate that developing with Sharepoint isn’t really that much different to developing for a standard ASP.Net 2.0-based website.

Development

Watch me create and deploy a brand new web part to a Sharepoint server:

1. This is my out of the box Publishing Site template
01 

2. I’m going to add a web part to my site by adding a new class to my visual studio project
02

3. My class must inherit from Microsoft.SharePoint.WebPartPages.WebPart. I’m going to override the Render method to make the web part output some text. Note how similar this is to an ASP.Net custom control.
03

4.  I build the project. A post-build step creates a CAB file which can be deployed to Sharepoint. This packages up my new features/webparts so that I can manage their usage within Sharepoint and easily repeat/reverse this deployment process.
04

5.  I run a script to deploy the CAB file to Sharepoint. 
05 

6. In Sharepoint I add the Web Part to a page. If I haven’t deployed this web part before I need to Import the web part from the Site Settings menu first.
06 

7. And there it is!
07 

This development process is so simple and repeatable, it’s just like a standard ASP.Net website. What’s more when I set up source-control for my visual studio solution I can set up a continuous integration environment to automatically deploy my changes for me.

Layouts

Now I’m going to change the layout for this page. Most developers seem to believe this is an almost impossible task, or at least much more painful than editing a regular ASP.Net 2.0 Web Forms page. Well, watch:

1. My page layout
08 

2. I open up Sharepoint Designer and browse to the page I want to edit and double click. Sharepoint Designer asks me if I want to edit the content for the page or the layout for the page. I select layout. Here’s what I see:

09

There are a lot of controls on the page. Most of them have the prefix SharePointWebControls, so we can pretty easily see what they’re doing and we don’t have to be afraid. Otherwise this is just like a standard ASP.Net Web Forms page – it has stuff inside ContentPlaceHolder controls. Sharepoint assigns this page layout a master page at runtime.

3. See those ugly tables in the PlaceHolderMain ContentPlaceholderControl? I’m going to change those to divs:

 10

4. And now I’m going to edit the master page for this page layout. I know that the master page I want to edit happens to be BlueBand.master, because I chose it within the SharePoint Site Settings menu. And I also know that all master pages can be found in /catalog/masterpage in SharePoint Designer. I’ll change the tables there to divs too.
12 

5. I check-in the changes to these files (SharePoint automatically provides versioning on these files because they’re actually in the SharePoint database – more on that in another post) and reload my site homepage:
13 

Not such a visually impressive example, I know, but I just wanted to demonstrate that editing a SharePoint website isn’t really that different to building an ASP.Net website, and it’s no more difficult.

In future posts I’m going to walk through how to set up the infrastructure to be able to enjoy the development experience I demonstrated in the first section, and I also hope to demonstrate some ways to make layout editing more enjoyable, like by removing as much of the .Net cruft as possible and make your pages generate something more like semantic markup.

Posted in .net, moss 2007, sharepoint | 2 Comments »

One of those cookie quirks

Posted by andrewmyhre on January 12, 2009

Today I discovered a weird thing that happens if you’re creating an authentication cookie and you’re setting the domain of the cookie.

Let’s say my site is http://mysite.somedomain.com and I set the domain of the cookie to “mysite.somedomain.com”. If I attempt to log in the cookie won’t be saved, meaning I can’t log in. Setting the cookie domain to “somedomain.com” on the other hand works fine. Is this weird behaviour or am I just cookie-ignorant?

Posted in Uncategorized | Leave a Comment »

ALT.Net Beers Tonight at Tequila

Posted by andrewmyhre on January 12, 2009

A reminder that ALT.Net Beers is tonight at the bar in the Tequila London building.

Question/comment here or contact me or Seb on Twitter.

Beer and pizza will be supplied, cheap but not free I’m afraid. £2 beers though – better than a poke in the eye, no?

Seb’s post with more information about format and stuff.

Posted in .net, alt.net, community events | Leave a Comment »

A wonderful trick for discovering the public key token of an assembly you’re building

Posted by andrewmyhre on January 7, 2009

Follow the steps in this article to add a simple shortcut to Visual Studio that will tell you the public key token of the assembly you’re working on. My previous method was: strongly sign the assembly, drop it in the GAC, open the GAC and look up the key token…. so I’m very pleased to have discovered this!

Posted in Uncategorized | Tagged: | 2 Comments »

London .Net User Group 28 January

Posted by andrewmyhre on January 7, 2009

The next London .Net User Group takes place 28 January from 6pm at the Tequila London office (map). I *think* I’m doing a grok talk.

Posted in Uncategorized | Leave a Comment »