Posts Tagged .Net
Installing Visual Studio Team Foundation Server 2010-Basic Configuration Step By Step
Posted by Rajanihanth in .Net, TFS, TFS 2010 on March 3, 2013
Installing Visual Studio Team Foundation Server 2010 (TFS 2010) is pretty simple, there are few types of installation available in TFS 2010/2012, they are:
- Basic
- Standard Single Server
- Advanced
- Advanced-Tier only
In this installation, I am going to choose the basic installation right now (TFS 2010) and I will post the advanced installation (in TFS 2012) later! 🙂
1. Double click the Setup.exe OR tfs_server.exe in your installation media!
2. You will get the following screen after few seconds, click Next
3. Select the license term and click Next
4. Select the necessary features and installation path then click install button.
5. Installation in progress
6. Few minutes later, you will get the following Success screen! 🙂
Select the Launch TFS Configuration Tool check box, and then click Configure button! I will post other screens tomorrow! 🙂
An invalid VARIANT was detected during a conversion from an unmanaged VARIANT to a managed object – C#
Posted by Rajanihanth in .Net, C# on October 16, 2012
I have got this exception after I fixed this error, please check this post and read the following…!
Error Message:
“An invalid VARIANT was detected during a conversion from an unmanaged VARIANT to a managed object. Passing invalid VARIANTs to the CLR can cause unexpected exceptions, corruption or data loss.”
Fix:
Just go to the Debug menu in Visual studio and select Exceptions
Click and expand the Manage Debugging Assistants
Find the Invalid Variant node and uncheck the Thrown check box.
Click Ok and run the application, That’s all! Happy Programming..! If you want to read more about this issue, just read this post! 🙂
References:
http://www.dotnetspider.com/forum/299944-System.outofmemoryexception.aspx
http://blogs.msdn.com/b/yangxind/archive/2006/03/21/556837.aspx
The CLR has been unable to transition from COM context 0xXXXXXXX to COM context 0xYYYYYYY for 60 seconds – C#
Posted by Rajanihanth in .Net, C# on October 16, 2012
Few months ago, I was developing a small windows application which gathers data from Active Directory(AD) and dumping into a SQL database table. There were around 18 to 20,000 records involved in the process. After developing and testing components with few data, everything was okay but when I run the application I got following error message:
“The CLR has been unable to transition from COM context 0x2297ce0 to COM context 0x2297f30 for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages. This situation generally has a negative performance impact and may even lead to the application becoming non responsive or memory usage accumulating continually over time. To avoid this problem, all single threaded apartment (STA) threads should use pumping wait primitives (such as CoWaitForMultipleHandles) and routinely pump messages during long running operations.”
I didn’t want to spend too much time with this error and I have found the quick fix from this site, if you want to know more about this please read there. 😉
Here are the steps to fix this error;
Step 1: Go to Debug –> Exceptions in Visual Studio 2010 (I was using 2010)
Step 2: Click on Managed Debug Assistants
Step 3: Un-check the ContextSwitchDeadlock and click OK
That’s all, the problem was fixed but I have got an other error, please see the same kind of solution here.
References:
http://dotnetdud.blogspot.ca/2009/01/clr-has-been-unable-to-transition-from.html
Difference between ‘Shadowing’ and ‘Overriding’ (Shadowing vs Overriding) – C#
Posted by Rajanihanth in .Net, C#, Tech Tips-.Net, Versus (vs) on July 29, 2012
This is a very quick Tech-Tips..! Actually Shadowing is VB.Net concept, in C# this concept called hiding! We will see this chapter later. 🙂
Shadowing : Creating an entirely new method with the same signature as one in a base class.
Overriding: Redefining an existing method on a base class.
- Both are used when a derived class inherits from a base class
- Both redefine one or more of the base class elements in the derived class
If you want to read more regarding this, just follow this MSDN topic.
class A { public int M1() { return 1; } public virtual int M2() { return 1; } } class B : A { public new int M1() { return 2; } public override int M2() { return 2; } } class Program { static void Main(string[] args) { B b = new B(); A a = (A)b; Console.WriteLine(a.M1()); //Base Method Console.WriteLine(a.M2()); //Override Method Console.WriteLine(b.M1()); Console.WriteLine(b.M2()); Console.Read(); } }
The output is : 1, 2, 2, 2
Difference between ‘ref’ and ‘out’ parameters (ref vs out) – C#
Posted by Rajanihanth in .Net, Tech Tips-.Net, Versus (vs) on July 14, 2012
- Both are treated differently @ runtime but same in the compile time, so can’t be overloaded.
- Both are passed by references except ‘ref’ requires that the variable to be initialized before passed.
ref:
class Program { static void M1(out int i) { i = 1; i += 1; } static void Main(string[] args) { int j; //Not assigned M1(out j); Console.Write(j); Console.Read(); } } }
The output is : 2
out:
class Program { static void M1(ref int i) { i = 1; i += 1; } static void Main(string[] args) { int j=0; //Assigned M1(ref j); Console.Write(j); Console.Read(); } }
The output is same: 2, but we have to assigned the variable before used otherwise we will get an error.
The type or namespace name ‘SharePoint’ does not exist in the namespace ‘Microsoft’ (are you missing an assembly reference?) – SharePoint 2010 Client Object Model dlls
Posted by Rajanihanth in .Net, Client Object model, SharePoint 2010 on July 13, 2012
When I started using the Client Object model (Client OM) in SharePoint 2010, I have got this simple error and I just want to share with you in this blog. Following was my develpment environment.
- Windows 7, 64 bit
- Console Application Visual Studio 2010
- Added Client Object Model references (Microsoft.SharePoint.Client.dll & Microsoft.SharePoint.Client.Runtime.dll) to the solution
After setting up all the above, I was trying to add the client reference to the code ‘using Microsoft.SharePoint.Client;‘and then I have got the following error and warnings 🙂
The text format of error is:
"The type or namespace name 'SharePoint' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)"
It’s an obvious error message and the reason of this error is:
SharePoint 2010 does not support .Net 4.0 in default and Visual Studio 2010 default framework is .Net 4.0.
Here are the simple steps to fix this:
Step 1: Right click on the project –> Properties
Step 2: Change the Target framework –> .Net Framework 3.5
Step 3: Warning message will be popping up, click Yes.
That’s all. Happy Coding..!
Please Note: If you use Windows Application then you will be getting an other error message! 😦 To solve this issue just click here.
How to get the current user’s OU (Organizational Unit) from AD (Active Directory) – C#
Posted by Rajanihanth in .Net, Active Directory on February 7, 2012
There are so many ways to get the user details form AD (Active directory), but I wanted to get the current user’s OU (Organizational Unit) from Active directory. There is no any direct method to get the OU (Actually I could not find anything on the web, if anyone get an easy way to find-out please let me know). I am currently developing a Custom Search for SharePoint 2007 and according to the OU, I want to display the search results.
Here is the method I have created and most of the comments I have put in the code itself. I used Asp.net and C#.
public string GetOU(string username) { string result = string.Empty; using (HostingEnvironment.Impersonate()) { //Getting the domain PrincipalContext yourDomain = new PrincipalContext(ContextType.Domain); //Finding the user UserPrincipal user = UserPrincipal.FindByIdentity(yourDomain, username); //If the user found if (user != null) { // Getting the DirectoryEntry DirectoryEntry directoryEntry = (user.GetUnderlyingObject() as DirectoryEntry); //if the directoryEntry is not null if (directoryEntry != null) { //Getting the directoryEntry's path and spliting with the "," character string[] directoryEntryPath = directoryEntry.Path.Split(','); //Getting the each items of the array and spliting again with the "=" character foreach (var splitedPath in directoryEntryPath) { string[] eleiments = splitedPath.Split('='); //If the 1st element of the array is "OU" string then get the 2dn element if (eleiments[0].Trim() == "OU") { result = username + "-" + eleiments[1].Trim(); break; } } } } } return result; }
Please don’t forget to add the following references:
using System.Collections; using System.DirectoryServices.AccountManagement; using System.DirectoryServices; using System.Security.Principal;
If you want to get the current user’s OU then you can call this method in the Page_Load event.
protected void Page_Load(object sender, EventArgs e) { string userName = Context.User.Identity.Name; LabelOU.Text = GetOU(userName); }
You will get the output like this:
OU-Name
References: