Thursday, August 5, 2010

SharePoint 2010 SPSite : System.IO.FileNotFoundException

Can any one spot an error in the following snippet. Following snippet tries to open a SPSite, SPWeb and tries to open a List to get it item count. All objects exist in the server and this code was built with VS 2010 for SharePoint 2010 in x86 Debug mode.

I ended up with the following exception

System.IO.FileNotFoundException was unhandled
Message=The Web application at http://Foo could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application.
Source=Microsoft.SharePoint
StackTrace:
at Microsoft.SharePoint.SPSite..ctor(SPFarm farm, Uri requestUri, Boolean contextSite, SPUserToken userToken)
at Microsoft.SharePoint.SPSite..ctor(String requestUrl)
at ConsoleApplication1.Program.Main(String[] args) in C:\Users\Administrator\documents\visual studio 2010\Projects\ConsoleApplication1\ConsoleApplication1\Program.cs:line 17
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:


After a couple of minutes I got things straight. There was a mistake in the build, as a basic rule while developing for SharePoint 2010 all your build should be in x64 mode not in x86 mode.

Basic mistake, but it hurts and the error message is not really helping...

Tuesday, July 20, 2010

Load testing SharePoint pages using JMeter

Recently I found myself in search of an open source web load testing tool to do testing and to measure my SharePoint application's home page performance. Apache Jmeter a feature rich tool to prepare a load test which helped to arrive at the statistics.
JMeter Java desktop application which comes in an executable jar file and can be downloaded from here. Obviously you need java runtime(JRE) to start this jar file.
open the bin folder and open ApacheJMeter.jar file from windows explorer
Right click the Test Plan and add a Thread group

Provide the applicable values


Thread group configuration
  • Name - Give a name to store all settings in a jmx file.
  • Number of Threads - Number of concurrent users to hit the page
  • Ramp-Up Period - Thread acceleration period If the number of threads used is 10 and the ramp-up period is 20 seconds,it will take 20 seconds to create those 10 threads.i.e,one new thread in every two seconds, want to create all threads in a single shot, put zero in this
  • Forever - this option tells to keep sending requests to the tested application indefinitely. If disabled, JMeter will repeat the test for the number of times entered in the Loop Count box.
  • Loop Count - the number of times it has to repeat the test, it is effective only if the Forever check box is unchecked
  • Scheduler - want to specify the start and end time of the test, you have an option here
Once the Thread Group is configured add a Sampler called "HTTP request"



Provide the server name, port number, method etc


HTTP Request configuration
  • Server Name or IP - the server name or the IP address of the machine running the application being tested.
  • Port Number - the port number used by the web application
  • Protocol - the protocol used, either HTTP or HTTPS.
  • Method - the request method, either GET/POST/PUT or other options.
  • Path - the relative path to the page you want to hit
  • Follow Redirects - follows redirections sent by the Web application, if any.
  • Use KeepAlive - if checked, sends the Connection = Keep-Alive request header. By default, an HTTP 1.1 browser uses Keep-Alive as the value of the Connection header. Therefore, this checkbox should be checked.
  • Parameters - the list of parameters sent with this request. Use the Add and Delete buttons to add and remove parameters.
  • Send a file with a request - simulate a file upload to the Web application, good to test a large file upload through POST request scenario
  • Retrieve all images and Java Applets - download embedded content.
Add a couple of listeners "View results as Table" & Spline visualizer to see the load test results



Now save the project and run the Test, you will be seeing the samples in your configured listeners, here you can find the time taken for each thread sample hit and status of the request served by Server, number of bytes transfered and start time of the samples
Results in a Table


Result in Spline visualizer


Now fiddle with your code to tweak the performance.

Thursday, July 1, 2010

Windows could not start the Windows Process Activation Service service on Local Computer.

Got a hit from my IIS 7, which hosts Share Point 2010.World wide web publishing service refused to start as there is a dependency with Windows Process activation service. It just says

The World Wide Web Publishing Service service depends on the Windows Process Activation Service service which failed to start because of the following error: The system cannot find the file specified

Restarting WAS results in

"The Windows Process Activation Service service terminated with the following error:The system cannot find the file specified."



Fortunately Scott Hanselman's blog article comes to the rescue to identify the issue. Some of folders within c:\inetpub was missing and Scott taught the way to locate the problem using Process monitor.



Good to have an additional tool narrow down the issue.

Wednesday, June 23, 2010

SPSecurity.SetApplicationCendentialKey !! wondering the typo error in SharePoint API

While digging in to the Microsoft.SharePoint.dll using Reflector for an impersonation related issue, discovered this method SPSecurity.SetApplicationCendentialKey. This method is used to encrypt and decrypt password strings but notice the typo error in a method name it is supposed to be SetApplicationCredentialKey. Microsoft marked this method as obsolete and provided a new method with out typo SPSecurity.SetApplicationCredentialKey.

Still wondering, how this method passed all Microsoft test cases before the release?

Thursday, June 17, 2010

Hide sign in link for anonymous users in SharePoint internet facing sites

A frequent request when you enable anonymous access to any of your SharePoint zone is to hide the "Sign In" hyper link which comes in top right corner of the page. Probably the business might have a request to have an intranet site for all authenticated users and an anonymous site for their customers, so showing a "sign in" link is irrelevant by all means.
Let try eliminating this link in somewhat supported way.

Anatomy of the control
This link comes from user control called welcome.ascx in 12hive\TEMPLATE\CONTROLTEMPLATES, this user control has a feature menu template which is responsible for rendering the menu containing "sign in as different user" and "Sign out" options

Rendering of Feature Menu Template


Scroll towards the end of the file you will find the following section

<SharePoint:ApplicationPageLink runat="server" id="ExplicitLogin" ApplicationPageFileName="Authenticate.aspx" AppendCurrentPageUrl=true
Text="<%$Resources:wss,login_pagetitle%>" style="display:none" Visible="false" />

This application link control is responsible for rendering the "Sign in" control

Take a look at the control tag for its implementation, its visible attribute is marked as false, this will become visible only if the user is not authenticated and the site has anonymous access enabled.
Steps to remove sign in link
  1. Create a new folder under 12hive\TEMPLATE\CONTROLTEMPLATES say 12hive\TEMPLATE\CONTROLTEMPLATES\Foo
  2. Copy the welcome.ascx to this Foo folder (lets stick to best practice of not touching the OOB files).
  3. Comment this ApplicationPageLink section in this copied file under \CONTROLTEMPLATES\Foo

<!--<SharePoint:ApplicationPageLink runat="server" id="ExplicitLogin"
ApplicationPageFileName="Authenticate.aspx" AppendCurrentPageUrl=true
Text="<%$Resources:wss,login_pagetitle%>" style="display:none" Visible="false" /> -->

4. Open your custom master page and modify the mapping to our new user control as below

<%@ Register TagPrefix="wssuc" TagName="Welcome" src="~/_controltemplates/Foo/Welcome.ascx" %>

There you go .. . Do an iisreset and refresh the anonymous page

Less custom code, less bugs and more solid solutions.


Wednesday, June 16, 2010

Compare context menu in Winmerge

I heavily use Beyond compare to compare and merge files. I personally like the BC's context menu option "Select left side to compare" and "Compare to xxx" But one fine day the trial version expired and the only other alternate is WinMerge.


Winmerge also has this option buried deep under the options dialog box.
Open winmerge.exe from C:\Program Files\WinMerge\winmergeU.exe and select Edit-> options


Here you go with the Winmerge's compare To option enabled in context menus

Saturday, June 5, 2010

Where is my iisapp.vbs in Win 2008 Server ?

In sharepoint development iisapp is one of the script which I use heavily to find the application pools running and to recycle a single application pool. This is the usual case in doing development against Win 2003 & IIS 6. While starting the development in Win 2008 server soon it showed me that I'm dealing with a different web server.

Hit the command line console and gave iisapp, it replied that it is not an internal command or invalid command. IIS 7.0 gotta new administration console command called appcmd.

Giving the command "%windir%\system32\inetsrv\appcmd.exe list wp" provides me the information about the running application pools in IIS 7

Yet another tool to learn in a SharePoint developer's life ....