Clara's Notes on Technology
Notes to me and the world

Attempted to use an object that has ceased to exist

In one of the pages of my SharePoint application, I added a Links web part (web part that shows the contents of the a links list). Pretty simple. Then, I se tthe "XSL Link" property so that the results were customised in a certain style. Then I got this really strange error:

Attempted to use an object that has ceased to exist. (Exception from HRESULT: 0x80030102 (STG_E_REVERTED)) 

After some searching I understood it meant that the current SPContext could not be accessed. I then realised that another (custom) web part in the page was destroying the SPContext object after use, so when the Links web part (OOTB) tried to use it, it couldn't.

Look for anything like

(SPWeb site = SPContext.Current.Site) {...}

 

in your custom web part code. This is wrong. You must not dispose the current site object. Instead you can use something like:

using (SPWeb elevatedSite = elevatedsiteColl.OpenWeb(siteID)) { ... }

Guid siteID = SPContext.Current.Web.ID;

 

 

Links that help me:
http://markanthonyparker.blogspot.com/2010/07/attempted-to-use-object-that-has-ceased.html

http://junooni.wordpress.com/2011/02/25/attempted-to-use-an-object-that-has-ceased-to-exist-exception-from-hresult-0x80030102-stg_e_reverted/

using



  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

"Required permissions cannot be acquired" after 3rd party feature uninstalled

I was looking for a web part that would provide me some sort of navigation inside wiki pages, and I installed a 3rd party farm feature. It didn't really do what I was looking for and I uninstalled it. Afterwards, any page in my site collection gave this error:

[PolicyException: Required permissions cannot be acquired.]
   System.Security.SecurityManager.ResolvePolicy(Evidence evidence, PermissionSet reqdPset, PermissionSet optPset, PermissionSet denyPset, PermissionSet& denied, Boolean checkExecutionPermission) +10237966
   System.Security.SecurityManager.ResolvePolicy(Evidence evidence, PermissionSet reqdPset, PermissionSet optPset, PermissionSet denyPset, PermissionSet& denied, Int32& securitySpecialFlags, Boolean checkExecutionPermission) +97

[FileLoadException: Could not load file or assembly 'RH.WikiNavigation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=bdb92ef53612be7b' or one of its dependencies. Failed to grant minimum permission requests. (Exception from HRESULT: 0x80131417)]
   System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) +0
   System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +416
   System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +166
   System.Reflection.Assembly.Load(String assemblyString) +35
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +190

I tried deleting the site collection and recreating it. Same thing. Aaahh! I spent hours looking at config file searching for a reference to the 3rd party assembly.

Solution: A .dll was left behind in C:\inetpub\wwwroot\wss\VirtualDirectories\80\bin. I deleted it and everything was okay again!
 

 



  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

SharePoint Search Problem: The crawler could not communicate with the server.

This one was not easy to solve ...

Error: The crawler could not communicate with the server. Check that the server is available and that the firewall access is configured.

Context: Some pages were not crawled (giving the above error) and, what is worse, all the sub content of that site was not crawled either! (the pages were the homepages of the site)

Solution:The pages that could not be crawled due to this error contained a custom web part. This web part used default credentials for a given action. During crawling, the SP_Search account tried to perform this action but did not have the appropriate rights. This gave an error that stopped the crawling for the whole site.

This blog helped me: http://patricklamber.blogspot.com/2010/04/why-might-moss-crawler-not-working.html

 



  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

SharePoint Search Problem: The start address sps3://server cannot be crawled.

With this post, I'm going to start a series on problems I have encountered with SharePoint search.

Error: The start address sps3://luapp105 cannot be crawled.

Context: Application 'Search_Service_Application', Catalog 'Portal_Content'

Details:
 Access is denied. Verify that either the Default Content Access Account has access to this repository, or add a crawl rule to crawl this repository. If the repository being crawled is a SharePoint repository, verify that the account you are using has "Full Read" permissions on the SharePoint Web Application being crawled.   (0x80041205)

(Event ID: 14, Task Category: Gatherer)

Solution: give appropriate permissions to User Profile Synchronisation Service
http://social.technet.microsoft.com/Forums/en-US/sharepoint2010setup/thread/64cdf879-f01e-4595-bc52-15975fefd18d
http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2010/03/29/how-to-set-up-people-search-in-sharepoint-2010.aspx



  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Default calculated value for datetime field in xml

How to specify a calculated value for a SharePoint custom field in its XML schema?

Like this:
 <Field
    Type="DateTime"
    Format="DateOnly"
    DisplayName="ExpiryDate"
    Required="FALSE"
    EnforceUniqueValues="FALSE"
    Group="My Group"
    ID="{99668BDC-5DED-46d0-A4EC-360237966F52}"
    StaticName="ExpiryDate"
    Name="ExpiryDate">
    <DefaultFormula>[today]+60</DefaultFormula>
  </Field>
 



  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

"Value does not fall within the expected range" with managed metadata fields

The problem: I have an item adding event receiver associated with a custom content type that accesses several managed metadata fields using the syntax "PublishingPage.ListItem["fieldname"]". Suddenly, I started getting the "Value does not fall within the expected range" when accessing one of the managed metadata fields. I had nothing else except the message and, more annoyingly and off-setting, it only happened with some users. It worked for users who were local administrators of the SharePoint server. This really sent me in the wrong direction.

The solution: Check the "List View Lookup Threshold" for the web application (in CA, under the web application general settings). The default is 8. Managed metadata fields in a list are actually lookup fields, so if you have more than 8, error. What I don't know is why I didn't get this error with local adminstrators (maybe the threshold doesn't apply to them?). The reason I had more than 8 managed metadata fields in my list is that, after each new deploy of my content type, the field kept duplicating itself. I think I now solved this problem too by adding Overwrite="TRUE" OverwriteInChildScopes="TRUE" to the field definition.

Solution source: http://social.technet.microsoft.com/Forums/en-US/sharepoint2010programming/thread/65e04367-e926-404b-b355-825a52f4ce69/

 Technorati Tags: SharePoint



  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Powershell: Change Title of PublishingPage

Today I had to change the title of several pages in several publishing sites. You can find the powershell script below.

Notice that you have to access the pages as PublishingPage and not SPListItem,otherwise you will not be able to modify the Title field ("Title" is ReadOnly). Also, you have to go through the same procedure as in the UI: checkout, change property, checkin and publish (and maybe approve if the library requires it).

Add-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue 

#read list

$lines = Get-Content "C:\SharePoint2010\PowerShell\sites.txt" #| Sort-Object

foreach($l in $lines)
{       
    try
    {          
        $a = $l.split(";");
        $url = $a[0]
        $title = $a[1]               
     
        $spWeb = Get-SPWeb -Identity $url
        if ([Microsoft.SharePoint.Publishing.PublishingWeb]::IsPublishingWeb($spWeb))
        {
            $spPubWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($spWeb)
            $pages = $spPubWeb.PagesList
            foreach($item in $pages.Items)
            {
                $pubPage = [Microsoft.SharePoint.Publishing.PublishingPage]::GetPublishingPage($item)
                
                if ($pubPage.Title -eq "wrong title")
                {            
                    $pubPage.CheckOut()
                    $pubPage.Title = $title
                    $pubPage.Update();
                    $pubPage.CheckIn("")
                    $pageFile = $pubPage.ListItem.File;
                    $pageFile.Publish("");
                    #pageFile.Approve(checkInComment);
                 }                      
            }
        }
        $spWeb.Dispose()                   
        Write-Host -BackgroundColor DarkGreen -ForegroundColor White ("Done: " + $url);      
    }    
    catch      
    {            
        Write-Host -BackgroundColor DarkRed -ForegroundColor White ("Failed:" + $url + ". Error details : " + $_)      
    }
}


The input file contains the url of the site and the title of the page, separated by a semicolon. Like this:
 

http://<servername>/home/site1/site2;Correct Title for page

 

 

Technorati Tags: PowerShell, SharePoint
 



  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

SharePoint 2010 Connections – Cascais

 

I’m at the SharePoint 2010 Connections at Cascais, next to Lisbon. The setting is amazing. I really like the talk by Dan Holme. I always knew I was an IT Pro at heart.

Anybody else out there is here?



  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

TFS 2008 to TFS 2010 Migration

 

Here’s how we migrated our TFS 2008 to TFS 2010. This is not an in-place migration.

What is generally recommended as upgrade path is to backup the TFS 2008 DBs, restore them in the new TFS data tier and then install TFS 2010. This will migrate all the projects at once. However, we wanted to keep the TFS 2008 environment running for a while, so this path did not do.

We first set up a new machine (and a new domain, but that is a whole other story) with TFS 2010 and WSS 3.0. The database tier was on yet another machine (SQL Server 2008, of course). And then we proceed with migration of the TFS content.

Migration of Version Control and Work Items

Just use the command below:

tfsconfig import /collectionName:Imported /sqlinstance:sql2008 /confirmed

Source code and work items were migrated fine, version control history was maintained (even timestamps). The process templates were not migrated but the old projects retained their template (their old work item structure, queries, etc.). That is exactly what we wanted: old projects should remain as they were, and not to be upgraded to the new process templates.

All the migrated projects went to a new project collection:

http://tfsserver:8080/tfs/Imported

While new projects will go to the default collection:

http://tfsserver:8080/tfs/DefaultCollection

As explained by the documentation, tfsconfig import does not move reports, builds or portals.

Be careful: tfsconfig is a destructive command! It means it will destroy the TFS2008 DBs. What I did was take a backup of the DBs and restore them in the new SQL server used for TFS 2010. The tfsconfig command points to the restored databases (so my old environment was safe). 

I found information on this step from the following blogs (thanks guys!):

· http://blog.mediawhole.com/2010/04/how-to-do-test-tfs-2008-migration-to.html

· http://blogs.msdn.com/b/bharry/archive/2009/10/21/upgrading-from-tfs-2005-2008-to-tfs-2010.aspx

Mapping old users

Since we also changed domains, I had to map the old users to the new users in work items. There used to be a TF power tool to do this (TFSUsers), but it does not exist anymore. TFS 2010 is intelligent enough to synchronize on its own with AD. So if a user changes name in the AD, it also changes in TFS 2010 work items. So, I came up with a workaround with excel.

Workspaces

When the users log into the new TFS 2010 server and try to get the latest version of their code, they will need to specify to local folder (mapping). After that, they usually get an error saying the workspace already exists.

You need to delete your old workspaces or create new ones. http://geekswithblogs.net/claraoscura/archive/2010/06/08/140279.aspx

It is important to delete the workspaces client cache too! Otherwise, your users will keep getting the annoying message:

tf workspaces /remove:* /server:tfsserver

Migration of the WSS 2.0 Team Portals

This is where the hard work started. The process is well explained here. Basically, it entails taking a backup of the WSS 2.0 content DB, restore it in the new data tier and attach it to a WSS 3.0 web application. A few problems we encountered:

- You need to run prescan tool on the WSS 2.0 server and the prescan log has to give no errors. In our case, we had one orphan site and it took me forever to get rid of it.

- Also very important: before attaching the old content DBs to the new WSS server, create a different web application to hold the old data. Otherwise, it will overwrite the existing web application (containing team sites for new projects, for example).

The final result is that the migrated team portals go into one web application:

http://tfsserver:11823/sites/oldprojectname

While new projects go into the initial web application

http://tfsserver/newproject

- You might need to reset user rights on the old portals. We had to do it because of our change of domain.

Once the old portals are migrated to WSS 3.0, you need to enable team portal on the projects. You can do it from Team Explorer: right click on the project and choose team portal settings. (Does anyone know how to automatise this? I had to do it manually for 53 projects?).

Migration of the Reports

There are different options for this step:

  1. Modify them to work with TFS 2010 warehouse (too complicated)
  2. Keep them
    1. as static content (e.g. export in excel, pdf, etc.)
    2. with old warehouse (this means that you need to move the TFS 2008 Warehouse db and cube to the new SQL Server, even if new data will not go to this warehouse)
  3. Get  the new reports to work with old projects (???)

 

Migration of Builds

We don't currently use TFS builds, so I don't have any info on that! Sorry.

Good luck with your own migrations!



  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Accounts in Work Items after migration to TFS 2010 and to new domain

 

Lately I’ve been doing some tests on migrating our TFS 2008 installation to TFS 2010, coupled with a machine and domain change. One particular topic that was tricky is user accounts.

We installed first a new machine with TFS 2010 and then migrated the projects in the old server. The work items were migrated with the projects. Great, but if I try to edit one of the old work items I cannot save it anymore because some fields contain old user names (ex. OLDDOMAIN\user) which are not known in the new domain (it should be NEWDOMAIN\user).

The errors look like this:

AssignedToError

When I correct the ‘Assigned To’ field value, I get another error regarding another field:

ActivatedByError

Before TFS 2010, we had TFSUsers power tool. It allow you to map an old user name to a new user name. This is not available anymore because WI fields with user accounts are now synchronized with AD display names changes (explained here).

The correct way to go about this in TFS 2010 is to use TFSConfig Identities before adding the new domain accounts into the TFS groups (documented here). So, too late for us.

I’ve found a (tedious) workaround to change those old account in work items in order to allow people to keep working with them.

1. Install TFS 2010 power tools

2. Export WIT from your project (VS | Tools | Process Editor | Work Item Types). Save the definition, for example: Original_MyProject_Task.xml

3. Copy the xml (NoReadOnly_MyProject_Task.xml) and edit it. From the field definition of ‘Activated By’, ‘Closed By’ and ‘Resolved By’, remove the following:

       <WHENNOTCHANGED field="System.State">
          <READONLY />
        </WHENNOTCHANGED>

4. Import WIT in VS. Choose the new file (NoReadOnly_MyProject_Task.xml) and import it in MyProject

5. Open all tasks in Excel (flat list). Display the following columns:

  • Asssigned To
  • Activated By
  • Closed By
  • Resolved By

Change the user accounts to the new ones (I usually sort each column alphabetically to make it easier).

6. Publish.

If you get a conflict on a field, tough luck. You will have to manually choose “Local version” for each work item. I told you it was a tedious process.

7. Import original WIT (Original_MyProject_Task.xml) in MyProject. We only changed the WI definition so that we could change some fields. The original definition should be put back.

And what about these other fields?

  • Created By
  • Authorized As

These fields are not editable by definition (VS | Tools | Process Editor | Work Item Fields Explorer), even if they are not marked as read-only in the WIT. You can leave the old values. It doesn’t seem to matter to TFS.

The other four fields are editable by definition, so only the WIT readonly rule prevents us from changing them.

widefiniton



  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Do you have to recreate workspaces after upgrading a TFS 2008 server to TFS 2010?

 

I am just reposting this thread from a MSDN forum since it seems to be unavailable. It was very useful when I was having trouble with my folder mappings after migrating to TFS 2010.

Question:
I opened VS2008 and connected it to the upgraded 2010 TFS server.  Upon clicking any of our Team Projects in source control explorer I get
"Team Foundation Error - The workspace MYWORKSPACE;DOMAIN\MYUsername already exists on computer MYPCNAME."

Answer:
The same local paths on your machine are mapped to 2 different workspaces, one on the preupgrade server and one on the postupgrade server.  It's not safe to have multiple workspaces on different servers mapped to the same local paths b/c you could pend some changes while connected to one server, and the other server would have no idea what you did.  You should either delete your conflicting workspaces from one of the servers (if you don't need them on both), or test the new TFS instance from a new workspace (on different machine).

If you want to test an existing production workspace on both servers, then yes, you will have to mess around with the workspace cache.

You don’t have to delete the entire cache, you just need to run "tf workspaces /remove:* /server:<serverurl>" to clear the cached workspaces from a server (the command won't delete the workspaces), and possibly "tf workspaces /server:<server>" to refresh the workspace cache for a given server.  You will also have to do back up and restore the workspace before switching servers or your local files could be inconsistent.

From the “Microsoft Visual Studio Team Foundation Server 2010 Beta 1” forum (not available anymore?)



  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Change Excel connection to a team project

Once you have imported a list of work items in excel from a team project in TFS, the excel file always proposes work items from the same team project. It does not seem possible to obtain the "connect to TFS" popup window again, where you choose the team project. This is because the connection is stored as a custom property in the excel file.

The answer is to delete all custom properties from the file. Go to the main menu and then: Prepare / Properties / Document Properties / Advanced Properties / Custom. Delete all "VS Team System Data DO NOT EDIT" properties (the content is encrypted). Do NOT save the file. If you save it, the properties are created again! Just go to the Team menu and choose "New List": you will now be prompted to choose a team project.

If you need to save the file (you want to keep it without the TFS connection in it), follow the instruction given by Buck Hodges here. Before removing the properites, you have to deactivate the TFS excel add-in.



  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Developing for Mobile (3): Calling a WCF/ASMX Service

Up to now I haven't explained what my mobile test application does. The main thing I wanted to test was calling a WCF service. If you use .NET CF 3.5 WCF will be available in your application to make the call but you can also call the service as "web service" (asmx)

(1) Calling the service as ASMX

In you Smart Device Application project just do "Add Web Reference", enter the url of the service (no "mex" part but with final /, like this: http://server:port/Design_Time_Addresses/WcfService/Service1/) and your are done.

This is the code I use in the device application to call the web service:

 

Service1WebReference.Service1 svc = new Service1WebReference.Service1(); IWebProxy proxyObject = new WebProxy(this.proxyAddress, true); proxyObject.Credentials = System.Net.CredentialCache.DefaultCredentials; svc.Proxy = proxyObject; string response = svc.GetData(i, true);

I had to specify the proxy address otherwise it would not work. The first time I call the service I get prompted for the credentials.

(2) Calling the service as WCF

The first thing you will notice is that in the Smart Device Application project, there is not option to "Add Service Reference". GRRRR ... You need to install the Power Toys for the Microsoft .NET Compact Framework. Then, you can use the NETCFSvcutil utility to generate the proxy code. Like this:

"C:\Program Files\Microsoft.NET\SDK\CompactFramework\v3.5\bin\NetCFSvcUtil.exe" http://server:port/Design_Time_Addresses/WcfService/Service1/

The utility generates two files (Service1.cs and CFClientBase.cs) that you have to add to your project.

This is the code I use in the device application to call the WCF service:

 

Service1Client client = new Service1Client(); string response = client.GetData(i);

 

Remarks

Notice that you have to use your machine IP as server name and not "localhost". Otherwise, your smart device will not be able to locate the service.

Several other blogs explain how to connect the emulator and your desktop machine: for example, here. (This is for Pocket PC or Smartphone emulators that are proviced by the SDK; if you can to use the Windows CE 5.0 emulator, read this and see my previous blog post).

 



  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Developing for Mobile (2): Pocket PC/Windows CE

After setting up the development environment, I started coding a simple application. Visual Studio does not provide a Windows CE 5.0 emulator (only a device - which means that it tries to connect to a real device and I don't have one), so I chose to develop a Windows Mobile 5.0 Pocket PC application.

(1) I first created a Smart Device Console Application. It built and deployed ok, but when running I didn't see any console! I think this is due to the fact that there is no cmd.exe in the emulator.

(2) I then created a Smart Device Application (Windows Forms). This is the kind of application I will have to develop later, anyway. Build and deploying where fine and the form appeared in my emulator:

My form in the Pocket PC emulator

Nice!

After that, I started wondering what the difference was between Windows Mobile 5.0 Pocket PC and Windows CE 5.0. Wikipedia is pretty good for this kind of questions: check it out here. So, they are pretty close (Windows Mobile 5.0 Pocket PC is built on top of Windows CE 5.0) but not the same. Besides, the Pocket PC emulator screen did not look like the Datalogic Memor screen:

 Pocket PC ScreenMemor Screen

Better check that my application works on Windows CE 5.0, then. How?

(1) Download the Windows CE 5.0 emulator from here.

(2) Launch it from the command line (not from the start menu link, otherwise you will not be able to specify any options for network connections):

C:\Program Files\Windows CE 5.0 Emulator>Emulator_500.exe /CEImage nk.cem /Ethernet virtualswitch
(3) Connect to the emulator: I followed the instructions here. Just a few remarks: 
  • the <CPU> of the emulator is x86;
  • the emulator does not have a command prompt (or I didn't find it), so I just double clicked on the exes to run them;
  • you can read the IP address by double clicking on the network link icon on the taskbar;
  • you can copy files from your machine to the emulator by creating a shared folder (see emulator file menu) which is accessible through the "storage card" in the emulator windows explorer.

 

Once I had the emulator connected, I deployed an application (usual method = F5 + select Windows CE Device) built using a Smart Project Device Application project for Windows CE 5.0.

 

But ... what about my initial Pocket PC application? Would it deploy in the Windows CE emulator? It did!

 

I created a CAB (deployment project for smart device apps) for the Pocket PC application. I copied on the Windows CE emulator and double clicked it: it installed and run fine!

 

 



  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Developing for Mobile (1): On Vista

I might have to develop an application for a mobile scanning device and I have been playing around with the .NET mobile components in preparation. Not easy at all: the documentation is not very clear and there are lots of different components/versions. Here are some of the problems I encountered and how I solved them.

My constraints:

a) My development environment is Windows Vista + VS 2008 Team System.

b) The device will probably be Datalogic Memor which runs Windows CE 5.0. This means I need to install Windows Mobile 5.0 SDK - the documentation says that it only supports VisualStudio 2005 and Windows XP and that it requires ActiveSync 4.0.

c) I want to develop with the .NET Compact Framework 3.5 in order to use WCF. This was installed already on my machine.

So, will all of this work toghether on Vista? Well, it did (unexpectedly).

The only quirk is that you cannot run ActiveSync 4.0 on Vista. You have to install Windows Mobile Device Center instead.

 



  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati