Author Archives: Atul Verma

About Atul Verma

I am working at Microsoft as a .NET Consultant. I have an experience of 5 years in .NET technologies and application packaging. My expertise include .NET Framework(4.0, 3.5, 3.0, 2.0), WPF, WCF, ASP.net, AJAX, Web Services, Enterprise Library, Enterprise Applications, SharePoint 2010, Web Services, SQL Server (2008, 2005), Open Xml, MS Word Automation.

How to remove ViewState from ASP.NET web page and save in Session using SessionPageStatePersister

By default ViewState is saved inside the web page. In ASP.NET using SessionPageStatePersister ViewState can be saved inside Session instead. This helps in securing the ViewState as well as reducing the size of the web page.

The code to implement the same is overriding the PageStatePersister for the ASP.NET page as displayed below. PageStatePersister provides the base functionality for ASP.NET view state persistence mechanisms.
Continue reading

Important counter sets for monitoring ASP.NET performance using Perfmon Tool

For Any ASP.NET application, monitoring performance is an important job. Performance Monitor tool having some nice features that helps us to monitor ASP.NET Application performance in a better way.In this Tips I  discuss four important counter sets that are very useful in monitoring ASP.NET performance.

Continue reading

Fix/Resolution: Unable to install Windows Server AppFabric through Microsoft Web Platform Installer

This tips talked about resolution of one very common problem that many developer might encounter during Windows server App Fabric Installation. While trying to install Windows Server AppFabric thorough Microsoft Web Platform Installer encountered the installation failed as displayed below . Continue reading

How to upload a document in SharePoint 2010 using Client Context Object Model ?

In order to use ClientContext I need to add reference to two dll’s to my project i.e. Microsoft.SharePoint.Client.dll and Microsoft.SharePoint.Client .Runtime.dll. In this Post we will talk abou8t 1) how to Get ListItemCollection from SharePoint document list using CAML 2) Upload a document to SharePoint Document list . Get ListItemCollection from SharePoint Document list using CAML: CodeProject. I can get the ListItemCollection as displayed in code snippets below

 ListItemCollection listItems = GetListItemCollectionFromSP("FileLeafRef", documentName, "Text", 1); 

The GetListItemCollectionFromSP returns the List item and the parameters to method are
name – Name of the FieldRef, value = value to match for that FieldRef, type – Type of the value and rowLimit – Maximum number of rows to fetch
Continue reading

Setting the right target framework for a .NET project in Visual Studio 2010

In this Tips I’ll discuss about Client Profile which is nothing but a subset of the associated framework and optimized for client applications e.g. .NET Framework 4 Client profile is a subset of .NET Framework 4.

You can view or change the target framework for a project in Visual Studio 2010 as displayed below

image

Client Profile improves the deployment experience by having smaller download sizes and quicker install times as it has a smaller redistribution package that installs the minimum set of client assemblies on the user’s computer, without requiring the full version of the .NET Framework to be present.

If an assembly is referred which is not in Client Profile then the full version of .NET Framework is required. For more details please refer this msdn article .NET Framework Client Profile

How to test a class member that is not public using Visual Studio 2010 ?

There are various ways to test a Class member which is not public

  • By making the private members public of a class under test
    • Breaks the encapsulation principle
    • API is modified just for the sake of testing
  • By making the private members internal of a class under test and annotate the assembly with internalsVisibleTo attribute and you can read more about it at http://msdn.microsoft.com/en-us/library/0tke9fxk.aspx
    • Breaks the encapsulation principle
    • API is modified just for the sake of testing
  • Make the private members reachable through a public member of a class under test and test these public members
    • Breaks the encapsulation principle
    • API is modified just for the sake of testing
  • Use reflection to invoke the non public members of a class under test

Using reflection is abstracted in Visual Studio so we can use

  • PrivateObject to access non public Instance members of a class under test
  • PrivateType to access static members of a class under test

These classes are inside Microsoft.VisualStudio.TestTools.UnitTesting namespace. I have created code snippets in Visual Studio 2010.CodeProject

PrivateObject:

PrivateObject class is used to access instance based members of  a class under test. The methods and properties of this class are displayed below
image
e.g. We have a BankAccount class that contains a private method i.e. VerifyAmount as displayed below

public class BankAccount
{
//Private method to test
private bool VerifyAmount(double amount)
{
return (amount <= 1000);
}

In order to unit test VerifyAmount method using PrivateObject class the code is displayed below

[TestMethod()]
public void VerifyAmountTest()
{
//Using PrivateObject class
PrivateObject privateHelperObject = new PrivateObject(typeof(BankAccount));
double amount = 500F;
bool expected = true;
bool actual;
actual = (bool)privateHelperObject.Invoke("VerifyAmount", amount);
Assert.AreEqual(expected, actual);
}

Continue reading

How Dynamic Language Runtime(DLR) feature in .NET Framework 4 is a boon for debugging COM objects

The dynamic language runtime (DLR) is a new runtime environment that adds a set of services for dynamic languages to the CLR. For more details regarding new features of .NET Framework 4 please read New C# Features in the .NET Framework 4 and What’s New in the .NET Framework 4

In this blog I’ll show how this feature can make life easy while developing/debugging COM applications and compare the same COM application running in frameworks prior to .NET Framework 4.

I’ll compare how easy it is to debug a Word Addin in .NET Framework 4 than frameworks prior to it e.g. .NET Framework 3.5.

As displayed below I’ve the screenshot from VS 2008(.NET Framework 3.5) Quickwatch window

image

I want to visualize the items of this collection so when I try to get the item at index 1 of COM object (ComAddIns in this example) .NET runtime throws exception as displayed below

image

In VS 2010(.NET Framework 4) Quckwatch window as highlighted in Red there is now a Dynamic View that displays members of the COM object I am debugging

image

When the Watch window displays an object that implements the IDynamicMetaObjectProvider. interface, the debugger adds a special Dynamic View node to the watch display. The Dynamic View node shows members of the dynamic object but does not allow editing of the member values. For more information please read Dynamic View

Now I can view the item(ComAddin in this example) at index 1 of COMAddins object in .NET Framework 4 because of DLR as displayed below

image

Shared By : Atul Verma

Blog : http://www.atulverma.com/