A Place for C Sharpers/.Netters

I Will do coding till last moment of life-Kiran Patil

Archive for April, 2008

How to Create ASP.NET web Service and how to consume it: A Beginner’s Guide

Posted by kiranpatils on April 23, 2008

Creating this post especially for my friend. Who want to learn How to create His First Web Service. If you too want to do the same then go ahead and start your visual studio.

Service

  1. Click on Web Site Project

  2. It will open New Web site Dialog box. Choose ASP.NET web service and give it appropriate name(HelloWorldService) and select your Coding language(C#). Click OK.

    It will take some time because it will make everything ready for you sir. So, you can start quickly

  3. What it has created?

    Service.cs: is the main file where you can write you code. E.g application logic etc..Calling Data Access layer etc.

    Service.asmx will expose your service to outer world.

  4. Web Method

    If you will see Service.cs it has one method already written. You can use it as a reference implementation

[WebMethod]

public
string HelloWorld() {


return
“Hello World”;

}

Any method you want to expose you have to declare it by attribute WebMethod

Let’S create our new method.So, you can get more into methods.

Just copy paste above one and modify it will like this:

///
<summary>


/// This method will take argument as a string and show it with greeting


///
</summary>


///
<param name=”name”></param>


///
<returns></returns>

[WebMethod]


public
string
MyHelloWorld(string name)

{


return
“Hello World,”+name;


//Here you can call your Insert,Update,Delete from DAL and write return statement

}

  1. Build Web Site [CTRL+SHIFT+B]. That’s it we have our service Ready. Let’s create one consumer for it.

Consumer

Our Service is ready. It will take name and return it with Hello World name. I am creating here one Windows application for demo. You can create any client to use it.[That's why it is service :) ]

1. Click on your solution file name Means [Your focus should be on C:\HelloService or your solution name]

2. Select File | Add | New Project

3. It will open Add New Project Dialog Box. Select Windows application and give appropriate name to it. Click OK

4. So now you will have structure as under:

5. Right Click on HelloWorldConsumer project and Click on Add Web Reference- For Adding service reference.

6.It will open Add Web Reference window. Just click on Web Services in this solution. Because we have our service under same solution.

7. It will find out service. Just click on it.

8. It will load our methods as shown here: [Web reference name I had changed "localhost" to "HelloWorldClient". So you should also do it. Its good practice]. Click on Add reference button. – Which will add our service reference to client.

9. Now your soln structure should look like:

10. Click on Form1 and drag some controls so we can test it. So, your form should look like this.

11. Double click on “Call Service” Button it is Buttton1 for me. For creating its Click event handler code. And it will point it to handler code call your service here and show result in Messagebox as shown here.

12. Build solution. And ensure that HelloWorldConsumer-windows application is your startup project. Then run the project [CTRL+F5]

13. looks Cool… It’s working man. Try with your name and enjoy!!!

Links:

http://quickstarts.asp.net/QuickStartv20/webservices/

http://www.w3schools.com/webservices/default.asp

Happy Service Coding!!!

I have also kept solution here for reference. But I request you first try yourself and if get some error then and then try this. Pls try to do it yourself first. you can download it from Here

Update:

Add Reference in VS 2008 — http://www.carlosfemmer.com/post/2008/01/How-to-add-web-reference-in-VS-2008-Project.aspx

Thanks to Ravindra Joshi for pointing it out!

 

Posted in ASP.NET | Tagged: | 12 Comments »

Page Building Error Points to temp file

Posted by kiranpatils on April 23, 2008

Error 43 ‘ASP.managebooking_alldetails_aspx.GetTypeHashCode()’: no suitable method found to override c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\developmentwebsite\1a446f94\c51a7975\App_Web_ngex7yua.0.cs 12120

Error 44 ‘ASP.managebooking_alldetails_aspx.ProcessRequest(System.Web.HttpContext)’: no suitable method found to override c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\developmentwebsite\1a446f94\c51a7975\App_Web_ngex7yua.0.cs 12125

Error 45 ‘ASP.managebooking_alldetails_aspx’ does not implement interface member ‘System.Web.IHttpHandler.IsReusable‘ c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\developmentwebsite\1a446f94\c51a7975\App_Web_ngex7yua.0.cs 1329

I was getting this error..something i had changed i remember but error is not much informative to tell me what i had done wrong. My code which is not working is as under:

—–OLD CODE——
.aspx code

<%@ Page Language=”C#” MasterPageFile=”~/Shared/ManageBookingMasterPage.master” AutoEventWireup=”true” CodeFile=”AllDetails.aspx.cs” Inherits=”Booking_ViewEditBooking_All_AllDetails” %>
.aspx.cs
public partial class ManageBooking_AllDetails
{

}
Suddenly i found the Solution


.aspx code

<%@ Page Language=”C#” MasterPageFile=”~/Shared/ManageBookingMasterPage.master” AutoEventWireup=”true” CodeFile=”AllDetails.aspx.cs” Inherits=”ManageBooking_AllDetails” %>

.aspx.cs class name

public partial class ManageBooking_AllDetails
{
}

you too got it na?? nope..In .aspx file in inherits you should give name of your code-behind[.aspx.cs] file name. That’s it

Posted in ASP.NET | Leave a Comment »

The DataSourceID of ‘gridID’ must be the ID of a control of type IDataSource. A control with ID ‘objectcontainerdatasourceID’ could not be found.

Posted by kiranpatils on April 22, 2008

The DataSourceID of ‘gridID’ must be the ID of a control of type IDataSource. A control with ID ‘objectcontainerdatasourceID’ could not be found.

Scenario:

I have One grid which is binded with objectcontainerdatasource. But when i try to run a page it shows me error as shown above.. i can’t figure it out why it working like so…but my colleague had found its solution.. Actually i have kept Grid and Objectconatinerdatasource within a Master page and it is underneath of LetZonePart..which is main problem.. when you run a page then it will hide all other controls which will not going to show on page e.g. ObjectContainerdatasoruce: so my old code which is not working is here:

<asp:Content ID=”Content1″ ContentPlaceHolderID=”LeftZoneParts” runat=”Server”>
<asp:GridView ID=”Mygview” runat=”server” AutoGenerateColumns=”false” Width=”950px” DataSourceID=”Myobjcdatasrc” >
<Columns>
//My Cols
</Columns>
</asp:GridView>
<pp:ObjectContainerDataSource runat=”server” ID=”Myobjcdatasrc” DataObjectTypeName=”Employee” />
<asp:content>

Solution:

Just put your grid and all stuff in ContentPlaceHolder rather than LeftZonePart. That’s it..working one is here…

<asp:Content ID=”Content1″ ContentPlaceHolderID=”ContentPlaceHolder1″ runat=”Server”>
<asp:GridView ID=”Mygview” runat=”server” AutoGenerateColumns=”false” Width=”950px” DataSourceID=”Myobjcdatasrc” >
<Columns>
//My Cols
</Columns>
</asp:GridView>
<pp:ObjectContainerDataSource runat=”server” ID=”Myobjcdatasrc” DataObjectTypeName=”Employee” />
<asp:content>

Happy Coding!!!

Posted in ASP.NET | Tagged: | Leave a Comment »

TDD (Test Driven development) and Nunit Quick start: A Beginner’s Guide

Posted by kiranpatils on April 11, 2008

TDD (Test Driven development) and Nunit Quick start

What Is Test-Driven Development?
Test Types
Black Box vs. White Box Test
Black Box Testing
White Box Testing
One of the biggest challenges you will face when writing units tests is to make sure that each test is only testing one thing. It is very common to have a situation where the method you are testing uses other objects to do its work. If you write a test for this method you end up testing not only the code in that method, but also code in the other classes. This is a problem. Instead we use mock objects to ensure that we are only testing the code we intend to test. A mock object emulates a real class and helps test expectations about how that class is used. Most importantly, mock objects are:

  1. Easy to make
  2. Easy to set up
  3. Fast
  4. Deterministic (produce predictable results)
  5. Allow easy verification the correct calls were made, perhaps in the right order

The following example shows a typical mock object usage scenario. Notice that the test code is clean, easy to understand and not dependent on anything except the code being tested.

namespace UnitTestingExamples.Tests {

using DotNetMock;

using System;

 

[TestFixture]

public class ModelTests

{

[Test]

public void TestSave()

{

MockDatabase db = new MockDatabase();

db.SetExpectedUpdates(2);

 

ModelClass model = new ModelClass();

model.Save( db );

 

db.Verify();

}

}

}

As you can see, the MockDatabase was easy to setup and allowed us to confirm that the Save method made certain calls on it. Also notice that the mock object prevents us from having to worry about real databases. We know that when the ModelClass saves itself, it should call the database’s Update method twice. So we tell the MockDatabase to expect two updates calls, call Save and the confirm that what we expected really happened. Because the MockDatabase doesn’t really connect to a database, we don’t have to worry about keeping “test data” around. We only test that the Save code causes two updates.

“When Mock Objects are used, only the unit test and the target domain code are real.” — Endo-Testing: Unit Testing with Mock Objects by Tim Mackinnon, Steve Freeman and Philip Craig.

 

 

Q.How I will use it [Practical Approach]?

Ans. Till this we have seen a lots of Theory and concepts about Nunit and eager to apply it ??. just follow the steps given as under

 

  1. Create a Console Application name it “HelloUnit Test”.
  2. Right Click on Reference and click on Add Reference.


  3. Click on browse and Select nunit.framework.dll

Figure 1 : Located at ‘c: \Program Files\Nunit 2.4.6\bin’


  1. Add New Class file to your project [which we will use for Writing Test] and name it ‘MyTest’
  2. For making ‘MyTest’ Testable by Nunit we have to do some steps.
    1. Reference to Nunit namespace by using NUnit.Framework;
    2. Make It public and provide attribute [TestFixture]


    3. [Optional] Create a Public Constructor. [Otherwise CLR will have it so not needed].
    4. Create a method which will be tested by Nunit. Inshort create one Method with Public Void, no parameters and attributed as [Test]


  3. Starting Nunit GUI for Testing
    1. You can open it from ‘C:\Program Files\Nunit 2.4.6\bin\nunit.exe’.
    2. OR Choose it from Start menu or Shortcut Icon on desktop


    3. To Load your Assembly Click on File->Open Project
    4. Select you Assembly [HelloUnitTest.exe]. @ path ‘../ HelloUnitTest\bin\Debug’.
    5. Click on Open you will see a screen like this


    6. Click on Run. If green bar comes means your test has been run successfully.


  4. Let us add something to test.[To fail the test]


  5. Now compile your solution and Press the Run button Again. You will see the screen like below. [Which says that Test Method has been failed]


  6. Now I think you can try on yourself all the Attributes like [SetUp], Teardown etc.
  7. I have used the [Setup] like this.
using System;

using System.Collections.Generic;

using System.Text;

using NUnit.Framework;

namespace HelloUnitTest

{


//STEP-1

[TestFixture]


public
class
MyTest

{


int i = 0;


//STEP-2


//Optional Create a Public Constructor

[SetUp]


public
void Init()

{

i = 1;

}

[Test]


public
void TESTMethod()

{


Assertion.Assert(i == 1);

 

} } }


 

 

 

References and Links

Link  Description 
http://www.nunit.org/index.php?p=download Download latest version from here. I have downloaded version “NUnit-2.4.6-net-2.0.msi”
http://msdn.microsoft.com/msdnmag/issues/05/12/VisualStudioAddins/default.aspx#S1 TestDriven.NET Add-In
http://www.falafel.com/community/blogs/testing/archive/2006/03/04/Unit-Testing-In-Visual-Studio-2005.aspx Creating Test
http://www.codeproject.com/KB/trace/tomaznunittests.aspx

Debugging Nunit Test Scripts

http://www.codeproject.com/KB/dotnet/tdd_in_dotnet.aspx

Test-Driven Development in .NET

http://www.codeproject.com/KB/cs/autp1.aspx Advanced Unit Testing
http://www.codeproject.com/KB/cs/unittestmanual.aspx  
http://azagappan.wordpress.com/2007/10/18/nunit-core-concepts/ Core Concepts of Nunit
http://www.tangent-studios.com/programming/csharp/NUnit2Tut/NUnitV2Tut.htm The people who can’t cook 
http://www.bandgap.cs.rice.edu/sites/comp410s05/Resources/Tutorial%20-%20NUnit.pdf Nunit Overview and Tutorial
http://www.nunit.org/index.php?p=quickStart&r=2.4.6 Documentation for Getting Started By Nunit peoples.
http://www.testdriven.net/ Add-in for VS  
http://www.flazx.info/ftanD7Ak/0735619484.zip.htm
Test Driven Development [Must Have Book]

    

Kent Beck, in his book Test-Driven Development: By Example (Addison-Wesley Professional, 2003), defines test-driven development using the following rules:

  • Never write a single line of code unless you have a failing automated test.
  • Eliminate duplication.

The first rule is straightforward: don’t write code without having a failing automated test because the tests embody the requirements that the code must satisfy, as stated in the Introduction. If there is no requirement (that is, test), there is no need to implement anything. This rule prevents us from implementing functionality that is not tested and not needed in the solution.

The second rule states that no code should be duplicated in the program. Code duplication is the epitome of bad software design; it leads to inconsistency problems and a reduced level of confidence in the program over time as people forget where the duplications are. If there is code duplication, it is the programmer’s job to remove it when it is seen. (In Extreme Programming [XP], this rule is called “Once and Only once!”)

Kent’s definition does not make a distinction between different types of tests[1] . All he says is that the tests have to be automated, which we agree with entirely. However, it is useful to categorize the test types around the constituents who produce them—for example, customers who specify the functionality, programmers who implement the functionality, and testers who support development during the development of the code and critique the final result after the code is complete. The two constituents that this book focuses on are programmers and customers.     

Programmer Tests

If we are talking about the programmers writing the code, it is useful to think of these tests as focused on technology, so you can refer to them as technology facing or programmer tests. Some people refer to this type of test as a unit test; we are specifically not calling it that because unit testing’s purpose is much different from what we are doing in TDD. Because the audience for these tests is programmers, it is critically important that the tests be written in a language that the programmers understand. (It’s even better if they are in the same language as the production code.) If the tests are in the same language, the programmer doesn’t have to change paradigms to write tests.

Customer Tests

Tests that customers use to specify the functionality they need and how it should work can be referred to as business facing or customer tests. These types of tests are often referred to as acceptance tests or functional tests. As in the case of programmer tests, the tests need to be written in a language that the customer understands. The goal is to empower the customer to be able to write tests.

Conclusion: Nunit comes in First type means Programmer Tests

Black box testing is different from white box testing.  The kind of testing that you can perform on the code determines, among other things, the complexity of the unit test.

A black box test (also known as a “functional test”) is one in which you feed it inputs and verify the outputs without being able to inspect the internal workings.  Furthermore, one doesn’t usually have information regarding:

  • how the box handles errors
  • whether your inputs are executing all code pathways
  • how to modify your inputs so that all code pathways are executed
  • dependencies on other resources

Black box testing limits your ability to thoroughly test the code, primarily because the you don’t know if you’re testing all the code pathways.  Typically, a black box test only verifies that good inputs result in good outputs (hence the term “functional test”).

Classes are often implemented as black boxes, giving the “user” of the class access only to the public methods and properties that the implementer selected.

A white box provides the information necessary to test all the possible pathways.  This includes not only correct inputs, but incorrect inputs, so that error handlers can be verified as well.  This provides several advantages:

  • you know how the box handles errors
  • you can usually write tests that verify all code pathways
  • the unit test, being more complete, is a kind of documentation guideline that the implementer can use when actually writing the code in the box
  • resource dependencies are known
  • internal workings can be inspected

In the “write the test first” scenario, the ability to write complete tests is vital information to the person that ultimately implements the code, therefore a good white box unit test must ensure that, at least conceptually, all the different pathways are exercised.

Another benefit of white box testing is the ability for the unit test to inspect the internal state of the box after the test has been run.  This can be useful to ensure that internal information is in the correct state, regardless of whether the output was correct.  Even though classes are often implemented with many private methods and accessors.  With C# and reflection, unit tests can be written which provide you the ability to invoke private methods and set/inspect private properties.

 

Q. what are Unit Tests?

Ans. According to Ron Jeffries, Unit Tests are “programs written to run in batches and test classes. Each typically sends a class a fixed message and verifies it returns the predicted answer.”

 

Q.What is Nunit?

Ans. Nunit is mostly used for Testing from so many times. Those systems provide base classes from which you have to derive your class and do its testing. But honestly speaking they also have some restrictions because C# only allows single inheritance. But .NET has introduced new concept to programming that solves this problem which is called Attribute. Attribute allows you to add metadata to your code. They don’t affect your code but it provides extra information about your code. It provides information to others. Using this feature exactly Nunit works. The Test Runner application scans your compiled code looking for attributes that tells it which classes and methods it have to use for testing. It then use Reflection to execute those methods. Nunit provides verity of attributes like Test Fixture, Test etc. which we will see in next section.

Q. Nunit Core Concepts or Attributes

Ans.

TestFixture Attribute

 

This attribute is to specify the class that contains the test case. This attribute is placed before the classes that contain test code.

When you attach this attribute to a class in your project, the Test Runner application will scan it for test methods.

 

using System;

using NUnit.Framework;

namespace NUnitCoreConcepts

{

[TestFixture]

public class CoreConcepts()

{


}

} 

    

NOTE: The only restrictions on classes that use the TestFixture attribute are that they must have a public default constructor (or no constructor which is the same thing. Because CLR itself provides default constructor which is public).

[TEST] Attribute

 

The [Test] attribute specifies the Test Methods inside the Test Class. The Test Methods are the methods that contains code for testing.

 

The method must be public, return void, and take no parameters or it will not be shown in the Test Runner GUI and will not be run when the Test Fixture is run

 

using System;

using NUnit.Framework;

namespace NUnitCoreConcepts

{

[TestFixture]

public class CoreConcepts

{

[Test]

public void AdditionTest()

{

int num1 = 3;

int num2 = 4;

Assert.AreEqual(7, num1 + num2);

}

}

}

 

Assertions

 

In NUnit, Assertions are the way to determine whether the Test Code in the Test method passed or failed. In the above example ASSERT.AREEQUAL () method verifies the actual and expected and says whether the test passed or not. There are many static methods in Assert class. Some of them are

Assert.AreEqual()

Assert.IsTrue()

Assert.IsNull() …

namespace UnitTestingExamples {

using System;

using NUnit.Framework;

 

[TestFixture]

public class SomeTests

{

[Test]

public void TestOne()

{

int i = 4;

Assertion.AssertEquals( 4, i );

}

}

}

 

[Setup] Attribute [TearDown] Attribute

 

The [Setup] attribute specifies the method that has to be executed before every Test method is executed. It normally contains initialization code.

The most common use for these attributes is when you need to create dependent objects (e.g., database connections, etc.).

 


The [TearDown] attribute specifies the method that has to be executed after the Test method is executed. Its normally contains code to release the resources.

 

 

using System;

using NUnit.Framework;

namespace NUnitCoreConcepts

{

[TestFixture]

public class CoreConcepts

{

private int num1 ;

private int num2 ;

[SetUp]

public void Init()

{

num1 = 3;

num2 = 4;

}

 

[TearDown]

public void TearDown()

{

NUM1=0;

NUM2=0;

}

 

[Test]

public void AdditionTest()

{

Assert.AreEqual(7, num1 + num2);

}

}

}

 

 

ExpectedException Attribute

 


ExpectedException attribute specifies that executing the test code would raise an exception. See the example below

 

using System;

using NUnit.Framework;

namespace NUnitCoreConcepts

{

[TestFixture]

public class CoreConcepts

{

[Test]

[ExpectedException(typeof(DivideByZeroException))]

public void DivideByZeroExceptionTest ()

{

int zero = 0;

int num = 100;

int result = num / zero;

Assert.Fail(“We are failing the test if it doesn’t raise an divide by zero exception”);

}

}

}

 

When this code runs the test will pass only if it throws an exception of type DivideByZeroException

 

Let us write some code using it.

 

Ignore Attribute

To indicate that this test should not be run now. Probably You won’t use it than also just for knowledge keep it in mind.

using System;

using NUnit.Framework;

namespace NUnitCoreConcepts

{

[TestFixture]

public class CoreConcepts

{

[Test]

[Ignore("We're skipping this one for now.")]

public void DivideByZeroExceptionTest ()

{

int zero = 0;

int num = 100;

int result = num / zero;

Assert.Fail(“We are failing the test if it doesn’t raise an divide by zero exception”);

}

}

}

 

Q. How to Run your Test?

NUnit comes with two different Test Runner applications: a Windows GUI app and a console XML app. Which one you use is a matter of personal preference. To use the GUI app, just run the application and tell it where your test assembly resides. The test assembly is the class library (or executable) that contains the Test Fixtures. The app will then show you a graphical view of each class and test that is in that assembly. To run the entire suite of tests, simple click the Run button. If you want to run only one Test Fixture or even just a single test, you can double-click it in the tree

There are situations, particularly when you want to have an automated build script run your tests, when the GUI app isn’t appropriate. In these automated builds, you typically want to have the output posted to a website or another place where it can be publicly reviewed by the development team, management or the customer. The Nunit 2.0 console application takes the assembly as a command-line argument and produces XML output. You can then use XSLT or CSS to convert the XML into HTML or any other format. For more information about the console application, check out the Nunit documentation.

Using Mock Objects – DotNetMock

Link: http://sourceforge.net/projects/dotnetmock/

Posted in Nunit, TDD | 1 Comment »

How to Check/uncheck radio button in Grid?

Posted by kiranpatils on April 11, 2008

I have one grid in which I want to checked/unchecked radio button value conditionally. Means if EmployeeID!=null then checked else unchecked

I have done it like this:

.aspx code

<input type=”radio” id=”rbtest” <%#IsChecked((string)Eval(“bookingIDField”))%>/>

.aspx.cs code

protected string IsChecked(string boolvalue)

{

return (!string.IsNullOrEmpty(boolvalue))? “checked=\”checked\”" : “” ;

 

}

That’s it..

Posted in ASP.NET | Leave a Comment »

Adding Total number of rows and formatting PagerRow In gridview with Default paging

Posted by kiranpatils on April 3, 2008

Hi..i have one grid which shows data from objectconatinerdatasource. I am using Default paging which shows pager row like this

1 2 3 4 5

But i want like this

1 2 3 4 5 (Page <CURRENT PAGENUMBER> of <TotalRecords> )

How to achieve this??

Some one will say use custom paging..But i am disagree with them. Because when i can do things easily then why should i do it other way….So here is my way to do this.

1. Handle your grid’s DataBound event.

2. Handler of it will do my task.

protected void GridViewEmp_DataBound(object sender, EventArgs e)
{
if (GridViewEmp!= null)
{
//Showing Search Result Count
//Get Top Pager Row from a gridview
GridViewRow row = GV_SearchBooker.TopPagerRow;
if (row != null)
{

//create one Cell for adding in my current paging strip

TableCell infocell = new TableCell();
infocell.Text = ” Page ” + (GridViewEmp.PageIndex + 1).ToString() + ” of ” +                      GridViewEmp.PageCount.ToString() +
“(” + _totalrowscount.ToString() + ” Records)”;

//Getting table which shows PagingStrip

Table tbl = (Table)row.Cells[0].Controls[0]; //Will Find table                                      tbl.Rows[0].Cells.Add(infocell);
}
}
}

Explanation:

This line needs more exp as i think:

Table tbl = (Table)row.Cells[0].Controls[0]; //Will Find table

row = will have TopRow

it has cells collection cells[0] means 1 2 3 4 5 6 and out of it controls[0] means that <table> just add one <td> that’s it by using Tablecell..

Posted in ASP.NET | Tagged: , | Leave a Comment »

An error occurred creating the configuration section handler for cachingConfiguration

Posted by kiranpatils on April 3, 2008

Server Error in ‘/DevelopmentWebsite’ Application.

Configuration Error

Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: An error occurred creating the configuration section handler for cachingConfiguration: The given assembly name or codebase was invalid. (Exception from HRESULT: 0×80131047)

Line 139:        </authorizationProviders>
Line 140:    </securityConfiguration>
Line 141:    <cachingConfiguration defaultCacheManager=”Cache Manager”>
Line 142:        <cacheManagers>
Line 143:            <add expirationPollFrequencyInSeconds=”2000″ maximumElementsInCacheBeforeScavenging=”1000″ numberToRemoveWhenScavenging=”10″ backingStoreName

If you are also facing same error as above…then i have its solution. Here it is

Solution:

Just open your web.config file and locate <cachingConfiguration> under it <backingStores>

under it you will have <add   encryptionProviderName

this tag has attribute type here you will find

type=”Microsoft.Practices.EnterpriseLibrary.Caching.BackingStoreImplementations.NullBackingStore, Microsoft.Practices.EnterpriseLibrary.Caching, Version=3.1.0.0, Culture=neutral, PublicKeyToken=null” name=”Null Storage”/>

have you seen this publicKeyToken is null..so how can it work..yes this is the solution.

so just add publicKeyToken value to assembly’s Token…so you will have now

<add encryptionProviderName=”" type=”Microsoft.Practices.EnterpriseLibrary.Caching.BackingStoreImplementations.NullBackingStore, Microsoft.Practices.EnterpriseLibrary.Caching, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a” name=”Null Storage”/>

Error is resolved..

Why this problem? 

I am not going to repeat its reason for problem. pls have a look at it from here:

http://blogs.msdn.com/echarran/archive/2006/07/13/665005.aspx 

Thanks a lot to this guy [if your error goes out then pls say thanks to echarran].

Posted in Enterprise Library | Tagged: | Leave a Comment »

tinyint+invalid cast exception with DataReader

Posted by kiranpatils on April 2, 2008

today i had faced a wired error in my DAL it was throwing an error invalid cast my code is like this:

int empid = reader.GetInt32(“EMPID”); //throws invalid cast..

i checked it with my database schema EMPID is tinyint. which is main cause of an error..

Solution:

I had done R&D and come in to know that:

SQL SERVER Stored tinyint as 8bit[1byte] .so we can’t fetch it using getint32…so to fetch it i had changed my code to:

 int empid = Convert.ToInt32(reader.GetBytes(“EMPID”)); //worked 

Posted in .NET, SQL SERVER 2005 | Leave a Comment »

Using showModalDialog() with an ASP.NET page that does PostBack opens another window

Posted by kiranpatils on April 2, 2008

Posted in Uncategorized | Leave a Comment »

Debugging client JavaScript in Visual Studio 2005

Posted by kiranpatils on April 2, 2008

I need to debug JS and i found it from here:

http://geekswithblogs.net/lazydeveloper/archive/2006/07/10/84552.aspx

Thanks to blogging..

Posted in Uncategorized | Leave a Comment »