FIX for Wrapper assembly for type library “MSHTML” cannot be found after Windows 10 upgrade.

Here we will see how to resolve an issue that comes after you have upgraded to Windows 10. After upgrading the system visual studio started showing errors that Metadata file .dll could not be found. After re-building, re-starting the solution as well as changing the references nothing changed and the errors still appeared. If you closely look at the Build failed errors you will find the below para.

C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.CurrentVersion.targets(2234,5): warning MSB3283: Cannot find wrapper assembly for type library “MSHTML”. Verify that (1) the COM component is registered correctly and (2) your target platform is the same as the bitness of the COM component. For example, if the COM component is 32-bit, your target platform must not be 64-bit.

Now this is very the problem is. If you check your references you will find an yellow warning mark to MSHTML. If you check this with your windows 8.1 machine it will be pointing to an ActiveX control that was registered from a file in GAC.

Continue reading FIX for Wrapper assembly for type library “MSHTML” cannot be found after Windows 10 upgrade.

Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.

Here we will see how to solve one of the most common runtime error ““Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.””

This error may occur in the following scenario’s

1) Response.End
2) Response.Redirect
3) Server.Transfer

Reason for this exception occurrence is because page execution is stopped and sent to the Application_EndRequest event in the application’s event pipeline.

When we call Response.End method it stops the page execution and raises the EndRequest event and thus the line of code after Response.End is not executed. Same thing happens when we use Response.Redirect and Server.Transfer methods because both they both call Response.End internally.

When a call is made to destroy a thread, the CLR internally throws a ThreadAbortException. This is a exception that can be caught and handled explicitly.

Use a try-catch statement to catch the exception as below

 catch (System.Threading.ThreadAbortException)  
     //do nothing  

While using Response.Redirect we can use an overload of the same

 Response.Redirect(String url, bool endResponse);  

It passes false for endResponse parameter to suppress the internal call to Response.End

Use Server.Execute instead of Server.Transfer as the execution of code happens on the new page.

3-Tier Architecture In Using C#.

Here we will see how to implement three tier architecture(also known as n-tier architecture) in application.Three tier architecture is a well known architecture in software development and you can implement it in web based as well desktop applications.

Three tier architecture basically means dividing your project into three layers

1) User Interface Layer [UI] (Also known as Application Layer or Presentation Layer)

2) Business Access Layer [BAL] (Also known as Business Logic Layer)

3) Data Access Layer [DAL]

The advantage of this functionality is it makes a logical separation of components so if in near future we want to replace / change our database we need to change only data layer or if we need to change user interface we need to change only user interface layer and rest remains the same.

Continue reading 3-Tier Architecture In Using C#.

Check Username Availability In Using Jquery Ajax

Here we will see how to check for username availability using Jquery Ajax method in In our website we normally keep the username unique and so it must be checked before saving the record that it has not been taken by any other user. We can do this validation on the submit button click or use OnTextChanged event but it is not so user friendly as the page gets Postback.

Following example demonstrates the same using Jquery Ajax method. Here while creating a user account he can check by making an Ajax call to [Web Method] at server side to get the availability of the username. It matches the user input against the database records and returns the text based on the availability. You can modified the code as per your requirements:

Continue reading Check Username Availability In Using Jquery Ajax

Pass DataTable To Store Procedure Using Table Value Parameter.

Here we will see how to pass a datatable as parameter to stored procedure in C# using the sql server user defined table type. One of the way to speed up your application is to reduce the trips to your database especially by avoiding a call to stored procedure multiple times.

Table-valued parameters let you pass a collection of table rows as a parameter to your stored procedure. They allow passing entire sets of rows from ADO.Net code to SQL Server.

Below we will see the steps that needs to be followed to implement this functionality.

Continue reading Pass DataTable To Store Procedure Using Table Value Parameter.

Prevent Cut, Copy And Paste Operation For Text Box In Asp.Net Using Jquery.

Here we will see how to block a user from performing CUT, COPY and PASTE operation on a particular textbox using jQuery. Sometimes it is required to disable the cut copy paste operation and make user mandatory to type the details.

The code is as follows: Continue reading Prevent Cut, Copy And Paste Operation For Text Box In Asp.Net Using Jquery.

Check-Box List Validation In

Here we will see how to validate check box list control in We will use javascript and custom validation to implement this functionality.
The code is as follows:

<html xmlns="">
<head runat="server">
    <script type="text/javascript">
        function CheckboxValidation(sender, args) {
            var checkBoxList = document.getElementById("<%=chk_list1.ClientID %>");
            var checkboxes = checkBoxList.getElementsByTagName("input");
            var isValid = false;
            for (var i = 0; i < checkboxes.length; i++) {
                if (checkboxes[i].checked) {
                    isValid = true;
            args.IsValid = isValid;
    <form id="form1" runat="server">        
            <asp:CheckBoxList runat="server" ID="chk_list1">
                <asp:ListItem Text="Example 1" Value="Example 1"></asp:ListItem>
                <asp:ListItem Text="Example 2" Value="Example 2"></asp:ListItem>
                <asp:ListItem Text="Example 3" Value="Example 3"></asp:ListItem>
                <asp:ListItem Text="Example 4" Value="Example 4"></asp:ListItem>
                <asp:ListItem Text="Example 5" Value="Example 5"></asp:ListItem>
                <asp:ListItem Text="Example 6" Value="Example 6"></asp:ListItem>
            <asp:CustomValidator ID="Checkbox_CustomValidator" runat="server"
                ErrorMessage="One or more checkboxes must be chosen">
            <asp:Button runat="server" ID="btn_submit" Text="Validate" ValidationGroup="CheckBoxValidation" />
            <asp:ValidationSummary runat="server" ID="validateionsummary" ValidationGroup="CheckBoxValidation" ShowMessageBox="true" ShowSummary="false" />

Solution To Request Timed Out Exception

Here we will see how to resolve the “Request Timed Out” issue in web applications. The basic reason for this exception to be thrown is that it exceeds the maximum number of seconds that a request is allowed to execute. Default value for the executionTimeout attribute is 90 seconds. This value can be altered by specifying executionTimeout in <httpRuntime> element under <system.web> section in web.config file. The executionTimeout attribute indicates the maximum number of seconds a request is permitted to run before being terminated by the web application. This error occurs mostly in either uploading large files or if you run a query that takes more than 90 seconds to process.

Following are the steps we need to follow to set the executionTimeout attribute value in the web.config file.

Step 1) Open the web.config file.

Step 2) Add the httpRuntime element in the system.web section.

Step 3) Add executionTimeout attribute to the above added httpRuntime element.

 <httpRuntime executionTimeout="3600" />

[Note : Increase the value of the executionTimeout attribute according to your requirement.]

Step 4) Save web.config file.

Solution to potentially dangerous Request.Form value was detected from the client.

Here we will see how to solve the error for potentially dangerous Request.Form value was detected from the client. Basic reason for the occurrence of this error is because prevents any attempt to compromise the security of application by script injection like cross site scripting etc.

This error occurs when end user enters any scripting / html tag<> in the inputbox. You can disable request validation by setting validateRequest=false in the page directive or in the configuration section but it is strongly recommended that your application explicitly check all inputs in this case.

To resolve this issue we can do following things.

1. Set validateRequest property to false in page directive.

<%@ Page validateRequest="false" %>

2. Set validateRequest property to false in the <pages /> section under <system.web>
section of web.config file if you want to turn off request validation globally(Entire Application).

      <pages validateRequest="false" />

3. For .NET 4 or higher we need to add requestValidationMode=”2.0″ to the httpRuntime configuration section of the web.config file

<httpRuntime requestValidationMode="2.0"/> validates all input controls for potentially unsafe contents that can lead to cross site scripting and Sql injections and so if you disable the request validation then you should check the input for any cross-site scripting (XSS) attacks.