Another question people ask me a lot is what the rules of the road are for using VSTO on the Server with the ServerDocument class. Typically because they’re trying to add a customization on a machine that doesn’t have Office installed using ServerDocument.AddCustomization. The problem is that AddCustomization behaves differently depending on whether the document has previously been customized and had a Runtime Storage Control (RSC) added to it.
|RSC Present||No RSC|
|Office Installed||In this case you can use the ServerDocument constructor onClient parameter to decide if you want to start Office or not.||ServerDocument will start Word or Excel in order to add the RSC to the document. If you set onClient=false then it will error.|
|No Office||ServerDocument can modify the customization using the existing RSC.||Ooops! The document doesn’t have a RSC and there’s no way to add it. If you try this you’ll get a weird COM exception.|
Usually when I’m asked about this it’s because the user is trying to add a VSTO customization to a new document on a (web) server where Office is not installed. The best approach in this scenario is to use a previously customized document and if need be create a copy of it, rather than trying to create a new one from scratch.
So I hear you cursing Microsoft for all this. I agree the COM exception isn’t the best – there should be a much better error there. However if you really think you want to start Office on the server then I’d suggest thinking long and hard about that one. Excel and Office are big applications and while VSTO doesn’t prevent you doing this its likely to really degrade your server performance.