try...catch...finally...bloggg....: April 2005

try...catch...finally...bloggg....

Thursday, April 21, 2005

Conditional Compilation to Help

I have been using this technique for quiet some time wanted to make this available to everyone who may be facing the problem. We used Canoo webtest for doing the functional and regression testing. I would say its pretty easy to write reusable testcases in the Canoo webtest as its based on XML. The tag set used is also relatively small and easy to get testcases written. Its one of the free tools which will get you started on the budget and is relatively stable than most other tools I evaluated. One of the problem I faced using Canoo webtest was it didnt support the link buttons which we were using in the site. I decided to go this way making all the site buttons to be got from a common base class which when compiled with the BUTTON as true will yield normal buttons which were supported in Canoo webtest and when compiled with BUTTON as false will yield the link buttons which was looking good in our site. Below is the code I use to acheive this.

1 using System;
2 using System.Web.UI;
3 using System.Web.UI.WebControls;
4 using System.Web.UI.HtmlControls;
5 using PeterBlum.VAM;
6
7 namespace KenPeople.JobBoard.Controls
8 {
9 /// <summary>
10 /// This is the button class used through out the project.
11 /// Since canoo webtest doesnt support link buttons we are
12 /// using this technique to test the application. When
13 /// compiled with the BUTTON value defined as true regular
14 /// buttons are rendered in the site. When deployment to
15 /// production after QA is completed compile without setting
16 /// the BUTTON variable so that link buttons are displayed.
17 /// </summary>
18 #if (BUTTON)
19 public class JobBoardButton : System.Web.UI.WebControls.Button {
20 #else
21 public class JobBoardButton : PeterBlum.VAM.LinkButton {
22 #end if
23 }
24 }

Wednesday, April 20, 2005

JMeter for Load, functional and regression testing

I am using JMeter to do all the Load, functional and regression testing in my .NET website. For people who might be familiar with the ACT (Application center test) or the previous WAST I would say its pretty easy to do all the same functionality with JMeter. The tool is pretty robust and after you get thro the initial glitches and gotchas of handling the ASP.NET pages using JMeter everything is pretty breezy. Before using JMeter we were extensively using Canoo Webtest for doing the functional & regression testing. Finally when we found JMeter and its ability to perform the same stuff as Canoo Webtest We switched to JMeter. For people who are using JMeter there is a tool called BadBoy to automatically generated JMeter test cases but I prefer it as only a guideline and we end up handcoding most of the testcases.

Logging Changes Logging Application Block to Log4NET

I am using Logging Application block (LAB) to do all the exception logging in my site presently. I wanted to add more info and debug statements to better help in debugging the application and to give a control flow idea to the new project members. I tried adding DEBUG level messages when entering and leaving a method. I added INFO level messages to print any parameter passed in to help in debugging. This really slowed things down considerably. I have since then evaluated log4net and I am planning to convert from LAB to Log4Net. I have some customization I did to LAB to log all the sql parameters passed to it. Now I am extending Log4Net for the same purpose. I am using version 1.2.9 and ThreadContext class provides a cool Properties map and a stack to store the additional info needed. I have additionally implemented a wrapper on the Log4Net logger class to conditionally compile out the DEBUG and INFO level messages from production release to keep the logging overhead to NIL. I am using at present the RollingFileAppender and the SMTP appender to log messages.

Finding the name of the page after a server.transfer

I have a reset button control which resets all the form elements by sending a new request to the same page as which the button is placed. I was initially getting the filename using the Request.PathInfo variable. Everything was working fine untill one fine morning we were changing the Response.Redirects to Server.Transfer. Apparently after the Server.Transfer the Request.PathInfo was returning the previous page info and my reset was redirecting to it. Now I use Request.CurrentExecutionFilePath and the reset works proper.

Thursday, April 14, 2005

Code highlighter

My effort to find a good code highlighter to use in my blogs ends today.I found this great freeware source code highlighter from ActiPro. The languages currently supported are
  • C#
  • VB.NET
  • HTML
  • CSS
  • JScript
  • VBscript
  • XML
  • SQL
  • Python


Please click Actipro CodeHighlighter to try this control. They have some really cool .NET controls to try out. Below is a gist of their products available. Please visit www.actiprosofware.com for details.

Actipro Software has developed components in C# made especially for other .NET framework developers to use in their applications. These components may be used in any .NET-compatible programming language including C#, VB.NET, and more.
  • SyntaxEditor provides an extremely powerful syntax-highlighting editor control, just like the one in the Visual Studio .NET IDE.
  • UIStudio is a suite of controls that includes docking tool and document window functionality, a TabStrip, and a NavigationBar
  • Wizard adds wizards that comply with the Wizard97 standard to your applications.
  • CodeHighlighter provides flexible syntax-highlighting for code samples in ASP.NET web pages.

Tuesday, April 12, 2005

The located assembly's manifest definition with name xxx.dll does not match the assembly reference

This error got me solve one of my build problems. Sounds wierd. :-). I have recently adopted log4net for the logging in my webapplication. While doing the testing I used the debug version of the log4net.dll and since it is not strongly named my compiled version of dll had its reference. finally I was satisfied with the logging process and changed the log4net.dll to the release version. I compile the project and I end up with this error message. I do some googling and come across with this nice blog Junfeng Zhang's .Net Framework Notes. I look into the issue and find that my clean build had stopped working (due to my previous nant changes) as I didn't delete the dll from my bin folder. I fix the build process and the whole thing works smooth again. In this process I learnt a major lesson about the dependencies and how things are resolved. While upgrading any of your 3rd party components make sure you just dont do an xcopy deployment hoping the changes will not break anything. Make sure to setup runtime binding redirects. Sample redirects for the nunit framework is attached below
1 <runtime>
2 <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
3 <dependentAssembly>
4 <assemblyIdentity name="nunit.framework"
5 publicKeyToken="96d09a1eb7f44a77" culture="Neutral" />
6 <bindingRedirect oldVersion="2.0.6.0" newVersion="2.2.0.0" />
7 <bindingRedirect oldVersion="2.1.4.0" newVersion="2.2.0.0" />
8 </dependentAssembly>
9 </assemblyBinding>
10 </runtime>

Monday, April 11, 2005

using Log4net in ASP.NET application

I tried setting up the logging for our webapplication using Log4net. I looked thro the examples and read some blogs on how difficult it is to setup the whole logging because of the lack of documentation. Read thro these blogs to see the info posted by different people

http://tom.gilki.org/programming/net/120604/
Ryans work blog
http://geekswithblogs.net/flanakin/archive/2004/08/30/10418.aspx

These are the steps which helped me get the logging setup
1.[assembly: log4net.Config.XmlConfigurator(ConfigFileExtension="log4net", Watch=true] this line must be added to the global.asax.cs file
1 // Load the configuration from the 'JobBoard.UI.dll.log4net' file
2 [assembly: log4net.Config.XmlConfigurator(ConfigFileExtension="log4net",
3 Watch=true)]
4 namespace xxxxxx
5 {

2. The name of the configuration file should be the name of the dll into which the global.asax.cs file is getting compiled with an extension of log4net. For eg if your dll generated is foo.dll then your configuration goes into foo.dll.log4net.
3. The configuration file should be located in the application root folder not in the bin folder.
4. Check the permissions on the folder you are logging the aspnet user account should have write permissions.

below is the sample configuration file I used for appending to the File and to Trace.
1 <?xml version="1.0" encoding="utf-8" ?>
2 <log4net debug="false">
3 <appender name="LogFileAppender"
4 type="log4net.Appender.FileAppender" >
5 <file value="c:\\temp\\webapp-log.txt" />
6 <appendToFile value="true" />
7 <layout type="log4net.Layout.PatternLayout">
8 <conversionPattern value="%date [%thread] %-5level %logger
9 [%ndc] - %message%newline" />
10 </layout>
11 </appender>
12 <appender name="HttpTraceAppender"
13 type="log4net.Appender.AspNetTraceAppender" >
14 <layout type="log4net.Layout.PatternLayout">
15 <conversionPattern value="%date [%thread] %-5level %logger
16 [%ndc] - %message%newline" />
17 </layout>
18 </appender>
19 <root>
20 <level value="DEBUG" />
21 <appender-ref ref="LogFileAppender" />
22 <appender-ref ref="HttpTraceAppender" />
23 </root>
24 </log4net>
25


·