Wednesday, September 30, 2009

Microsoft Visual C# 2008 Compiler could not be created

 

Today i got the error(‘Microsoft Visual C# 2008 Compiler could not be created. QueryService for '{7D960B16-7AF8-11D0-8E5E-00A0C911005A} failed) when i try to open my existing project in Visual Studio.I repaired my Visual Studio 2008 using VS 2008 CD.But the same error :(.

Then i googled it . i got the solution .

Solution

  1. open command prompt
  2. Navigate to C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE (if your visual studio is installed in the corresponding location)
  3. type devenv /ResetSkipPkgs

Note ResetSkipPkgs

Now my problem is solved :)

Sunday, September 27, 2009

C# New Features – Till Visual Studio 2008 SP1

1) Implicitly Typed Local Variables

Local variable can be declared as var instead of explicit type.The compiler automatically takes the necessary type.This example shows this.

private void Bind()
        {
            DataClassesDataContext db = new DataClassesDataContext();
            var sString = "anishmarokey";
            var query = from n in db.tblNames
                        select n;
        }

Result for var query;

queryResult

By using ILDASM ,See the result for var sString and var query var copy

2) Object and Collection Initializers


  • Object Initializers

With out invoking the constructor ,values can be accessible to fileds or properties

in .NET 2.0 invoking constructor value

using System;
class objectInitializers
{
    public int Age { get; set; }
    public string Name { get; set; }
}
class Application
{
    static void Main()
    {
        objectInitializers o = new objectInitializers();
        o.Age = 24;
        o.Name = "anishmarokey";
    }
}

The compiler takes it as

objini

In .NET 3.5 without invoking constructor

using System;
class objectInitializers
{  
    public int Age { get; set; }
    public string Name { get; set; } 
}

class Application
{
    static void Main()
    {
         objectInitializers obj = new objectInitializers { Age = 24, Name = "anishmarokey" };
    }
}

The compiler takes it as


objini1
Note : Code size is different,for .NET 3.5 Code size is little higher.All the other things are same

  • Collection Initializers

When we want to initialize a collection class that class should initialize IEnumerable.

in .NET 2.0

static void Main()
    {
        List<string> l = new List<string>();
        l.Add("A");
        l.Add("B");
        l.Add("C");
    }

The compiler takes it as

collec2

in .NET 3.5

static void Main()
    {
        List<string> l = new List<string> { "A", "B", "C" };
    } 

The compiler takes it as

collec3

Note : Code size is different,for .NET 3.5 Code size is little higher.All the other things are same

3) Extension Method

As per ScottGU - Extension methods allow developers to add new methods to the public contract of an existing CLR type, without having to sub-class it or recompile the original type.

using System;
public static class NewFeature
{
    public static int TointNewFeature(this int i, int j)
    {
        return i + j;
    }
    public static int TointOldFeature(int i, int j)
    {
        return i + j;
    }
}
class App
{
    static void Main()
    {
        int iDemo = 2.TointNewFeature(3);
        Console.WriteLine(iDemo);
        iDemo = NewFeature.TointOldFeature(2, 3);
        Console.WriteLine(iDemo);
    }
}

4) Anonymous Type

A convenient way to encapsulate a set of read only properties into a single object without having to first explicitly define type.

 DataClassesDataContext db = new DataClassesDataContext(); 
            var query = from n in db.tblNames
                        select new { n.name };
5) Lambda Expression( => )
It can be used to create a delegate or a expression type
Example taken from MSDN


delegate int del(int i);
    static void Main(string[] args)
    {
        del myDelegate = x => x * x;
        int j = myDelegate(5); //j = 25
    }

6) Auto Implemented Properties

If we declare this the compiler automatically adds the get accessor method and set accessor method to the corresponding properties.

in .NET 3.5

class Test
{
    public int Age { get; set; }
}

The compiler takes it as

autoimple

Page Events – MasterPage + WebUserControl + Page + WebUserControl

 

The page events Life Cycle in ASP.NET in Web Form application is a follows as .

preinit

GreenPage_Init copy

RedBoxPage_Init 

yellowPage_Init

page_init

Page_InitComplete

Page_PreLoad

Page_Load

yellowPage_Load

 GreenPage_Load

RedBoxPage_Load 

Page_LoadComplete

Page_PreRender

yellowPage_PreRender

GreenPage_PreRender

RedBoxPage_PreRender 

Page_PreRenderComplete

Page_SaveStateComplete

GreenPage_Unload

RedBoxPage_Unload 

yellowPage_Unload

Page_Unload

 

 

Each Box are stands for

Page

BlackBox

 WebUserControl Registered in Page

RedBox

Master page

yellow

 WebUserControl Registered in Master Page

Green

Wednesday, September 23, 2009

ASP.NET Page Life Cycle

Step 1 : Asp page consist of both .aspx and .cs page . When the page hits first the Asp.Net engine coverts the HTML portion into a structured series of programmatically created web controls.

E.g : I created a page Default.aspx page and place a TextBox1 in .aspx page.When the page compiles for the first time.A auto generated class file created(WINDOWS\Microsoft.NET\Framework\version\Temporary ASP.NET Files) its look like as follows

Consider a aspx page created like this.

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    </br>
    What is your gender?
    <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
    </form>
</body>
</html>

  Corresponding .CS page is  


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
}


The Compiled page after first hit

aspTextbox


Note : the TextBox1 is created in the class file.

During the second hit onwards it takes from the corresponding page(i.e it won’t create a .cs page again)

The purpose of auto generated class is to create a control hierarchy.The control hierarchy for the previous page is


controlhierarchy copy


If you set Trace="true" .You can see the below image.


PageEventsControls


Step 2 : PreInit


  • Checks the IsPostBack property to determine whether this is the first time page is load.

  • Page event to set Theme , ie when the page before initialize.

Step 3 : Init

  • All control has been initialized in the order of controls in the control Hierarchy

Step 4 : InitComplete

  • After the page is been initialized.

Step 5 : PreLoad

  • Event before the page is loaded

Step 6 : Load

  • calls the onload() event method and set properties for all controls in the page

Step 7 : Control Events

  • button click ,SelectedIndexChanged etc

Step 8 : LoadComplete

  • All the controls in the page has been loaded.

Step 9 : PreRender

  • Event to take final changes to the content of the page or its control.After this event all the control moves to the IOStream into a HTML format

Step 10 : SaveStateComplete

  • View sate is changed for all controls and page for postback purpose by calling SaveViewState().

Step 11 : Render

  • This is not an event ,but control’s markup to send to browser.

Step 12 : UnLoad

  • Final clean up is happens

Sunday, September 13, 2009

Windows Live Writer - For Better Blogging

In my last post i wrote  how to copy a Code Snippet form visual studio to a blog . Today when i gone through some of the sites which says Windows live writer helps to write better blogs.

Steps that i followed to write a blog

step 1 : Download

Step 2 : After installation go to start –> programs –>  Windows Live –> Windows Live Writer

                               windows live writer

Step 3 : Windows Live write ask for the details about your Blog details .After all the windows live writer open as shown below

 

                     windows live writer Main

Now you can write and publish your post :)

For Copying code from visual studio to blog is as follows

Step 1 : Go to Visual studio and copy the code that you want

 

                                Windows live Visual studio

 

Step 2  : Select Code Snippet from Windows Live Writer

 

            windows live writer code snippest

Step 3 : Which opens a new window as shown below.From there select Edit –> Paste then Click Insert.

 

                windows live writer code

Step 4 : the output is displayed in your blog,when you click you publish in windows live writer.

Friday, September 11, 2009

WPF(Windows Presentation Foundation)

Which helps to develop rich windows and smart client user interfaces with 2-D ,3-D,animations,Styles etc .Which offers a new markup language known as XAML (Extensible Application Markup Language ),to define UI elements,databinding,eventing and other features.





Wednesday, September 9, 2009

Const Vs Fields

Constant : constant is stored in module's metadata after compilation, so it cannot change at the runtime .

E.g :

10 const int i = 9;


Note : Only primitive types(int,boolean,char etc ) can be Constants.Then the compiler takes const as literal(The value is hardcode in source code ) as shown below.





Fields: Are dynamic memory allocation, so value can be allocated at runtime only.

E.g :

10 static readonly int i = 9;

Readonly – fields can be written only with in constructor method.


Note: No need to be primitive type and it support both static and non-static fields





Note : Any datatype the compiler directly supports are called primitive datatype .

E.g : in C# an int maps directly to a System.Int32

Sunday, September 6, 2009

How to copy code from Visual studio to Html page

When i am give some code snippets its not a good way to read for readers.And when i go to see some other blogs they are given the code in very easily and neat way.Today i got the solution,am sharing the same with you all.

Steps to follow

Step 1 : Get the Addins from here
Step 2 :Extract it to your Visual studio Addins folder(C:\Users\anishmarokey\Documents\Visual Studio 2008\Addins) ,if the Addins folder is not there create it.
Step 3 : Open visual studio,click in Tools -> Add-in Manager



Step 4 :Add-in Manager a message box will come.Checked the check box for "Copy as HTML" and click ok.



Step 5 :Now you can select any code and when rigth click "Copy As HTML" as shown


Step 6 : Paste in your blog.It looks like as shown below

6 static void Main(string[] args)

7 {

8 }


Thursday, September 3, 2009

Applied Microsoft NET_Framework_Programming by Jeffrey Richter

I am really interested in compiler.So i checked with different book which one is good.At last i got a good one "Applied Microsoft NET_Framework_Programming"

The following are the main topics in the book Applied Microsoft NET_Framework_Programming.

Part I: Basics of the Microsoft .NET Framework
Chapter 1 : The Architecture of the .NET Framework Development Platform

Overview of .NET Frame work is architected.CLR,CLS ,and a good understanding of ILDASM(intermediate laguage de assembler tool)

Chapter 2: Building, Packaging, Deploying, and Administering Applications and Types
This chapter gives a good understanding of how the assembly is build and how the version number is given and also gives a better understanding of Culture.

Chapter 3: Shared Assemblies
This chapter gives a better understanding of week and strong assembly.Why the public key is used etc . The main point in this chapter is GAC,what is the main function of GAC

Part II: Working with Types and the Common Language Runtime

Chapter 4: Type Fundamentals
This chapter gives a good understanding of Type safe and type casting
Chapter 5: Primitive, Reference, and Value Types
Primitive Type -Any dataType compiler directly and a good understanding of value type and Reference type

Chapter 6: Common Object Operations
How to compare objects ,object cloning etc

Part III: Designing Types
Chapter 7: Type Members and Their Accessibility
This chapter gives a better understanding of type member and different predefined attribute .

Chapter 8: Constants and Fields
This chapter say what happends in metadata when declare a constant and fields.
Chapter 9: Methods
This chapter gives me a better understanding of constructor,type constructor ,Operator overloading,ref and out ,virtual method
Chapter 10: Properties
This explains properties and indexers
Chapter 11: Events
This explains me How the delegate is Doing its action in events
Part IV: Essential Types
Chapter 12: Working with Text
This explains why the string is immutable ,says how the string is doing its operation with culture
Chapter 13: Enumerated Types and Bit Flags
This chapter goes through the idea of Enum in metadata
Chapter 14: Arrays
The array ,and says array is a reference type and various other methodologies in array
Chapter 15: Interfaces
This chapter goes through the idea of inferface in CLR . Gives me a better idea on the interface.
Chapter 16: Custom Attributes
This gives a better undersatanding of arrtibutes ,how to define user created custom attribute
Chapter 17: Delegates
The Microsoft .NET Framework exposes a callback function mechanism using delegates.
and lot of other various thing of delegates
Part V: Managing Types
Chapter 18: Exceptions
This chapter gives a better understanding of Exceptions.how to write user created exceptions
Chapter 19: Automatic Memory Management (Garbage Collection)
This chapter says how the GC is working.
Chapter 20: CLR Hosting, AppDomains, and Reflection
This chapter says how the CLR is hosting in Windows,what is the use of application domain etc

About author Jeffrey Richter
 
Counter