Archive

Posts Tagged ‘Trouble Shooting’

Failure adding assembly to the cache

January 31st, 2010 Dominick Cosgrove No comments

Issue

When copying files to the GAC I occasionaly get the following message in the Visual Studio OutPut window on my development VPC:

Failure adding assembly to the cache: Access denied. You might not have administrative credentials to perform this task. Contact your system administrator for assistance.

Also I cannot see any assemblies in the GAC through Windows Explorer, while it is this state.

clip_image002

Background

When developing features for SharePoint, it is common practice to deploy only the Signed Assembly to the GAC, rather that re-deploying the whole SharePoint solution. Personally depending on the project I use one of two mechanisms:

WSPBuilder – Copy to GAC

WSPBuilder is my tool of choice for increasing productivity while developing SharePoint Solutions. One of the functions of WSPBuilder is Copy to GAC, which does exactly as the name suggest:

clip_image004

PostBuild Task
Some clients don’t allow WSPBuilder to be installed or they prefer a more custom project structure. In these cases I tend to use Project Post Build Tasks. You can use the Edit Post Build… function to add parameters to your post build command, as shown below. I tend to use the GACUtil command to copy the assembly to the GAC and the iisapp.vbs to recycle the application pool. A sample script is show below. This is required to ensure that the Just In Time (JIT) compilation occurs again.

clip_image006

clip_image008

"%programfiles%\Microsoft Visual Studio 8\SDK\v2.0\Bin\GacUtil.exe" /if "$(TargetPath)" /nologo
"%systemroot%\system32\iisapp.vbs" /a "SharePoint – 9000" /r

Resolution

Although I cannot actually explain what is causing this issue, I found that if you restart the Indexing Service through the Windows Services Management Console, the problem is resolved.

If anyone has an explanation as to why this occurs I would be grateful.

clip_image010

Unable to enter text into text boxes in Internet Explorer

September 14th, 2009 Dominick Cosgrove No comments

If you are experiencing the following symptoms:

  • Unable to enter text into text boxes;
  • The About box fields indicating the browser version and patch level, are blank ;

    image

  • Unable to right-click on pages;
  • Unable to select text in a HTML document or a Web page;
  • When you open the About box, the following error occurs and the dialog closes;

    image

    You need to either reinstall Internet Explorer or run the following commands:

    REGSVR32 MSHTMLED.DLL

    REGSVR32 JSCRIPT.DLL

    REGSVR32 /i MSHTML.DLL

  • This file cannot be saved to this location because there is no connection

    August 28th, 2009 Dominick Cosgrove No comments

    If you are using a VPC with no network connectivity, (i.e. your LAN or Wireless network is not available to the VPC) and you try to save a document to a SharePoint Document library you get the following error message

    “This file cannot be saved to this location because there is no connection to the server. Check your network connection and try again.”

    image

    This issue is cause System Event Notification Service.

    Purpose

    Applications designed for use by mobile users require a unique set of connectivity functions and notifications. In the past these individual applications were required to implement these features internally. The System Event Notification Service (SENS) now provides these capabilities in the operating system, creating a uniform connectivity and notification interface for applications. Using SENS developers can determine connection bandwidth and latency information from within their application and optimize the application’s operation based on those conditions.

    Where Applicable

    The connectivity functions and notifications of SENS are useful for applications written for mobile computers or computers connected to high latency local area networks.

    Solution

    Office applications use the System Event Notification Service to ensure that the required connection is available during the save process. As the service determines that there is no network connection available it causes the save to fail. To prevent this you need to stop this service. The easiest way to do this is to use the following command:

    net stop sens

    image

    To restart the service issue the following command:

    net start sens

    image

    Note: The service is set to start automatically by default in Windows, so you will get the error again after a reboot of the VPC. To prevent this you can set the service to start manually:

    image

    RunWithElevatedPrivileges Gotcha

    January 14th, 2009 Dominick Cosgrove No comments

    The Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges is a useful method that can execute a delegate method that runs a subset of code in the context of an account with higher privileges than the current user.

    Sample usage:

    SPSecurity.RunWithElevatedPrivileges(delegate(){    // implementation details omitted});
     
    Something you need to watch for, which is eluded to in the SDK is that you must create a new SPSite object inside the delegate because SPSite objects created outside do not have Full Control even when referenced inside the delegate. Now it’s not only the SPSite object that you need to concern yourself about. For instance if you have some custom code that run with Elevated Privileges and that code accepts a SPListItem as a parameter, then that SPListItem will have the same security as when it was created. This is to say that the RunWithElevatedPrivileges method does not increase the security for objects that already exist. You need to create the objects within the method for them to adopt the elevated privilege.
     
    Take for example the following scenario; You have two folders in the same document libraries, one (Folder A) where users have the permissions to contribute with the other (Folder B) is locked down and only the system administrator can contribute, all other users only have read access. The use case is that, when a user sets the document approval status to approved and checks in the file the file will be moved from Folder A to Folder B. The issue arise where the user who executes the method does not have the correct privileges on Folder B to add the file. This is where RunWithElevatedPrivileges comes into play. The following shows an example a possible Move Document method:
     
    This code will Error!
     
    private void MoveDocument(SPItemEventProperties properties)
            {
                string targetDir = [PathToSharePointFolder];
    
                SPList list = web.Lists[properties.ListId];
                SPListItem item = list.GetItemById(properties.ListItemId);
                SPFile file = item.File;
    
                try
                {
                    SPSecurity.RunWithElevatedPrivileges(delegate()
                           {
                               using (SPSite site = new SPSite(properties.SiteId))
                               {
                                   using (SPWeb web = site.OpenWeb(properties.RelativeWebUrl))
                                   {
                                       file.MoveTo(targetDir + "/" + file.Name, true);
                                   }
                               }
    
                           });
    
                }
                catch (Exception ex)
                {
                }
            }

     
    When you run this code in your ItemCheckedIn EventHandler you notice that you’re getting an unauthorised exception! What is causing this?
     
    Well the culprit in this case is the SPFile object. As the file object is instantiated out side of the RunWithElevatedPrivileges method the file object has the security context of the user who performed the action. This user does not have sufficient privileges on folder B hence the error message.
     
    To rectify the issue you can instantiate the file object within the RunWithElevatedPrivileges method as show below:  
     
    This code should execute successfully
     
    private void MoveDocument(SPItemEventProperties properties)
            {
                string targetDir = [PathToSharePointFolder];
    
                try
                {
                    SPSecurity.RunWithElevatedPrivileges(delegate()
                           {
    
                   SPList list = web.Lists[properties.ListId];
                              SPListItem item = list.GetItemById(properties.ListItemId);
                             SPFile file = item.File;
    
                               using (SPSite site = new SPSite(properties.SiteId))
                               {
                                   using (SPWeb web = site.OpenWeb(properties.RelativeWebUrl))
                                   {
                                       file.MoveTo(targetDir + "/" + file.Name, true);
                                   }
                               }
    
                           });
    
                }
                catch (Exception ex)
                {
                }
            }

     
    So it is important to be aware of where SharePoint Object are created when using the RunWithElevatedPrivileges method and if you are experiencing a unauthorised error the chances are that a object is being created outside of the RunWithElevatedPrivileges method.
     
    Note: The code in this article is for demonstration purposes and should not be used in any other context than what it is intended for.