.Net Interview Questions and Answers
What is .NET?
.NET is essentially a framework for software development. It is similar in
nature to any other software development framework (J2EE etc) in that it
provides a set of runtime containers/capabilities, and a rich set of pre-built
functionality in the form of class libraries and APIs
The .NET Framework is an environment for building, deploying, and running Web
Services and other applications. It consists of three main parts: the Common
Language Runtime, the Framework classes, and ASP.NET.
How many languages .NET is supporting now?
When .NET was introduced it came with several languages. VB.NET, C#, COBOL and
Perl, etc. The site DotNetLanguages.Net says 44 languages are supported.
How is .NET able to support multiple languages?
A language should comply with the Common Language Runtime standard to become a
.NET language. In .NET, code is compiled to Microsoft Intermediate Language
(MSIL for short). This is called as Managed Code. This Managed code is run in
.NET environment. So after compilation to this IL the language is not a
barrier. A code can call or use a function written in another language.
How ASP .NET different from ASP?
Scripting is separated from the HTML, Code is compiled as a DLL, these DLLs can
be executed on the server.
What is smart navigation?
The cursor position is maintained when the page gets refreshed due to the
server side validation and the page gets refreshed.
What is view state?
The web is stateless. But in ASP.NET, the state of a page is maintained in the
in the page itself automatically. How? The values are encrypted and saved in
hidden controls. this is done automatically by the ASP.NET. This can be
switched off / on for a single control
How do you validate the controls in an ASP .NET page?
Using special validation controls that are meant for this. We have Range
Validator, Email Validator.
Can the validation be done in the server side? Or this can be done only in the
Client side?
Client side is done by default. Server side validation is also possible. We can
switch off the client side and server side can be done.
How to manage pagination in a page?
Using pagination option in DataGrid control. We have to set the number of
records for a page, then it takes care of pagination by itself.
What is ADO .NET and what is difference between ADO and ADO.NET?
ADO.NET is stateless mechanism. I can treat the ADO.Net as a separate in-memory
database where in I can use relationships between the tables and select insert
and updates to the database. I can update the actual database as a batch.
Creating a Key Pair?
You can create a key pair using the Strong Name tool (Sn.exe). Key pair files
usually have an .snk extension. To create a key pair At the command prompt,
type the following command:
sn k
In this command, file name is the name of the output file containing the key
pair. The following example creates a key pair called sgKey.snk.
sn -k sgKey.snk
What is the difference between “using System.Data;” and directly adding the
reference from “Add References Dialog Box”?
When u compile a program using command line, u add the references using /r
switch. When you compile a program using Visual Studio, it adds those
references to our assembly, which are added using “Add Reference” dialog box.
While “using” statement facilitates us to use classes without using their fully
qualified names.
For example: if u have added a reference to “System.Data.SqlClient” using “Add
Reference” dialog box then u can use SqlConnection class like this:
System.Data.SqlClient.SqlConnection
But if u add a “using System.Data.SqlClient” statement at the start of ur code
then u can directly use SqlConnection class.
On the other hand if u add a reference using “using System.Data.SqlClient”
statement, but don’t add it using “Add Reference” dialog box, Visual Studio
will give error message while we compile the program.
What is GAC?
The global assembly cache stores assemblies specifically designated to be
shared by several applications on the computer. You should share assemblies by
installing them into the global assembly cache only when you need to.
Assemblies deployed in the global assembly cache must have a strong name. When
an assembly is added to the global assembly cache, integrity checks are
performed on all files that make up the assembly. The cache performs these
integrity checks to ensure that an assembly has not been tampered with, for
example, when a file has changed but the manifest does not reflect the change.
Use a developer tool called the Global Assembly Cache tool (Gacutil.exe),
provided by the .NET Framework SDK or Use Windows Explorer to drag assemblies
into the cache. To install a strong-named assembly into the global assembly
cache At the command prompt, type the following command:
gacutil I
In this command, assembly name is the name of the assembly to install in the
global assembly cache.
What is a Metadata?
Metadata is information about a PE. In COM, metadata is communicated through
non-standardized type libraries.
In .NET, this data is contained in the header portion of a COFF-compliant PE
and follows certain guidelines;
it contains information such as the assembly’s name, version, language (spoken,
not computera.k.a., culture), what external types are referenced, what internal
types are exposed, methods, properties, classes, and much more.
The CLR uses metadata for a number of specific purposes. Security is managed
through a public key in the PE’s header.
Information about classes, modules, and so forth allows the CLR to know in
advance what structures are necessary. The class loader component of the CLR
uses metadata to locate specific classes within assemblies, either locally or
across networks.
Just-in-time (JIT) compilers use the metadata to turn IL into executable code.
Other programs take advantage of metadata as well.
A common example is placing a Microsoft Word document on a Windows 2000
desktop. If the document file has completed comments, author, title, or other
Properties metadata, the text is displayed as a tool tip when a user hovers the
mouse over the document on the desktop. You can use the Ildasm.exe utility to
view the metadata in a PE. Literally, this tool is an IL disassembler.
What is managed code and managed data?
Managed code is code that is written to target the services of the Common
Language Runtime.
In order to target these services, the code must provide a minimum level of
information (metadata) to the runtime.
All C#, Visual Basic .NET, and JScript .NET code is managed by default.
Visual Studio .NET C++ code is not managed by default, but the compiler can
produce managed code by specifying a command-line switch (/CLR).
Closely related to managed code is managed data–data that is allocated and de-
allocated by the Common Language Runtime’s garbage collector. C#, Visual Basic,
and JScript .NET data is managed by default.
C# data can, however, be marked as unmanaged through the use of special
keywords.
Visual Studio .NET C++ data is unmanaged by default (even when using the /CLR
switch), but when using Managed Extensions for C++, a class can be marked as
managed using the __gc keyword. As the name suggests, this means that the
memory for instances of the class is managed by the garbage collector.
In addition, the class becomes a full participating member of the .NET
Framework community, with the benefits and restrictions that it brings. An
example of a benefit is proper interoperability with classes written in other
languages (for example, a managed C++ class can inherit from a Visual Basic
class).
An example of a restriction is that a managed class can only inherit from one
base class.
What is .NET / .NET Framework?
It is a Framework in which Windows applications may be developed and run. The
Microsoft .NET Framework is a platform for building, deploying, and running Web
Services and applications. It provides a highly productive, standards-based,
multi-language environment for integrating existing investments with
next-generation applications and services as well as the agility to solve the
challenges of deployment and operation of Internet-scale applications. The .NET
Framework consists of three main parts: the common language runtime, a
hierarchical set of unified class libraries, and a componentized version of
Active Server Pages called ASP.NET. The .NET Framework provides a new
programming model and rich set of classes designed to simplify application
development for Windows, the Web, and mobile devices. It provides full support
for XML Web services, contains robust security features, and delivers new
levels of programming power. The .NET Framework is used by all Microsoft
languages including Visual C#, Visual J#, and Visual C++.
What is Reflection?
It extends the benefits of metadata by allowing developers to inspect and use
it at runtime. For example, dynamically determine all the classes contained in
a given assembly and invoke their methods. Reflection provides objects that
encapsulate assemblies, modules, and types. You can use reflection to
dynamically create an instance of a type, bind the type to an existing object,
or get the type from an existing object. You can then invoke the type’s methods
or access its fields and properties. Namespace: System.Reflection
What is “Common Type System” (CTS)?
CTS defines all of the basic types that can be used in the .NET Framework and
the operations performed on those type.
All this time we have been talking about language interoperability, and .NET
Class Framework. None of this is possible without all the language sharing the
same data types. What this means is that an int should mean the same in VB,
VC++, C# and all other .NET compliant languages. This is achieved through
introduction of Common Type System (CTS).
What is “Common Language Specification” (CLS)?
CLS is the collection of the rules and constraints that every language (that
seeks to achieve .NET compatibility) must follow. It is a subsection of CTS and
it specifies how it shares and extends one another libraries.
What is “Common Language Runtime” (CLR)?
CLR is .NET equivalent of Java Virtual Machine (JVM). It is the runtime that
converts a MSIL code into the host machine language code, which is then
executed appropriately. The CLR is the execution engine for .NET Framework
applications. It provides a number of services, including:
- Code management (loading and execution)
- Application memory isolation
- Verification of type safety
- Conversion of IL to native code.
- Access to metadata (enhanced type information)
- Managing memory for managed objects
- Enforcement of code access security
- Exception handling, including cross-language exceptions
- Interoperation between managed code, COM objects, and pre-existing DLL’s
(unmanaged code and data)
- Automation of object layout
- Support for developer services (profiling, debugging, and so on).
What are Attributes?
Attributes are declarative tags in code that insert additional metadata into an
assembly. There exist two types of attributes in the .NET Framework: Predefined
attributes such as AssemblyVersion, which already exist and are accessed
through the Runtime Classes; and custom attributes, which you write yourself by
extending the System.Attribute class.
What are the Types of Assemblies?
Assemblies are of two types:
1. Private Assemblies
2. Shared Assemblies
Private Assemblies: The assembly is intended only for one application. The
files of that assembly must be placed in the same folder as the application or
in a sub folder. No other application will be able to make a call to this
assembly. The advantage of having a private assembly is that, it makes naming
the assembly very easy, since the developer need not worry about name clashes
with other assemblies. As long as the assembly has a unique name within the
concerned application, there won’t be any problems.
Shared Assemblies: If the assembly is to be made into a Shared Assembly, then
the naming conventions are very strict since it has to be unique across the
entire system. The naming conventions should also take care of newer versions
of the component being shipped. These are accomplished by giving the assembly a
Shared Name. Then the assembly is placed in the global assembly cache, which is
a folder in the file system reserved for shared assemblies.
Using COM Component in .Net ?
As most of you know that .Net does not encourage the development of COM
components and provides a different solution to making reusable components
through Assemblies. But, there are a lot of COM components present which our
.Net application might need to use. Fortunately, .Net provides an extremely
simple approach to achieve this. This is achieved by using ‘Wrapper Classes’
and ‘Proxy Components’. .Net wraps the COM component into .Net assembly
technically called ‘Runtime Callable Wrapper’ or RCW. Then u can call and use
your COM component just as a .Net (or C#, if u are using C#) Assembly.
What is an assembly?
An assembly is the primary building block of a .NET Framework application. It
is a collection of functionality that is built, versioned, and deployed as a
single implementation unit (as one or more files). All managed types and
resources are marked either as accessible only within their implementation
unit, or as accessible by code outside that unit. .NET Assembly contains all
the metadata about the modules, types, and other elements it contains in the
form of a manifest. The CLR loves assemblies because differing programming
languages are just perfect for creating certain kinds of applications. For
example, COBOL stands for Common Business-Oriented Language because it’s
tailor-made for creating business apps. However, it’s not much good for
creating drafting programs. Regardless of what language you used to create your
modules, they can all work together within one Portable Executable Assembly.
There’s a hierarchy to the structure of .NET code. That hierarchy is Assembly –
> Module -> Type -> Method.” Assemblies can be static or dynamic. Static
assemblies can include .NET Framework types (interfaces and classes), as well
as resources for the assembly (bitmaps, JPEG files, resource files, and so on).
Static assemblies are stored on disk in portable executable (PE) files. You can
also use the .NET Framework to create dynamic assemblies, which are run
directly from memory and are not saved to disk before execution. You can save
dynamic assemblies to disk after they have executed.
What is a Web Service?
A web service is a software component that exposes itself through the open
communication channels of the Internet. Applications running on remote
machines, on potentially different platforms, can access these components in a
language and platform-independent manner. A Web Service is a group of
functions, packaged together for use in a common framework throughout a
network.
webFarm Vs webGardens
A web farm is a multi-server scenario. So we may have a server in each state of
US. If the load on one server is in excess then the other servers step in to
bear the brunt.
How they bear it is based on various models.
1. RoundRobin. (All servers share load equally)
2. NLB (economical)
3. HLB (expensive but can scale up to 8192 servers)
4. Hybrid (of 2 and 3).
5. CLB (Component load balancer).
A web garden is a multi-processor setup. i.e., a single server (not like the
multi server above).
How to implement webfarms in .Net:
Go to web.config and Here for mode = you have 4 options.
a) Say mode=inproc (non web farm but fast when you have very few customers).
b) Say mode=StateServer (for webfarm)
c) Say mode=SqlServer (for webfarm)
Whether to use option b or c depends on situation. StateServer is faster but
SqlServer is more reliable and used for mission critical applications.
How to use webgardens in .Net:
Go to web.config and Change the false to true. You have one more attribute that
is related to webgarden in the same tag called cpuMask.
What is the difference between a namespace and assembly name?
A namespace is a logical naming scheme for types in which a simple type name,
such as MyType, is preceded with a dot-separated hierarchical name. Such a
naming scheme is completely under control of the developer. For example, types
MyCompany.FileAccess.A and MyCompany.FileAccess.B might be logically expected
to have functionally related to file access. The .NET Framework uses a
hierarchical naming scheme for grouping types into logical categories of
related functionality, such as the ASP.NET application framework, or remoting
functionality. Design tools can make use of namespaces to make it easier for
developers to browse and reference types in their code. The concept of a
namespace is not related to that of an assembly. A single assembly may contain
types whose hierarchical names have different namespace roots, and a logical
namespace root may span multiple assemblies. In the .NET Framework, a namespace
is a logical design-time naming convenience, whereas an assembly establishes
the name scope for types at run time.
What’s a Windows process?
It’s an application that’s running and had been allocated memory.
What’s typical about a Windows process in regards to memory allocation?
Each process is allocated its own block of available RAM space, no process can
access another process’ code or data. If the process crashes, it dies alone
without taking the entire OS or a bunch of other applications down.
Explain what relationship is between a Process, Application Domain, and
Application?
Each process is allocated its own block of available RAM space, no process can
access another process’ code or data. If the process crashes, it dies alone
without taking the entire OS or a bunch of other applications down.
A process is an instance of a running application. An application is an
executable on the hard drive or network. There can be numerous processes
launched of the same application (5 copies of Word running), but 1 process can
run just 1 application.
What are possible implementations of distributed applications in .NET?
.NET Remoting and ASP.NET Web Services. If we talk about the Framework Class
Library, noteworthy classes are in System.Runtime.Remoting and
System.Web.Services.
What are the consideration in deciding to use .NET Remoting or ASP.NET Web
Services?
Remoting is a more efficient communication exchange when you can control both
ends of the application involved in the communication process. Web Services
provide an open-protocol-based exchange of information. Web Services are best
when you need to communicate with an external organization or another
(non-.NET) technology.
What’s a proxy of the server object in .NET Remoting?
It’s a fake copy of the server object that resides on the client side and
behaves as if it was the server. It handles the communication between real
server object and the client object. This process is also known as marshaling.
What are remotable objects in .NET Remoting?
Remotable objects are the objects that can be marshaled across the application
domains. You can marshal by value, where a deep copy of the object is created
and then passed to the receiver. You can also marshal by reference, where just
a reference to an existing object is passed.
What are channels in .NET Remoting?
Channels represent the objects that transfer the other serialized objects from
one application domain to another and from one computer to another, as well as
one process to another on the same box. A channel must exist before an object
can be transferred.
What security measures exist for .NET Remoting in System.Runtime.Remoting?
None. Security should be taken care of at the application level. Cryptography
and other security techniques can be applied at application or server level.
What is a formatter?
A formatter is an object that is responsible for encoding and serializing data
into messages on one end, and deserializing and decoding messages into data on
the other end.
Choosing between HTTP and TCP for protocols and Binary and SOAP for formatters,
what are the trade-offs?
Binary over TCP is the most effiecient, SOAP over HTTP is the most
interoperable.
What’s SingleCall activation mode used for?
If the server object is instantiated for responding to just one single request,
the request should be made in SingleCall mode.
What’s Singleton activation mode?
A single object is instantiated regardless of the number of clients accessing
it. Lifetime of this object is determined by lifetime lease.
How do you define the lease of the object?
By implementing ILease interface when writing the class code.
Can you configure a .NET Remoting object via XML file?
Yes, via machine.config and application level .config file (or web.config in
ASP.NET). Application-level XML settings take precedence over machine.config.
How can you automatically generate interface for the remotable object in .NET
with Microsoft tools?
Use the Soapsuds tool.
What is Delegation?
A delegate acts like a strongly type function pointer. Delegates can invoke the
methods that they reference without making explicit calls to those methods.
Delegate is an entity that is entrusted with the task of representation, assign
or passing on information. In code sense, it means a Delegate is entrusted with
a Method to report information back to it when a certain task (which the Method
expects) is accomplished outside the Method’s class.
How do you trigger the Paint event in System.Drawing?
Invalidate the current form, the OS will take care of repainting. The Update
method forces the repaint.
With these events, why wouldn’t Microsoft combine Invalidate and Paint, so that
you wouldn’t have to tell it to repaint, and then to force it to repaint?
Painting is the slowest thing the OS does, so usually telling it to repaint,
but not forcing it allows for the process to take place in the background.
How can you assign an RGB color to a System.Drawing.Color object?
Call the static method FromArgb of this class and pass it the RGB values.
What class does Icon derive from? Isn’t it just a Bitmap with a wrapper name
around it?
No, Icon lives in System.Drawing namespace. It’s not a Bitmap by default, and
is treated separately by .NET. However, you can use ToBitmap method to get a
valid Bitmap object from a valid Icon object.
Before in my VB app I would just load the icons from DLL. How can I load the
icons provided by .NET dynamically?
By using System.Drawing.SystemIcons class, for example
System.Drawing.SystemIcons.Warning produces an Icon with a warning sign in it.
When displaying fonts, what’s the difference between pixels, points and ems?
A pixel is the lowest-resolution dot the computer monitor supports. Its size
depends on user’s settings and monitor size. A point is always 1/72 of an inch.
An em is the number of pixels that it takes to display the letter M.
What is .NET?
.NET is essentially a framework for software development. It is similar in
nature to any other software development framework (J2EE etc) in that it
provides a set of runtime containers/capabilities, and a rich set of pre-built
functionality in the form of class libraries and APIs
The .NET Framework is an environment for building, deploying, and running Web
Services and other applications. It consists of three main parts: the Common
Language Runtime, the Framework classes, and ASP.NET.
How many languages .NET is supporting now?
When .NET was introduced it came with several languages. VB.NET, C#, COBOL and
Perl, etc. The site DotNetLanguages.Net says 44 languages are supported.
How is .NET able to support multiple languages?
A language should comply with the Common Language Runtime standard to become a
.NET language. In .NET, code is compiled to Microsoft Intermediate Language
(MSIL for short). This is called as Managed Code. This Managed code is run in
.NET environment. So after compilation to this IL the language is not a
barrier. A code can call or use a function written in another language.
How ASP .NET different from ASP?
Scripting is separated from the HTML, Code is compiled as a DLL, these DLLs can
be executed on the server.
What is smart navigation?
The cursor position is maintained when the page gets refreshed due to the
server side validation and the page gets refreshed.
What is view state?
The web is stateless. But in ASP.NET, the state of a page is maintained in the
in the page itself automatically. How? The values are encrypted and saved in
hidden controls. this is done automatically by the ASP.NET. This can be
switched off / on for a single control
How do you validate the controls in an ASP .NET page?
Using special validation controls that are meant for this. We have Range
Validator, Email Validator.
Can the validation be done in the server side? Or this can be done only in the
Client side?
Client side is done by default. Server side validation is also possible. We can
switch off the client side and server side can be done.
How to manage pagination in a page?
Using pagination option in DataGrid control. We have to set the number of
records for a page, then it takes care of pagination by itself.
What is ADO .NET and what is difference between ADO and ADO.NET?
ADO.NET is stateless mechanism. I can treat the ADO.Net as a separate in-memory
database where in I can use relationships between the tables and select insert
and updates to the database. I can update the actual database as a batch.
Creating a Key Pair?
You can create a key pair using the Strong Name tool (Sn.exe). Key pair files
usually have an .snk extension. To create a key pair At the command prompt,
type the following command:
sn k
In this command, file name is the name of the output file containing the key
pair. The following example creates a key pair called sgKey.snk.
sn -k sgKey.snk
What is the difference between “using System.Data;” and directly adding the
reference from “Add References Dialog Box”?
When u compile a program using command line, u add the references using /r
switch. When you compile a program using Visual Studio, it adds those
references to our assembly, which are added using “Add Reference” dialog box.
While “using” statement facilitates us to use classes without using their fully
qualified names.
For example: if u have added a reference to “System.Data.SqlClient” using “Add
Reference” dialog box then u can use SqlConnection class like this:
System.Data.SqlClient.SqlConnection
But if u add a “using System.Data.SqlClient” statement at the start of ur code
then u can directly use SqlConnection class.
On the other hand if u add a reference using “using System.Data.SqlClient”
statement, but don’t add it using “Add Reference” dialog box, Visual Studio
will give error message while we compile the program.
What is GAC?
The global assembly cache stores assemblies specifically designated to be
shared by several applications on the computer. You should share assemblies by
installing them into the global assembly cache only when you need to.
Assemblies deployed in the global assembly cache must have a strong name. When
an assembly is added to the global assembly cache, integrity checks are
performed on all files that make up the assembly. The cache performs these
integrity checks to ensure that an assembly has not been tampered with, for
example, when a file has changed but the manifest does not reflect the change.
Use a developer tool called the Global Assembly Cache tool (Gacutil.exe),
provided by the .NET Framework SDK or Use Windows Explorer to drag assemblies
into the cache. To install a strong-named assembly into the global assembly
cache At the command prompt, type the following command:
gacutil I
In this command, assembly name is the name of the assembly to install in the
global assembly cache.
What is a Metadata?
Metadata is information about a PE. In COM, metadata is communicated through
non-standardized type libraries.
In .NET, this data is contained in the header portion of a COFF-compliant PE
and follows certain guidelines;
it contains information such as the assembly’s name, version, language (spoken,
not computera.k.a., culture), what external types are referenced, what internal
types are exposed, methods, properties, classes, and much more.
The CLR uses metadata for a number of specific purposes. Security is managed
through a public key in the PE’s header.
Information about classes, modules, and so forth allows the CLR to know in
advance what structures are necessary. The class loader component of the CLR
uses metadata to locate specific classes within assemblies, either locally or
across networks.
Just-in-time (JIT) compilers use the metadata to turn IL into executable code.
Other programs take advantage of metadata as well.
A common example is placing a Microsoft Word document on a Windows 2000
desktop. If the document file has completed comments, author, title, or other
Properties metadata, the text is displayed as a tool tip when a user hovers the
mouse over the document on the desktop. You can use the Ildasm.exe utility to
view the metadata in a PE. Literally, this tool is an IL disassembler.
What is managed code and managed data?
Managed code is code that is written to target the services of the Common
Language Runtime.
In order to target these services, the code must provide a minimum level of
information (metadata) to the runtime.
All C#, Visual Basic .NET, and JScript .NET code is managed by default.
Visual Studio .NET C++ code is not managed by default, but the compiler can
produce managed code by specifying a command-line switch (/CLR).
Closely related to managed code is managed data–data that is allocated and de-
allocated by the Common Language Runtime’s garbage collector. C#, Visual Basic,
and JScript .NET data is managed by default.
C# data can, however, be marked as unmanaged through the use of special
keywords.
Visual Studio .NET C++ data is unmanaged by default (even when using the /CLR
switch), but when using Managed Extensions for C++, a class can be marked as
managed using the __gc keyword. As the name suggests, this means that the
memory for instances of the class is managed by the garbage collector.
In addition, the class becomes a full participating member of the .NET
Framework community, with the benefits and restrictions that it brings. An
example of a benefit is proper interoperability with classes written in other
languages (for example, a managed C++ class can inherit from a Visual Basic
class).
An example of a restriction is that a managed class can only inherit from one
base class.
What is .NET / .NET Framework?
It is a Framework in which Windows applications may be developed and run. The
Microsoft .NET Framework is a platform for building, deploying, and running Web
Services and applications. It provides a highly productive, standards-based,
multi-language environment for integrating existing investments with
next-generation applications and services as well as the agility to solve the
challenges of deployment and operation of Internet-scale applications. The .NET
Framework consists of three main parts: the common language runtime, a
hierarchical set of unified class libraries, and a componentized version of
Active Server Pages called ASP.NET. The .NET Framework provides a new
programming model and rich set of classes designed to simplify application
development for Windows, the Web, and mobile devices. It provides full support
for XML Web services, contains robust security features, and delivers new
levels of programming power. The .NET Framework is used by all Microsoft
languages including Visual C#, Visual J#, and Visual C++.
What is Reflection?
It extends the benefits of metadata by allowing developers to inspect and use
it at runtime. For example, dynamically determine all the classes contained in
a given assembly and invoke their methods. Reflection provides objects that
encapsulate assemblies, modules, and types. You can use reflection to
dynamically create an instance of a type, bind the type to an existing object,
or get the type from an existing object. You can then invoke the type’s methods
or access its fields and properties. Namespace: System.Reflection
What is “Common Type System” (CTS)?
CTS defines all of the basic types that can be used in the .NET Framework and
the operations performed on those type.
All this time we have been talking about language interoperability, and .NET
Class Framework. None of this is possible without all the language sharing the
same data types. What this means is that an int should mean the same in VB,
VC++, C# and all other .NET compliant languages. This is achieved through
introduction of Common Type System (CTS).
What is “Common Language Specification” (CLS)?
CLS is the collection of the rules and constraints that every language (that
seeks to achieve .NET compatibility) must follow. It is a subsection of CTS and
it specifies how it shares and extends one another libraries.
What is “Common Language Runtime” (CLR)?
CLR is .NET equivalent of Java Virtual Machine (JVM). It is the runtime that
converts a MSIL code into the host machine language code, which is then
executed appropriately. The CLR is the execution engine for .NET Framework
applications. It provides a number of services, including:
- Code management (loading and execution)
- Application memory isolation
- Verification of type safety
- Conversion of IL to native code.
- Access to metadata (enhanced type information)
- Managing memory for managed objects
- Enforcement of code access security
- Exception handling, including cross-language exceptions
- Interoperation between managed code, COM objects, and pre-existing DLL’s
(unmanaged code and data)
- Automation of object layout
- Support for developer services (profiling, debugging, and so on).
What are Attributes?
Attributes are declarative tags in code that insert additional metadata into an
assembly. There exist two types of attributes in the .NET Framework: Predefined
attributes such as AssemblyVersion, which already exist and are accessed
through the Runtime Classes; and custom attributes, which you write yourself by
extending the System.Attribute class.
What are the Types of Assemblies?
Assemblies are of two types:
1. Private Assemblies
2. Shared Assemblies
Private Assemblies: The assembly is intended only for one application. The
files of that assembly must be placed in the same folder as the application or
in a sub folder. No other application will be able to make a call to this
assembly. The advantage of having a private assembly is that, it makes naming
the assembly very easy, since the developer need not worry about name clashes
with other assemblies. As long as the assembly has a unique name within the
concerned application, there won’t be any problems.
Shared Assemblies: If the assembly is to be made into a Shared Assembly, then
the naming conventions are very strict since it has to be unique across the
entire system. The naming conventions should also take care of newer versions
of the component being shipped. These are accomplished by giving the assembly a
Shared Name. Then the assembly is placed in the global assembly cache, which is
a folder in the file system reserved for shared assemblies.
Using COM Component in .Net ?
As most of you know that .Net does not encourage the development of COM
components and provides a different solution to making reusable components
through Assemblies. But, there are a lot of COM components present which our
.Net application might need to use. Fortunately, .Net provides an extremely
simple approach to achieve this. This is achieved by using ‘Wrapper Classes’
and ‘Proxy Components’. .Net wraps the COM component into .Net assembly
technically called ‘Runtime Callable Wrapper’ or RCW. Then u can call and use
your COM component just as a .Net (or C#, if u are using C#) Assembly.
What is an assembly?
An assembly is the primary building block of a .NET Framework application. It
is a collection of functionality that is built, versioned, and deployed as a
single implementation unit (as one or more files). All managed types and
resources are marked either as accessible only within their implementation
unit, or as accessible by code outside that unit. .NET Assembly contains all
the metadata about the modules, types, and other elements it contains in the
form of a manifest. The CLR loves assemblies because differing programming
languages are just perfect for creating certain kinds of applications. For
example, COBOL stands for Common Business-Oriented Language because it’s
tailor-made for creating business apps. However, it’s not much good for
creating drafting programs. Regardless of what language you used to create your
modules, they can all work together within one Portable Executable Assembly.
There’s a hierarchy to the structure of .NET code. That hierarchy is Assembly –
> Module -> Type -> Method.” Assemblies can be static or dynamic. Static
assemblies can include .NET Framework types (interfaces and classes), as well
as resources for the assembly (bitmaps, JPEG files, resource files, and so on).
Static assemblies are stored on disk in portable executable (PE) files. You can
also use the .NET Framework to create dynamic assemblies, which are run
directly from memory and are not saved to disk before execution. You can save
dynamic assemblies to disk after they have executed.
What is a Web Service?
A web service is a software component that exposes itself through the open
communication channels of the Internet. Applications running on remote
machines, on potentially different platforms, can access these components in a
language and platform-independent manner. A Web Service is a group of
functions, packaged together for use in a common framework throughout a
network.
webFarm Vs webGardens
A web farm is a multi-server scenario. So we may have a server in each state of
US. If the load on one server is in excess then the other servers step in to
bear the brunt.
How they bear it is based on various models.
1. RoundRobin. (All servers share load equally)
2. NLB (economical)
3. HLB (expensive but can scale up to 8192 servers)
4. Hybrid (of 2 and 3).
5. CLB (Component load balancer).
A web garden is a multi-processor setup. i.e., a single server (not like the
multi server above).
How to implement webfarms in .Net:
Go to web.config and Here for mode = you have 4 options.
a) Say mode=inproc (non web farm but fast when you have very few customers).
b) Say mode=StateServer (for webfarm)
c) Say mode=SqlServer (for webfarm)
Whether to use option b or c depends on situation. StateServer is faster but
SqlServer is more reliable and used for mission critical applications.
How to use webgardens in .Net:
Go to web.config and Change the false to true. You have one more attribute that
is related to webgarden in the same tag called cpuMask.
What is the difference between a namespace and assembly name?
A namespace is a logical naming scheme for types in which a simple type name,
such as MyType, is preceded with a dot-separated hierarchical name. Such a
naming scheme is completely under control of the developer. For example, types
MyCompany.FileAccess.A and MyCompany.FileAccess.B might be logically expected
to have functionally related to file access. The .NET Framework uses a
hierarchical naming scheme for grouping types into logical categories of
related functionality, such as the ASP.NET application framework, or remoting
functionality. Design tools can make use of namespaces to make it easier for
developers to browse and reference types in their code. The concept of a
namespace is not related to that of an assembly. A single assembly may contain
types whose hierarchical names have different namespace roots, and a logical
namespace root may span multiple assemblies. In the .NET Framework, a namespace
is a logical design-time naming convenience, whereas an assembly establishes
the name scope for types at run time.
What’s a Windows process?
It’s an application that’s running and had been allocated memory.
What’s typical about a Windows process in regards to memory allocation?
Each process is allocated its own block of available RAM space, no process can
access another process’ code or data. If the process crashes, it dies alone
without taking the entire OS or a bunch of other applications down.
Explain what relationship is between a Process, Application Domain, and
Application?
Each process is allocated its own block of available RAM space, no process can
access another process’ code or data. If the process crashes, it dies alone
without taking the entire OS or a bunch of other applications down.
A process is an instance of a running application. An application is an
executable on the hard drive or network. There can be numerous processes
launched of the same application (5 copies of Word running), but 1 process can
run just 1 application.
What are possible implementations of distributed applications in .NET?
.NET Remoting and ASP.NET Web Services. If we talk about the Framework Class
Library, noteworthy classes are in System.Runtime.Remoting and
System.Web.Services.
What are the consideration in deciding to use .NET Remoting or ASP.NET Web
Services?
Remoting is a more efficient communication exchange when you can control both
ends of the application involved in the communication process. Web Services
provide an open-protocol-based exchange of information. Web Services are best
when you need to communicate with an external organization or another
(non-.NET) technology.
What’s a proxy of the server object in .NET Remoting?
It’s a fake copy of the server object that resides on the client side and
behaves as if it was the server. It handles the communication between real
server object and the client object. This process is also known as marshaling.
What are remotable objects in .NET Remoting?
Remotable objects are the objects that can be marshaled across the application
domains. You can marshal by value, where a deep copy of the object is created
and then passed to the receiver. You can also marshal by reference, where just
a reference to an existing object is passed.
What are channels in .NET Remoting?
Channels represent the objects that transfer the other serialized objects from
one application domain to another and from one computer to another, as well as
one process to another on the same box. A channel must exist before an object
can be transferred.
What security measures exist for .NET Remoting in System.Runtime.Remoting?
None. Security should be taken care of at the application level. Cryptography
and other security techniques can be applied at application or server level.
What is a formatter?
A formatter is an object that is responsible for encoding and serializing data
into messages on one end, and deserializing and decoding messages into data on
the other end.
Choosing between HTTP and TCP for protocols and Binary and SOAP for formatters,
what are the trade-offs?
Binary over TCP is the most effiecient, SOAP over HTTP is the most
interoperable.
What’s SingleCall activation mode used for?
If the server object is instantiated for responding to just one single request,
the request should be made in SingleCall mode.
What’s Singleton activation mode?
A single object is instantiated regardless of the number of clients accessing
it. Lifetime of this object is determined by lifetime lease.
How do you define the lease of the object?
By implementing ILease interface when writing the class code.
Can you configure a .NET Remoting object via XML file?
Yes, via machine.config and application level .config file (or web.config in
ASP.NET). Application-level XML settings take precedence over machine.config.
How can you automatically generate interface for the remotable object in .NET
with Microsoft tools?
Use the Soapsuds tool.
What is Delegation?
A delegate acts like a strongly type function pointer. Delegates can invoke the
methods that they reference without making explicit calls to those methods.
Delegate is an entity that is entrusted with the task of representation, assign
or passing on information. In code sense, it means a Delegate is entrusted with
a Method to report information back to it when a certain task (which the Method
expects) is accomplished outside the Method’s class.
How do you trigger the Paint event in System.Drawing?
Invalidate the current form, the OS will take care of repainting. The Update
method forces the repaint.
With these events, why wouldn’t Microsoft combine Invalidate and Paint, so that
you wouldn’t have to tell it to repaint, and then to force it to repaint?
Painting is the slowest thing the OS does, so usually telling it to repaint,
but not forcing it allows for the process to take place in the background.
How can you assign an RGB color to a System.Drawing.Color object?
Call the static method FromArgb of this class and pass it the RGB values.
What class does Icon derive from? Isn’t it just a Bitmap with a wrapper name
around it?
No, Icon lives in System.Drawing namespace. It’s not a Bitmap by default, and
is treated separately by .NET. However, you can use ToBitmap method to get a
valid Bitmap object from a valid Icon object.
Before in my VB app I would just load the icons from DLL. How can I load the
icons provided by .NET dynamically?
By using System.Drawing.SystemIcons class, for example
System.Drawing.SystemIcons.Warning produces an Icon with a warning sign in it.
When displaying fonts, what’s the difference between pixels, points and ems?
A pixel is the lowest-resolution dot the computer monitor supports. Its size
depends on user’s settings and monitor size. A point is always 1/72 of an inch.
An em is the number of pixels that it takes to display the letter M.