Month: December 2012

The local farm is not accessible. Cmdlets with FeatureDependencyId are not registered.(SharePoint 2010 Powershell error)

Error:- “The local farm is not accessible. Cmdlets with FeatureDependencyId are not registered when trying to run SharePoint 2010 PowerShell”

This message would also show up if you try to run the SharePoint 2010 Managment Shell without the proper permissions, or if the account does not have the proper permissions in SQL

OR





the SharePoint 2010 Management Shell was pointing to the incorrect version or path that is invalid and not compatible.

 To Verify which version is being used
1.  Bring up SharePoint 2010 Managment Shell (ignore) the error Message
2.  Type:
$ver=$host | select version
$ver.Version
3.  If you receive something like below.  If the Major version is not on 2, then you will get this runtime error.
Major  Minor  Build  Revision
—–  —–  —–  ——–
3      0      -1     -1
4.  Close out of SharePoint 2010 Managment Shell.
5.  Go back to the SharePoint 2010 Managment Shell Shortcut, right click and select “Properties”
6.  Under the Shortcut tab, Target: section, insert ”-version 2″ into the path, like so.  Make sure its before the -NoExit.
C:\Windows\System32\WindowsPowerShell\v1.0\PowerShell.exe –version 2 -NoExit ” & ‘ C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\CONFIG\POWERSHELL\Registration\\sharepoint.ps1 ‘ “
7.  Click apply, and then Ok
8.  Reopen up the SharePoint 2010 Managment Shell with admin rights, and you should now no longer receive that error, you should then be able to run your scripts.

C# Delegate to perform asynchronous method calls

Paste below code in  VS 2010 console application:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ProjectDelegateAsync
{
    class Program
    {
        public delegate void LongTimeTask_Delegate(string s);
        public delegate void LongTimeTask_Delegate1(string s);
        static void Main(string[] args)
        {
            LongTimeTask_Delegate d = null;
            d = new LongTimeTask_Delegate(LongTimeTask);

            IAsyncResult R = null;
            R = d.BeginInvoke(“TestString”, null, null); //invoking the method

             LongTimeTask_Delegate1 d1 = null;

             d1 = new LongTimeTask_Delegate1(LongTimeTask1);

             IAsyncResult R1 = null;

             R1 = d1.BeginInvoke(“TestString”, null, null); //invoking the method

             Console.WriteLine(“last line of program”);
             Console.ReadLine();
        }
        public static void LongTimeTask(strings)
        {
            for (int i = 0; i < 100; i++)
            {
                Console.Write(” i:” + i);
            }
        }
        public static void LongTimeTask1(strings)
        {
            for (int i = 0; i < 100; i++)
            {
                Console.Write(” jj:” + i);
            }
        }
    }
}

Output:-

last line of program
 jj:0 jj:1 i:0 jj:2 jj:3 jj:4 jj:5 jj:6 jj:7 jj:8 jj:9 jj:10 jj:11 jj:12 jj:13 j
j:14 jj:15 jj:16 jj:17 jj:18 jj:19 jj:20 jj:21 jj:22 jj:23 jj:24 jj:25 jj:26 jj:
27 jj:28 jj:29 jj:30 jj:31 jj:32 jj:33 jj:34 jj:35 jj:36 jj:37 i:1 i:2 i:3 i:4 i
:5 i:6 i:7 i:8 i:9 i:10 i:11 i:12 i:13 i:14 i:15 i:16 i:17 i:18 i:19 i:20 i:21 i
:22 i:23 i:24 i:25 i:26 i:27 i:28 i:29 i:30 i:31 i:32 i:33 i:34 i:35 i:36 i:37 i
:38 i:39 i:40 i:41 i:42 i:43 i:44 jj:38 jj:39 jj:40 jj:41 jj:42 jj:43 jj:44 jj:4
5 jj:46 jj:47 jj:48 jj:49 jj:50 jj:51 jj:52 jj:53 jj:54 jj:55 jj:56 jj:57 jj:58
jj:59 jj:60 jj:61 jj:62 jj:63 jj:64 jj:65 jj:66 jj:67 jj:68 jj:69 jj:70 jj:71 jj
:72 jj:73 jj:74 jj:75 jj:76 jj:77 jj:78 jj:79 jj:80 jj:81 jj:82 jj:83 jj:84 jj:8
5 jj:86 jj:87 jj:88 jj:89 jj:90 jj:91 jj:92 jj:93 jj:94 jj:95 jj:96 jj:97 jj:98
jj:99 i:45 i:46 i:47 i:48 i:49 i:50 i:51 i:52 i:53 i:54 i:55 i:56 i:57 i:58 i:59
 i:60 i:61 i:62 i:63 i:64 i:65 i:66 i:67 i:68 i:69 i:70 i:71 i:72 i:73 i:74 i:75
 i:76 i:77 i:78 i:79 i:80 i:81 i:82 i:83 i:84 i:85 i:86 i:87 i:88 i:89 i:90 i:91
 i:92 i:93 i:94 i:95 i:96 i:97 i:98 i:99