.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Base class contructor firing first. why?

Posted By:      Posted Date: September 06, 2010    Points: 0   Category :ASP.Net
Hi,If I create instance of derived class, the code in base class constructor executing first. why is that? any reason?see code belowPublic Class class1 Sub New() Console.WriteLine("1") End Sub End Class Public Class class2 Inherits class1 Sub New() Console.WriteLine("2") End Sub End Class

View Complete Post

More Related Resource Links

How to change the default page base class?


I've tried setting the <pages pageBaseType="DynamicWebPage" /> value in web.config, but when I response.write out the page type, I'm still getting Microsoft.WebPages.WebPage.

I'm simply trying to sub-class WebPage and add some additional functionality such as a dynamic PageData dictionary similar to Phil Haack's dynamic ViewData dictionary.



Can I replace the EntityObject as base-class in Entity Designer 3.5 sp1?


I'm using EF3.5sp1 for a project, and I've been working around many of its problems... as such, my entity partial classes have a lot of logic in them for change-tracking and whatnot.  Obviously, I'd like to factor this logic out into a common base class, but of course all my objects must derive from EntityObject.  Is it possible to tell them to derive from some class of my own invention (which would actually likely derive from EntityObject themselves)?

I'd rather avoid editing the EDMX file unless the changes will be safe on entity-model-update, since I'm still making changes to the database schema in this early state of my project.


Also, is there any good workaround for the fact that the change isn't tracked when you change EntityReference.EntityKey?

CLR Inside Out: What's New in the .NET Framework 4 Base Class Library


Just about everyone who uses Microsoft .NET uses the Base Class Libraries (BCL).When we make the BCL better, almost every managed developer benefits. This column will focus on the new additions to the BCL in .NET 4 beta 1.

Justin Van Patten

MSDN Magazine September 2009

CLR Inside Out: Base Class Library Performance Tips and Tricks


The common language runtime (CLR) sits at the very heart of managed code. Indeed, it is the heart of managed code, so to understand managed code you need to understand the CLR.

Kit George

MSDN Magazine January 2006

Serial Comm: Use P/Invoke to Develop a .NET Base Class Library for Serial Device Communications


Out-of-the-box, the only way of coding RS232 serial communications applications in the .NET environment is to import the outdated and somewhat limited MSComm ActiveX control. This article describes the development of a lean, multithreaded, and modern RS232 base class library in C# managed code. The library uses Platform Invocation Services to interact with the Win32 API directly. Application programmers can use the library from any .NET language through inheritance; the article explores examples written in C# and Visual Basic .NET.

John Hind

MSDN Magazine October 2002

Web Service and Base Class Sub Routines



I have several Web Services that I call using jQuery, they are all <WebMethod()> _    Public Function and return either a boolean or string, depending on the function.

I have some Web Service functions, where I would like to call sub routines I have in my base class, they are Public Sub's.

When I add a call of a sub routine in the Web Service function, I get a blue line that says 'Object reference not set to an instance of an object'.  If I change the sub routine to Public Shared Sub, then the blue line and error go away, but I get other errors from the calls I was successfully making to the base class routines before.

Is there a way to get these two to work together?

"The base class includes the field 'WebUserControl1', but its type (common_WebUserControl) is not


I tried to convert a project from ASP.NET 1.1 to 2.0 and found one big problem which stops the whole process.

An .aspx page from the subfolder "admin" includes a user control from the subfolder "common". Both subfolders ("admin" and "common" are in the root).

- admin
-- aspx page
- common
-- user control

The page works well when started from Visual Studio, but when the project is precompiled for deployment, the next error occurs:

"The base class includes the field 'WebUserControl1', but its type (common_WebUserControl) is not compatible with the type of control (ASP.common_webusercontrol_ascx)"

I tried to use "Reference" in the .aspx page, but that doesn't work.

Does anybody know any workaround for this?

override of base class error please help!!!


i would really like to override http keepalives for my webservice and i found some source code that seems promising but i get an error that says

"function GetWebRequest" Cannot be declared override. 


    Protected Overrides Function GetWebRequest(ByVal uri As Uri) As WebRequest
        Dim webRequest = DirectCast(MyBase.GetWebRequest(uri), HttpWebRequest)
        webRequest.KeepAlive = False
        Return webRequest
    End Function

how do i implement this into my serivice and why im i getting this error??? in other words what in hell is the uri that i should be passing into this function.

Any assictance would be greatly appreciated.


BinaryFormatter, SortedSet base class and a few instance variables.

/* This example successfully serializes and deserializes the SortedSet<string> base contents, but all the instance variables show up uninitialized. Here's the output: n1: 0 n2: 0 str: s == "String 1" s == "String 2" s == "String 3" Any ideas? */ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.Serialization.Formatters.Binary; using System.Runtime.Serialization; using System.IO; [Serializable] public class MyObject : SortedSet<string> {     public MyObject() : base() { }     protected MyObject(SerializationInfo info, StreamingContext context)         : base(info, context)     {     }     public int n1 = 0;     public int n2 = 0;     public String str = null; } namespace BasicBinarySerializationInheritanceFromSortedSet {     class BasicBinarySerializationInheritenaceFromSortedSetTest     {         static void Main(string[] args)         {             {                 MyObject obj = new MyObject();   &nb

MouseUp event not firing on ActivityDesigner class?

I have a custom control derived from ActivityDesigner.  I'm basically retemplating the contol to give it a stylized look and feel ... I want to add the ability to change the Display Name by swapping out the TextBlock with a TextBox on MouseUP - but this event is not firing. I can handle the MouseDown event and it works OK, except it enters the Edit mode when dragging the activity around.  Is the MouseUp handled at the base level?  Is there a way to work around this? 

Can you Serialize a Derived class, cast as it's base?

Can you Serialize a Derived class, cast as it's base? (Using the stock XmlSerializer.Serialize?)   (The overall goal I'm trying to achieve, is I have 1 object, and I need to serialize it in 2 different ways, 1 with full info, one with half info, and I *thought* a base class would be the way to do it)   e.g. I have a base and derived class   [XmlRoot("MyBaseXml" )] public class MyBaseClass { public string baseField = "base" ; } [XmlRoot("MyDerivedXml" )] public class MyDerviedClass : MyBaseClass { public string derivedField = "derived" ; }   I make a new instance of my derived class MyDerviedClass obj = new MyDerivedClass();   And then I have the following serialization method(s)   /// <summary> /// Saves an object to a file /// </summary> /// <param name="obj"> Object to save</param> /// <param name="fileName"> Path to output to</param> public void Serialize(object obj, string fileName) { Type type = obj.GetType(); XmlSerializer xmlSerializer = new XmlSerializer(type); Serialize(obj, fileName, type); } /// <summary> /// Saves an object to a file casting it as a specific type /// </summary> /// <param name="obj"> Object to save</param> /// <param name="fileName"

Is it possible to add a class method to CLR base class like Date?

Hi All, I would like to add a class method like ParseYYYYMMDD to the Date base class. So that I can use the following code. Dim result As Date = Date.ParseYYYYMMDD(dateString) Any idea? Is it possible via extension? Thanks! Regards, AlexAlex Lau from HKSAR

Is it possible to get a base class by it's member?

I.e. I've got my class that contains a Panel. I do dragdrop with that panel, so when i get an form.dragdrop event I'm getting my Panel in eventArgs. I want to get the base class (MyClass), that contain that Panel to invoke some methods. Smth. like GetParent Class... Could you tell, is it possible?

Calling a static method in a static class from a base class.


I have the following static class and method:

public static class GenericList


      public static List<DocumentElement> PopulateGenericList()



What is the syntax to call the PopulteGenericList() method from a base class?



Raising events of base class


I have base class with public event:

public abstract class MessageProcessor
        public event EventHandler<MessageEventArgs> MessageReceived;


And I want to raise this event from derived class:

public class Device:MessageProcessor

        void timerAlive_Elapsed(object sender, ElapsedEventArgs e)
            MessageReceived(this, null); //compilation-time error here



Error :The event 'WorkServerClasses.MessageProcessor.MessageReceived' can only appear on the left hand side of += or -= (except when used from within the type 'WorkServerClasses.MessageProcessor')

How can I resolve this?

Base Class Library FAQ


There's already a BCL FAQ on MSDN,


This document is a supplement to the FAQ.

1.     How do I compare two DateTime objects?

Assign values to base class properties


In my controller have a FormViewModel which inherits from a domain class declared in dbml.  In the constructor of the FormViewModel I want to do a shorthand assignment to the inherited class properties with the passed in object (ie thisPerson) without iterating through each property of the inherited class and assigning its value with corresponding property in the passing in object. Should I use super, base, this, or something else?

public MyFormViewModel: Person
  public SelectList Cities {get; private set;}
  public SelectList State {get; private set;}

  public MyFormViewModel(){}

  public MyFormViewModel(Person thisPerson) 

        this = thisPerson; 
     //or super = thisPerson;
     //base = thisPerson;


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend