Category Archives: Development

Things not directly SharePoint related

Configuring Reflector in Visual Studio 2008


Red Gate's Reflector (Formerly by Lutz Roeder) is one of those tools that you can technically live without but the question then becomes: why?  It is free and makes SharePoint development that much easier.  And to be honest, those of us doing serious development in SharePoint can use a few breaks in this area.

The main thing that it gives SharePoint developers is the full name of your compiled dll's (including the PublicKeyToken) in the exact format that you have to use all over SharePoint whenever you reference anything in that library. 

The only problem is that Reflector doesn't know where to find your handy DLL, so you have to open Reflector and do File-Open and browse to your newly compiled library.  Except, of course, if you configure it as an External Tool (under Tools on the menu) so that Visual Studio tells it where to find your DLL.  Easy enough.

 

For those who like copy-paste, those arguments are :

"$(BinDir)$(TargetName)$(TargetExt)"

Compiling your project and running Reflector from the Tools menu now should now show you a whole list of libraries with your custom dll at the bottom.  Clicking on your dll name will put information like this at the bottom of the Reflector window where you can then highlight it and copy.  Yes, the information is available simply by looking at the GAC but this is much quicker and less prone to typing errors, and is already in the proper format.

The second thing it gives you, which is actually Reflector's main purpose, is immediate and easy disassembly of a library so you can see the code that is actually being executed when you call functions in Microsoft.SharePoint.dll.  It also opens you up to a whole new world of frustration, as in: “Why in the world did Microsoft not seal a certain webpart class, but then did seal that webpart's custom toolpart class”  Yep. You get to see that stuff too.

Happy reflecting 🙂

SharePoint Advanced Search Scopes Bug


I have a situation where I need to allow a user to pick from a set of available scopes in the Advanced Search box in SharePoint.  In and of itself, this is not a problem as I can configure the Advanced Search Web Part to do this and then customize the specified Display Group as needed.  Easy.  The problem arises when the user attempts to select multiple scopes in the Advanced Search and hits Submit.  Then I get:

“Your search cannot be completed because of a service error. Try your search again or contact your administrator for more information”

It turns out that the problem is that one of the scopes included in the Display Group contains the Scope Rule to include All Content.

The Solution

Create a new scope in your Shared Service Provider that will include all of the content via URL includes and such but does not have the All Content scope rule.  Then update the Display Group used for Advanced Search to use the new scope instead of the original scope. Naturally, the complexity of this option will vary greatly based on your environment.

Note: I cannot take credit for solving this as the original diagnosis and solution is posted here.  I'm rewording it and reposting it here in the hopes of making it easier for people to find as tracking down the original solution took quite a while.  The original solution is also rather technical which may cause non-technical admins to gloss over pretty quickly.

Vital Hotfix for Sluggish Design View in Visual Studio 2008


Microsoft has released a Hotfix for the incredibly annoying performance issues when working in the Design view of an Asp.Net form that contained custom user controls.

The installation info is on the MSDN Blog and is pretty self explanatory.  It takes a few minutes to install but it is worth the wait.  Before the patch, simply switching to Design view for one of my Asp.Net forms could take upwards of 30 seconds.  After the patch, it takes around 3 seconds and half of that is the pulling together the nested master pages behind the form. 

I've also noticed that the properties window now switches almost immediately when I click on a control.  Before, it would take 5-10 seconds to change and sometimes never did.

InfoPath 2007 / WCF Nasty Gotcha


I've spent the better part of two days tracking down an extremely nasty bug in InfoPath that corrupts an InfoPath form completely and almost terminally after connecting to a WCF (Windows Communication Foundation) web service.  Each time you try to open the form in design mode, InfoPath kicks out the error below and then refuses to open the form.

"InfoPath cannot open the following form: C:longpath oform.xsn.  The XML Schema file specified in the form definition (.xsf) file for dataObject 'xyz' cannot be used"

Once this happens, there is no way to get InfoPath to edit the form again.  However, there is a fix.

The Fix – Recovering your work

First, we have to get you so you can edit your form again.  Since the actual error hides itself completely during the initial design session it is possible to lose a lot of work, depending on how much you worked on the form during the session where you connected it to the web service.  Either way, you have to fix both problems in order to get the form working properly anyway.

  1. Create a new folder and copy your "corrupt" .XSN file to that folder. 
  2. Rename it from .XSN to .CAB (Yes, .XSN is really just a .CAB)
  3. Use a compression utility that can read CAB files (like WinZIP) to unpack the contents of the file into that folder. 
  4. Open the Manifest.xsf file in a text editor (NOT in InfoPath) and look for "<xsf:dataObjects>"  under that node, you will see several <xsf:dataObject> nodes. 
  5. Delete all <xsf:dataObject> nodes that point to WCF web services.  You can spot these easily because they usually have ".svc" somewhere in the wsdlUrl attribute of the <xsf:webServiceAdapter…> child node.
  6. Save the Manifest.xsf file. 
  7. Now right-click on the manifest.xsf and select 'Design'.  This should open InfoPath and will give you a warning that the form has been moved.
  8. Click ok. At this point, the form should open in design properly.  You should also see "[Read-Only]" in the title bar.
  9. Go through all views in your form and disconnect any controls that were bound to the WCF data sources.  Sometimes this is as simple as converting them from whatever type they are to text boxes.
  10. Click File -> Save As and save the file to the folder where you want the file to reside.  This will automatically save it as an .XSN file again.
  11. Close InfoPath (very important- don't just close the form)
  12. Browse to the the new folder and find the new .XSN file
  13. Right-click on it and select 'Design'.
  14. Click 'Preview' to preview the form.  If you get the error "InfoPath cannot open the selected form", it means that one of your controls is still bound to one of the data sources you removed earlier.  Check your controls again and also check any Rules you may have defined under Tools -> Form Options -> Open and Save -> Open behavior.

At this point, you should now be back editing your form as normal, just without the web service data.  Warning: do NOT reconnect to the web service until the next part of the fix is completed.  Doing so immediately lands you back at step 1!

The Fix – Fixing the Web Service

This will require the help of the author of the web service who will probably deny that there is an error and try to blame InfoPath because it works in all of his loosely typed test applications.  You must convince them that the problem really is with the way the service is defined.  Perhaps this entry will help, perhaps not.  Either way, he will have to do something with his web service if he wants that data exposed in your form because it won't work as it is right now.  I was lucky that the developer of the web service was every bit as curious about this error as I was so we were able to troubleshoot this from both ends.

The root of the problem is that one or more of the underlying data types is defined with an improper Namespace in the [DataContract] attribute or one that doesn't match all of the others.  InfoPath is extremely particular and if the namespaces don't match precisely, it will cause the error mentioned at the start of the article.  It is case-sensitive.

To track down exactly where the problem lies involves a little bit of detective work and some of the files extracted from Step 3.  When you created the Data Connection to the web service call in InfoPath you gave it a name like 'GetSomeDataFromJoe'.  If you look in the folder from Step 3, you should see 4 or 5 files called GetSomeDataFromJoeXX.xsd where XX is a number between 1 and 99.  These are the actual schema files that InfoPath pulled down when you connected to the web service.  Send these to the developer.  If he looks through them, he will find one (usually the second in the series) that shows the data types found in the web service.  One or more of the types he is using should be missing completely from the XSD files which means that those are the ones with the broken namespace.

After fixing this, the developer will need to build and then publish the web service before you can attempt to connect to it again.

Putting it All Back Together

Now that the developer has assured you that the fix has been made you will need to reconnect to the web service. To reconnect safely, try it this way:

  1. Backup your current working form (.xsn) from the first part of the fix – just in case the developer hasn't gotten the fix quite right yet.
  2. Open the form for design in InfoPath
  3. Reconnect to the web services
  4. Save the form and close InfoPath
  5. Reopen the form in InfoPath. 
  6. Switch to Design mode.
  7. If it opens properly then the developer cleaned up his namespaces and it is safe to reconnect your controls to the web service data.
  8. If you still get the "… XML Schema file … cannot be used" error, then the problem is still in the web service.  Delete the .XSN (because it is now corrupted again) and restore it from your backup.  If you jumped ahead and reconnected without backing up, then you get to do this whole thing all over again starting with Step 1 under "Recovering Your Work". 

Behind the Scenes (IMO)

The reason for the error is because of the way that InfoPath pulls the schema for a WCF web service.  When it connects and pulls down the schema info from the WSDL, it also pulls down all of the schemas for the data types used in the service.  In this case, the namespace of one of those schemas didn't match precisely so it couldn't be found later on, which is logical and expected behavior. However, InfoPath itself ignores that error during the session in which you originally connect to the web service.  It is not until you close InfoPath and then go back in that you get bitten by it.  What would be nice is if InfoPath kicked out the error when you connected to the service rather than laying a trap for you later on.

The truly curious part of all of this is that despite having an invalid schema, you can still open the "corrupt" .xsn file for data entry in InfoPath and it works perfectly.  One would think that something as substantial as a broken schema would kill the form no matter what.

Bizarre InfoPath Dialog


I'm trying to open a local copy of an InfoPath form that was originally opened from SharePoint.  The actual .xsn file that I've been working with is on my local file system and that is where I'm opening it from.  However, when I open it, I get the dialog below:

Fli118

 

Ok…. so … I know the template on my local machine is the one I want to open and I know that it is different than what is in SharePoint, so I naively click on the "Keep Form Template on Your Computer" button, thinking that it will, you know, keep the one that is on my computer rather than the one in SharePoint.  Silly me.  That option actually opens the original template from SharePoint, which is a "replace" of my local copy in my way of thinking of things.

Now, I realize that a very careful reading of the actual message (which nobody actually does until after the fact) will somewhat point you to the right answer, but having to click "Replace…" in order to keep local changes and "Keep…" to replace local changes is just a little bit counter-intuitive. Maybe a "use this one" button under each option might have been clearer?  Just a thought…