Dot Net FAQ
Dot Net FAQ
1) What is Assembly?
The assembly is a collection of files that together make up the assembly. It contains
some special metadata known as assembly manifest. The assembly manifest defines
what the versioning requirements of the assembly are, who authorized the assembly,
what the security permissions the assembly requires to run, and what files from part
of the assembly. An assembly is created by default whenever you build a DLL. The
only requirement is that these files need to all reside in the same directory of the
disk. When they are placed into an assembly, the Common Language Runtime treats
all these as a single unit. The assembly can be thought of as a logical DLL.
Benefits of Metadata
Metadata is the key to a simpler programming model, eliminating the need for Interface
Definition Language (IDL) files, header files, or any external method of component reference.
Metadata allows .NET languages to describe themselves automatically in a language-neutral
manner, unseen by both the developer and the user. Additionally, metadata is extensible
through the use of attributes. Metadata provides the following major benefits:
• Self-describing files.
Common language runtime modules and assemblies are self-describing. A module's
metadata contains everything needed to interact with another module. Metadata
automatically provides the functionality of IDL in COM, allowing you to use one file for
both definition and implementation. Runtime modules and assemblies do not even
require registration with the operating system. As a result, the descriptions used by
the runtime always reflect the actual code in your compiled file, which increases
application reliability.
• Language interoperability and easier component-based design.
Metadata provides all the information required about compiled code for you to inherit
a class from a PE file written in a different language. You can create an instance of
any class written in any managed language (any language that targets the common
language runtime) without worrying about explicit marshaling or using custom
interoperability code.
• Attributes
The .NET Framework allows you to declare specific kinds of metadata, called
attributes, in your compiled file. Attributes can be found throughout the .NET
Framework and are used to control in more detail how your program behaves at run
time. Additionally, you can emit your own custom metadata into .NET Framework files
through user-defined custom attributes
13) What is global assembly cache
A machine-wide code cache that stores assemblies specifically installed to be shared
by many applications on the computer. Applications deployed in the global assembly
cache must have a strong name
14) What is key file? How will u generate key file and how will link to the
assembly?
Specifies the path to the file that contains the strong name key for the generated
assemblies.
Public keyFile As String
Remarks
By default, this field is set to a null reference (Nothing in Visual Basic).
Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition,
Windows 2000, Windows XP Home Edition, Windows XP Professional,
Windows .NET Server family
15) Static and dynamic assembly
Static: Loading an assembly in the design time is called static assembly
Dynamic: Loading an assembly in the run time is called dynamic assembly
Method is System.Reflection.Assembly.loadfrom ()
Get Types () and get Methods ()
16) What is side-by-side execution and types?
The ability to run multiple versions of the same assembly simultaneously. This can be
on the same computer or in the same process or application domain. Allowing
assemblies to run side-by-side is essential to support robust versioning in the
common language runtime.
There are two types of side-by-side execution:
• Running on the same computer.
In this type of side-by-side execution, multiple versions of the same application run
on the same computer at the same time without interfering with each other. An
application that supports side-by-side execution on the same computer demands
careful coding. For example, consider an application that uses a file at a specific
location for a cache. The application must either handle multiple versions of the
application accessing the file at the same time or the application must remove the
dependency on the specific location and allow each version to have its own cache.
• Running in the same process.
To successfully run side by side in the same process, multiple versions cannot have
any strict dependencies on process-wide resources. Side-by-side execution in the
same process means that single applications with multiple dependencies can run
multiple versions of the same component, and Web servers and other hosts can run
applications with possibly conflicting dependencies in the same process.
17) How the run time locates the assembly
The runtime uses the following steps to resolve an assembly reference:
1. Determines the correct assembly version by examining applicable
configuration files, including the application configuration file, publisher policy
file, and machine configuration file. If the configuration file is located on a remote
machine, the runtime must locate and download the application configuration file
first.
2. Checks whether the assembly name has been bound to before and, if so, use
the previously loaded assembly.
3. Checks the global assembly cache. If the assembly is found there, the runtime
uses this assembly.
4. Probes for the assembly using the following steps:
a. If configuration and publisher policy do not affect the original
reference and if the bind request was created using the Assembly.Load
From method, the runtime checks for location hints.
b. If a codebase is found in the configuration files, the runtime checks
only this location. If this probe fails, the runtime determines that the
binding request failed and no other probing occurs.
c. Probes for the assembly using the heuristics described in the probing
section. If the assembly is not found after probing, the runtime requests
the Windows Installer to provide the assembly. This acts as an install-on-
demand feature.
Note There is no version checking for assemblies without strong
names, nor does the runtime check in the global assembly cache for
assemblies without strong names.
18) What is application domain?
Application domains provide a secure and versatile unit of processing that the
common language runtime can use to provide isolation between applications. You can
run several application domains in a single process with the same level of isolation
that would exist in separate processes, but without incurring the additional overhead
of making cross-process calls or switching between processes. The ability to run
multiple applications within a single process dramatically increases server scalability.
19) What is difference between constants, read only and, static
Constants: The value can’t be changed
Read-only: The value
Static: Value can be initialized once.
20) What is difference between shared and public?
Both are same
21) What is use of context Util class?
Using this Class, the transaction can be controlled programmatically by using method
of SetAbort and SetComplete
22) What is the new three features of COM+ services, which are not there in
COM (MTS)
1) Load balancing
2) Queue
23) What is method for transaction?
SetAbort and SetComplete
24) How will you call a .net assembly from VB and vice versa?
CCW(COM Callable wrapper) : Calling .net component from Other applications(VB)
using tlbExp.exe
RCW(Remote callable wrapper)Calling VB.Dll from .Net Application
Using tlpImp.exe
25) What is namespace used for loading assemblies at run time and name the
methods?
system. Reflection
26) What are the types of authentication in .net?
We have two types of authentication: 1. SQL authentication and
2. Windows authentication
This has to be declared in web.config file. ( I think they are form based and windows
based)
27) Which is the namespace used to write error message in event Log File?
System.Diagonastics
28) What is role-based security?
Roles are often used in financial or business applications to enforce policy. For
example, an application might impose limits on the size of the transaction being
processed, depending on whether the user making the request is a member of a
specified role. Clerks might have authorization to process transactions that are less
than a specified threshold, supervisors might have a higher limit, and vice-presidents
might have a still higher limit (or no limit at all). Role-based security can also be used
when an application requires multiple approvals to complete an action. Such a case
might be a purchasing system in which any employee can generate a purchase
request, but only a purchasing agent can convert that request into a purchase order
that can be sent to a supplier.
.NET Framework role-based security supports authorization by making information
about the principal, which is constructed from an associated identity, available to the
current thread. The identity (and the principal it helps to define) can be either based
on a Windows account or be a custom identity unrelated to a Windows account. .NET
Framework applications can make authorization decisions based on the principal's
identity or role membership, or both. A role is a named set of principals that have the
same privileges with respect to security (such as a teller or a manager). A principal
can be a member of one or more roles. Therefore, applications can use role
membership to determine whether a principal is authorized to perform a requested
action.
To provide ease of use and consistency with code access security, .NET Framework
role-based security provides PrincipalPermission objects that enable the common
language runtime to perform authorization in a way that is similar to code access
security checks. The PrincipalPermission class represents the identity or role that
the principal must match and is compatible with both declarative and imperative
security checks. You can also access a principal's identity information directly and
perform role and identity checks in your code when needed.
The .NET Framework provides role-based security support that is flexible and
extensible enough to meet the needs of a wide spectrum of applications. You can
choose to interoperate with existing authentication infrastructures, such as COM+ 1.0
Services, or to create a custom authentication system. Role-based security is
particularly well-suited for use in ASP.NET Web applications, which are processed
primarily on the server. However, .NET Framework role-based security can be used on
either the client or the server.
29) What is the difference between ASP and ASP.net
ASP ASP.net
Request(item) this method will return an array of In ASP .NET Request(item) it returns a
strings NameValueCollection
Request.QueryString(item) In ASP, this method . In ASP .NET Request.QueryString(item)
will return an array of strings. a NameValueCollection
<%
Call RenderMe()
%>
In ASP, the Option Explicit keywords were available In Visual Basic .NET, this has changed. Opti
but were not enforced as the default Explicit is now the default so all variables n
be declared
On Error Resume Next and On Error Goto error Although the familiar On Error Resume Ne
handling techniques are in Visual Basic On Error Goto error handling techniques a
allowed in Visual Basic .NET, they are not th
way to do things anymore. Visual Basic now
blown structured exception handing using th
Catch, and Finally keywords. If possible, yo
move to this new model for error handling a
allows for a more powerful and consistent
mechanism in dealing with your application
It is Having both (Single thread apartment) The ASP .NET threading model is the Multipl
STA and MTA (Multi-thread apartment) Threaded Apartment (MTA). What this mean
component components that you are using that were cr
the Single Threaded Apartment (STA) will no
perform or function reliably without taking s
extra precautions in ASP .NET. This includes,
not limited to, all COM components that hav
created using Visual Basic 6.0 and earlier ve
You will be glad to hear that you can still use
STA components without having to change a
What you need to do is include the compatib
attribute aspcompat=true in a <%@Page>
the ASP .NET page. For example, <%@Page
aspcompat=true Language=VB%>. Usin
attribute will force your page to execute in S
mode, thus ensuring your component will co
function correctly. If you attempt to use an S
component without specifying this tag, the r
will throw an exception.
In ASP, all Web application configuration information ASP .NET introduces a whole new configurat
is stored in the system registry and the IIS Metabase model based on simple, human readable XM
Each ASP .NET application has its own Web.
file that lives in its main application director
Earlier versions of Visual You should not do this in Visual Basic.NET, because dates
Basic supported using the are not internally stored as doubles. The .NET framework
Double data type to store provides the ToOADate and FromOADate functions to
and manipulate dates convert between doubles and dates
In Visual Basic 6.0, many Visual Basic.NET does not support parameter less default
objects expose default properties, and consequently does not allow this
properties. programming shortcut
For example, Textbox has
a default property of Text,
so instead of writing:
MsgBox Form1.Text1.Text
Visual Basic 6.0 allowed you arrays in Visual Basic.NET must have a lower bound of zero,
to define arrays with lower and ReDim cannot be used unless the variable was
and upper bounds of any previously declared with Dim As Array
whole number. You could
also use ReDim to reassign
a variant as an array. To
enable interoperability with
other languages
DefBool, DefByte, DefInt, • Def<type>
DefLng, DefCur, DefSng, • Computed GoTo/GoSub
DefDbl, DefDec, DefDate, • GoSub/Return
DefStr, DefObj and DefVar • Option Base 0|1
were used in the
• VarPtr, ObjPtr, StrPtr
declarations section of a
module to define a range of • LSet
variables as a certain type This not supported by VB.net.
ADO.NET provides the basis for data If you use COM marshaling to transmit an ADO
interchange between components and record set, the target application must be
across tiers: programmed to use the record set data structure.
1. 1. Datasets can be passed This requires more difficult programming than simply
over the Internet and through reading XML data. Alternatively, you can persist the
firewalls as XML. ADO record set as XML and more easily share the
2. 2. You can view the same data with other applications and services
set of data as relational tables
within your application and as
an XML data structure in some
other application.
3. 3. The dataset provides
convenient two-way
transformation: from dataset
tables to an XML document,
and from an XML document
into dataset tables
Sequential, read-only server ADO by a forward only/read-only Record set object.
cursors are supported in ADO.NET by Sequential, read-only cursors provide the fastest
data readers (such as the means of reading data out of a database
SqlDataReader or OleDbDataReader
objects)
In ADO.NET, rows are represented as In ADO you scan sequentially through the rows of the
collections, so you can loop through a record set using the ADO Move Next method
table as you would through any
collection, or access particular rows
via ordinal or primary key index
In ADO.NET you communicate with the In ADO you communicate with the database by
database through a data adapter (an making calls to an OLE DB provider
OleDbDataAdapter or SqlDataAdapter
object), which makes calls to an OLE
DB provider or the APIs provided by
the underlying data source
To transmit data in ADO.NET, you use To transmit an ADO disconnected record set from
a dataset, which can transmit an XML one component to another, you use COM marshalling
stream.
ADO.NET transmits data in standard Whereas ADO requires that transmitting and
XML format so that COM marshaling or receiving components be COM objects
data-type conversions are not required
Late Binding:
By contrast, an object is late bound when it is assigned to a variable declared to be of
type Object. Objects of this type can hold references to any object, but lack many of
the advantages of early-bound objects. For example, the following code fragment
declares an object variable to hold an object returned by the CreateObject function:
' To use this example, you must have Microsoft Excel installed on your computer.
Option Strict Off ' Option Strict Off allows late binding.
...
Sub TestLateBinding()
Dim xlApp As Object
Dim xlBook As Object
Dim xlSheet As Object
xlApp = CreateObject("Excel.Application")
'Late bind an instance of an Excel workbook.
xlBook = xlApp.Workbooks.Add
'Late bind an instance of an Excel worksheet.
xlSheet = xlBook.Worksheets(1)
xlSheet.Activate()
xlSheet.Application.Visible = True ' Show the application.
' Place some text in the second row of the sheet.
xlSheet.Cells(2, 2) = "This is column B row 2"
End Sub
You should use early-bound objects whenever possible, because they allow the
compiler to make important optimizations that yield more efficient applications.
Early-bound objects are significantly faster than late-bound objects and make your
code easier to read and maintain by stating exactly what kind of objects are being
used. Another advantage to early binding is that it enables useful features such as
automatic code completion and Dynamic Help because the Visual Studio .NET
integrated development environment (IDE) can determine exactly what type of object
you are working with as you edit the code. Early binding reduces the number and
severity of run-time errors because it allows the compiler to report errors when a
program is compiled.
Note Late binding can only be used to access type members that are
declared as Public. Accessing members declared as Friend or Protected
Friend results in a runtime error.
Sub F()
System.Console.WriteLine("Test.F")
End Sub
Sub Main()
Dim d As New SimpleDelegate(F)
d()
End Sub
End Module
There is not much point in instantiating a delegate for a method and then
immediately calling via the delegate, as it would be simpler to call the method
directly. Delegates show their usefulness when their anonymity is used. The next
example shows a MultiCall method that repeatedly calls a SimpleDelegate instance:
Sub MultiCall(d As SimpleDelegate, count As Integer)
Dim i As Integer
For i = 0 To count - 1
d()
Next i
End Sub
It is unimportant to the MultiCall method what the target method for the
SimpleDelegate is, what accessibility this method has, or whether the method is
Shared or nonshared. All that matters is that the signature of the target method is
compatible with SimpleDelegate.
DelegateTypeDeclaration ::=
[ DelegateModifier+ ] Delegate MethodDeclaration
DelegateModifier ::= AccessModifier | Shadows
' The base class for event data, EventArgs, does not have
' any data and hence can be used as the event data type for events that do not
generate data.
// C#
public class userService1 : System.ServiceProcess.ServiceBase {
}
Add the following code to configure your service class:
' Visual Basic
Public Sub New()
Me.ServiceName = "MyService2"
Me.CanStop = True
Me.CanPauseAndContinue = True
Me.AutoLog = True
End Sub
// C#
public void userService1() {
this.ServiceName = "MyService2";
this.CanStop = true;
this.CanPauseAndContinue = true;
this.AutoLog = true;
}
Create a Sub Main for your class, and use it to define the service your
class will contain:
' Visual Basic
Public Sub Main()
System.ServiceProcess.ServiceBase.Run(New UserService1())
End Sub
// C#
public static void Main() {
System.ServiceProcess.ServiceBase.Run(new UserService1());
}
where userService1 is the name of the class.
Override the OnStart method, and define any processing you want to
occur when your service is started.
' Visual Basic
Protected Overrides Sub OnStart(ByVal args() As String)
' Your processing here
End Sub
// C#
protected override void OnStart(string[] args) {
// Your processing here
}
3. Override any other methods you want to define custom processing for, and
write code to determine the actions the service should take in each case.
4. Add the necessary installers for your service application..
5. Build your project by selecting Build Solution from the Build menu.
Note Do not press F5 to run your project — you cannot run a service
project in this way.
6. Create a setup project and the custom actions to install your service. Install
the service.
52) How many web.config files can we have for an application? [ ans : 1]
53) What are CCW and RCW?
When a COM client calls a .NET object, the common language runtime creates the
managed object and a COM callable wrapper (CCW) for the object. Unable to
reference a .NET object directly, COM clients use the CCW as a proxy for the
managed object.
The runtime creates exactly one CCW for a managed object, regardless of the
number of COM clients requesting its services. As the following illustration shows,
multiple COM clients can hold a reference to the CCW that exposes the INew
interface. The CCW, in turn, holds a single reference to the managed object that
implements the interface and is garbage collected. Both COM and .NET clients can
make requests on the same managed object simultaneously.
COM callable wrappers are invisible to other classes running within the .NET
Framework. Their primary purpose is to marshal calls between managed and
unmanaged code; however, CCWs also manage the object identity and object lifetime
of the managed objects they wrap.
Object Identity The runtime allocates memory for the .NET object from its garbage-
collected heap, which enables the runtime to move the object around in memory as
necessary. In contrast, the runtime allocates memory for the CCW from a non-
collected heap, making it possible for COM clients to reference the wrapper directly.
Object Lifetime Unlike the .NET client it wraps, the CCW is reference-counted in
traditional COM fashion. When the reference count on the CCW reaches zero, the
wrapper releases its reference on the managed object. A managed object with no
remaining references is collected during the next garbage-collection cycle.