No More Solutions

You can find a lot of debugging and deploying problems while developing applications in .NET and Visual Basic here. There are also some querying tips in SQL and typical source codes which might be useful shared here.

Could not Load Type from Assembly

Could not load type 'xxxxxx' from assembly 'AssemblyName, Version=, Culture=neutral, PublicKeyToken=null'.

This error occurs when trying to open a webpage. The project is built successfully. However, when accessing particular page, the error pops out. The error message is actually quite long. This is only part of the error message.

On Visual Studio, go to menu Tools -> Options -> Debugging -> General -> Disable "Enable Just My Code" options.

PS: I am not sure if there is another more feasible solution. This might only be a workaround. There could be side effects. As of now, it is still working fine after this option is disabled.

Looks like this does not really solve the issue. I find out that if the project or solution is rebuilt, it will go to normal when the web is run. If it doesn't, rebuild, then try it again.

However, when the web is run on debug mode, some pages will get this error, thus not viewable. Another workaround is to view the web in browser (not in debug mode), then attach the process to the web. On Visual Studio, after the web is viewed in browser, go to menu Tools -> Attach to Process -> look for the web server process under which the web is run, e.g. WebDev.WebServer20.EXE
Bookmark and Share

DatePicker Calendar Appears on Top of Page

On page load, datepicker calendar appear on top of a web page which contains datepicker textbox (either visible or hidden).
This issue appears to be happening on Chrome browser. Some may experience it in Internet Explorer.

Source of the problem:
1. There could be more than 1 element on the page which use the same ID.
2. Another possibility is that this is a bug in some of the versions of jQuery style or script.

Either change the ID of the elements with the same IDs if this is the issue.
If the issue is with the jQuery style, add this code to hide the DatePicker calendar when the page is first loaded:

<style type="text/css">
    #ui-datepicker-div { display: none; }
Bookmark and Share

Skip RedirectFromLoginPage in ASP.Net

You have a web application that has a specific redirect page after user logs into the application. But, in certain circumstances, you want to skip it and redirect the user to another page instead of the default page specified after user usually logs into the application.

Thanks to a thread from VelocityReviews, I find the solution.
Instead of using
FormsAuthentication.RedirectFromLoginPage(userName, createPersistantCookie) 
FormsAuthentication.SetAuthCookie(userName, createPersistantCookie) 
methods to redirect the user to the page you want.

Bookmark and Share

Conflict in Namespace


Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30175: module 'ContextMenuHelpers' and module 'ContextMenuHelpers', declared in 'C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\metroweb\87c204db\55321c07\App_Code.rcey62l6.13.vb', conflict in namespace ''.

Source Error:

Line 3:  
Line 4:  Public Module ContextMenuHelpers 
Line 5:  
Line 6:      'Public SysMsg As GlobalResources.SystemMessages = New GlobalResources.SystemMessages()

This problem occurs because more than one file of the same class with the same namespace are found in the folder, usually App_Code folder. If you back-up the source files, make sure it is renamed as another extension, so that it does not conflict with the original file. Otherwise, either put your back-up files outside of the application, or archive it in a compressed file.

In the case I encountered, someone puts a back-up file in a new sub folder inside the App_Code folder. After renaming the extension of the back-up file, the problem is solved.
Bookmark and Share

GetJSON Only Runs Once

$getJSON() method only runs once


If you are using jQuery, and multiple $.getJSON() methods are called in the web page, but can only get one of the getJSON method working, then you will need to add in this code to refresh the cache, before each of the getJSON method.

$.ajaxSetup({ cache: false });

PS: This problem usually occurs when running the web page from Internet Explorer web browser. The same problem should not be encountered when running it from Chrome.
Bookmark and Share

Check if a Function Exists in Javascript

There are times when we want to call a JavaScript function, and in certain circumstances, we want to make sure that the function does exist. e.g. When a dialog window can be opened from more than one page. And, we want to refresh the component of the the parent page from the dialog window. Thus, we need to check if the function really exists.

This is a simple yet useful example to check if a function exists in JavaScript.

<input type="button" onclick="checkFunctionExist();" value="Check Function Existence" />

<script type="text/javascript" language="javascript">

 function testFunction() {


 function checkFunctionExist() {
  if (window.testFunction) alert('testFunction exists');
  else alert('testFunction does not exist');

  if (window.nonExistantFunction) alert('nonExistantFunction exists');
  else alert('nonExistantFunction does not exist');


To check whether a function exists on the parent page (the page which opened the dialog window), use:

if(window.opener.testFunction) alert('testFunction exists');
else alert('testFunction does not exist');

Bookmark and Share

The Server Was Unable to Process The Request Due to an Internal Error

Message: The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs.
This error usually occurs when the application uses web service or similar technologies.

The solution may vary, depending on the issue faced. One thing for sure, there is one way to make sure the exact technical error of the message.

Open the web.config or app.config file of the application, then search for serviceDebug tag, then change the includeExceptionDetailInFaults attribute to true.

<serviceDebug includeExceptionDetailInFaults="false" />

Afterwards, reproduce the error. The exact technical error message should be displayed.
Bookmark and Share

Get The First and The Last Day of The Month

Just saw a question from someone on a mailing list I join asking for how to get the transactions occurring for the last three months (in other words, three months from current date).

First, you may want to do something simple.
To get the first day and the last day of the month, we can use:

DATEADD(month, DATEDIFF(month, 0, GETDATE()), 0),
DATEADD(month, DATEDIFF(month, 0, GETDATE())+1, 0) - 1

If you play around a little bit, you can also get the first day and the last day of the previous month:

DATEADD(month, DATEDIFF(month, 0, GETDATE())-1, 0),
DATEADD(month, DATEDIFF(month, 0, GETDATE()), 0) - 1

To get the transactions for the last three months, we just need to modify the number a little bit.

DATEADD(month, DATEDIFF(month, 0, GETDATE())-2, 0),
DATEADD(month, DATEDIFF(month, 0, GETDATE())+1, 0) - 1

Then, just select the transactions occurring in between these ranges.

DATEADD(month, DATEDIFF(month, 0, GETDATE())-2, 0) AND
DATEADD(month, DATEDIFF(month, 0, GETDATE())+1, 0) - 1

Bookmark and Share

Select Several Rows into One Row in SQL

In SQL Server, there are times when we want to consolidate the content of several rows into one row.

Though it is not meant for sophisticated purposes, there is actually a simple and easy way to do this.
Suppose we have a Member table containing  MemberID and Name fields.

To select the names of the members in one row, simply use the query:

DECLARE @strResult VARCHAR(5000)
SELECT @strResult = COALESCE(@strResult + ', ', '') + Name
FROM Member

SELECT MembersName = @strResult

The result will be:

We can also add some conditions to the select statement.
e.g. To generate the members with name containing 'Himura', we can simply do:

DECLARE @strResult VARCHAR(5000)
SELECT @strResult = COALESCE(@strResult + ', ', '') + Name
FROM Member
WHERE Name LIKE '%himura%'

SELECT TheHimura = @strResult

And we'll get:

That's all folks :)
Bookmark and Share

Formulas Not Calculating in Excel 2007

I just encountered a weird problem.
When I open an excel document, the formula does not seem to calculate. I have a cell containing formula. When I change the value of other cells which form the formula, the cell containing the formula does not change.

Find the solution. Somehow, the settings on my Excel changes.
I am using Office 2007. To enable the formula calculation, go to the Excel Menu, click Excel Options.

On the Formulas tab -> Calculation options, Choose Automatic. It was Manual before. If you choose Automatic, then the result of the formula will be refreshed everytime the document is loaded.

There is another workaround, if you don't want the formula to be recalculated everytime the file is opened. Press F9 to refresh the value of the cells with formula.
Bookmark and Share

Access to Temp Directory is Denied

When deploying application and viewing the web page, the following error occurs:
Access to the temp directory is denied.
Identity 'IIS APPPOOL\WebAppPool' under which XmlSerializer is running does not have sufficient permission to access the temp directory. CodeDom will use the user account the process is using to do the compilation, so if the user doesnt have access to system temp directory, you will not be able to compile. Use Path.GetTempPath() API to find out the temp directory location.

Go to IIS, change advanced settings of the application pool used for the website, then under Process Model Category, change the Identity to ApplicationPoolIdentity.
Bookmark and Share

Cannot Display Web Page on IIS due to Configuration Error


HTTP Error 500.19 - Internal Server Error

The requested page cannot be accessed because the related configuration data for the page is invalid.

Config Error: There is a duplicate 'system.web.extensions/scripting/scriptResourceHandler' section defined
Config File:  Application\Web\web.config

The error on IIS 7.5 should look like this.

Open web.config, and then comment out the "system.web.extensions" sectionGroup under configSections tag.
For example:
<!--<sectiongroup name="system.web.extensions">
Bookmark and Share

Data Type Exception Error

This is only part of the errors, since it is quite long, I will just quote the core part.

System.Web.HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.InvalidOperationException: DataReader.GetFieldType(5) returned null.

This happens when I deploy a web application developed under Visual Studio .Net 2010 using SQL Server 2008 R2 for the database. The query used happen to retrieve fields of type hierarcyid. It works on other machines, this is the first time I encountered such error.
After searching through the internet, I found a solution in a thread on MSDN forum.

Seems that not only for table with field of CLR data type: hierarchyid, fields of Spatial type: geometry and geography also could result in such error.

Add the file C:\Program Files\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SqlServer.Types.dll to the project (as a reference), or simply copy the DLL file to the bin folder in which the project is deployed.

According to the post, it seems that the new SQL Server 2008 data types are not native .NET data types. On the machine where the application is deployed to, the DLL file was not available, so the DataAdapter can't initialize the data types correctly.
Bookmark and Share