Wednesday, April 27, 2005

SubClassing in C#

After years of coding in C# it feels a bit embarassing to be posting this... But

public class person
{
private person(){/* ...Constructor implementation... */ }
// ... More Attributes and Methods...
}

public class customer : person
{
public customer () { /* ...Constructor implementation... */ }
// ... More Attributes and Methods...
}

in the above code snippet .NET fires a compile time error basically becuase 'person' has a private constructor! It's a no brainer than you can't directly create objects out of classes which have private constructor - but sub classing them - well, i couldn't say for sure that that sub classing wasn't allowed too until that code snippet had been punched in and tried out!

public class person
{
public person() {/* ...Constructor implementation... */ }
// ... More Attributes and Methods...
}

public class customer : person
{
public customer () { /* ...Constructor implementation... */ }
// ... More Attributes and Methods...
}

The above code, of course works! Moral of the story - all classes that you want to sub class must have public / protected constructors. All classes that you want to create objects out of must have public / protected constrctors... and even after years of coding there's always something we're either yet to learn or have conveniently forgotten!

Tuesday, April 26, 2005

Strange Adventure with SQL Server

What does The followin query return IF orders table does NOT have a transfer_id column?

select transfer_id from orders

if you answered a runtime error - you were correct! read on...

What does the following query give you if transfers has transfer_id columns BUT orders table does NOT have any transfer_id column?

select * from transfers
where transfer_id in
(select transfer_id from orders)

if you answered a runtime error - you're WRONG! SQL Server simply returns ENTIRE Transfers table to you without ANY errors!

Any reasons behind this strange behavior? None comes to my mind!!!

but,

select * from transfers
where transfer_id in
(select orders.transfer_id from orders)

DOES return a runtime error and is a MUCH professional and better way of writting Sql Qruery!

Monday, April 18, 2005

ASP.NET 2 and 1 Conflicts!!

After i loaded loaded VS.NET 2005 and tricked my firefox to act on iexplore.exe a strange error started popping up when trying to debug web applications from VS 2003! it said something like Auto-attach to process w3wp.exe failed... error code 0x8013134b.

Did a bit of googling and turns out - firefox has nothing to do with this! it's a conflict between VS 2003 and VS 2005! An ASP.NET 2.x and 1.x conflict to be more specific! A few sites seems to give you solutions but none seemed to work for me - (a combination of more than what one usergroup suggested did the trick however:) ) here's what allows you to get debug mode running in VS 2003...


  • Ensure that you register 1.x with iis again - go to command prompt of VS 2003 and type aspnet_regiis -i
  • change your default web site's asp.net version to 1.x - open properties in iis manager, select properties, go to asp.net tab and select 1.x as your version!
  • Just to be sure is registered 1.x again - (aspnet_regiis -i)
  • deployed a new project and hit F5 - and there it was!!! running as sweet as before!


So did the aspnet_regiis -i work fist time / second time? what happens to VS 2005 now if i try to run web applications there with debug mode...? For now, my apps in 2003 are running again and that's good enough... maybe i'll do a aspnet_regiis -i
from VS 2005 beta while playing around with Whidbey! and then choose ASP.NET v 2.x from iis :)

Tuesday, April 12, 2005

Deploying Web Services With MSI Project

While creating a deployment project to deploy Web Services, The Web Deployment project needs to deploy "Content" files for the Web Service Projects ALONG with the Primary Output of the Web Services and Other other project that the Web Service depends on!
The ASMX files are treated as Content Files for the Web Services and will NOT be packaged into the Cab file till you explictly ask VS.NET Deployment Project to include content files!

Serializing an Object to a XML document!

Pretty elementary but cool concept of Serializing an object to XMLDocument that i read about on the net somewhere... This gives you serialized 'Web Service' like output for virtually any object that is serializable!!!
...
using System;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
using System.Text;
using System.Data;

namespace com.miswaco.OracleApplicationsWebServices.ServiceFramework
{
///
/// Additional XML Functionality to serialize objects to XML Documents!
///

public class CustomXMLHelper
{
public CustomXMLHelper() {}
public static XmlDocument GetobjAsXmlDocument(object obj)
{
XmlDocument retVal = new XmlDocument();
//Convert the obj into an Xml document
XmlSerializer ser = new XmlSerializer(obj.GetType());
StringBuilder sb = new StringBuilder();
TextWriter writer = new StringWriter(sb);
ser.Serialize(writer, obj );
StringReader reader = new StringReader(writer.ToString());
//Read the Xml from the StringReader object
DataSet dst = new DataSet();
dst.ReadXml(reader);
retVal.LoadXml(dst.GetXml());
return retVal;
}
}
}

Thursday, April 07, 2005

fxCop … A Cop or a Guide?

fxCop – a cool new tool from Microsoft which is supposed to analyze your code against pre-set or custom created rules and programming guidelines and warn you if your code doesn’t adhere to good programming conventions and practices.

Ironically however, fxCop code when analyzed using fxCop produces 158 warning messages – 32 of them being critical :)!

Microsoft points out however, that fxCop is more like a guide – and once the messages have been pinpointed you must make a conscious decision to either ignore them or go back and fix them. The least you can do is ensure that no new violations creap into your projects. Anyways, this tool does a great job and teaching programmers how to code … read more @ MSDN Blogs for fxCop