Professional Documents
Culture Documents
Dot Net Framework Faq1
Dot Net Framework Faq1
Next >>
What is IL?
IL = Intermediate Language. Also known as MSIL (Microsoft Intermediate Language) or CIL
(Common Intermediate Language). All .NET source code (of any language) is compiled to IL. The
IL is then converted to machine code at the point where the software is installed, or at run-time by
a Just-In-Time (JIT) compiler.
exception handling and security. For these services to work, the code must provide a minimum
level of information to the runtime.
Such code is called managed code. All C# and Visual Basic.NET code is managed by default.
VS7 C++ code is not managed by default, but the compiler can produce managed code by
specifying a command-line switch (/com+).
Managed data: This is data that is allocated and de-allocated by the .NET runtime's garbage
collector. C# and VB.NET data is always managed. VS7 C++ data is unmanaged by default, even
when using the /com+ switch, but it can be marked as managed using the __gc
keyword.Managed classes: This is usually referred to in the context of Managed Extensions (ME)
for C++. When using ME C++, a class can be marked with the __gc keyword. As the name
suggests, this means that the memory for instances of the class is managed by the garbage
collector, but it also means more than that. The class becomes a fully paid-up member of the
.NET community with the benefits and restrictions that brings. An example of a benefit is proper
interop with classes written in other languages - for example, a managed C++ class can inherit
from a VB class. An example of a restriction is that a managed class can only inherit from one
base class.
What is reflection?
All .NET compilers produce metadata about the types defined in the modules they produce. This
metadata is packaged along with the module (modules in turn are packaged together in
assemblies), and can be accessed by a mechanism called reflection. The System.Reflection
namespace contains classes that can be used to interrogate the types for a module/assembly.
Using reflection to access .NET metadata is very similar to using ITypeLib/ITypeInfo to access
type library data in COM, and it is used for similar purposes - e.g. determining data type sizes for
marshaling data across context/process/machine boundaries.
Reflection can also be used to dynamically invoke methods (see System.Type.InvokeMember ) ,
or even create types dynamically at run-time (see System.Reflection.Emit.TypeBuilder).
Class instances often encapsulate control over resources that are not managed by the runtime,
such as window handles (HWND), database connections, and so on. Therefore, you should
provide both an explicit and an implicit way to free those resources. Provide implicit control by
implementing the protected Finalize Method on an object (destructor syntax in C# and the
Managed Extensions for C++). The garbage collector calls this method at some point after there
are no longer any valid references to the object. In some cases, you might want to provide
programmers using an object with the ability to explicitly release these external resources before
the garbage collector frees the object. If an external resource is scarce or expensive, better
performance can be achieved if the programmer explicitly releases resources when they are no
longer being used. To provide explicit control, implement the Dispose method provided by the
IDisposable Interface. The consumer of the object should call this method when it is done using
the object.
Dispose can be called even if other references to the object are alive. Note that even when you
provide explicit control by way of Dispose, you should provide implicit cleanup using the Finalize
method. Finalize provides a backup to prevent resources from
Full Assembly reference: A full assembly reference includes the assembly's text name, version,
culture, and public key token (if the assembly has a strong name). A full assembly reference is
required if you reference any assembly that is part of the common
Partial Assembly reference: We can dynamically reference an assembly by providing only partial
information, such as specifying only the assembly name. When you specify a partial assembly
reference, the runtime looks for the assembly only in the application
directory.
We can make partial references to an assembly in your code one of the following ways:
-> Use a method such as System.Reflection.Assembly.Load and specify only a partial reference.
The runtime checks for the assembly in the application directory.
-> Use the System.Reflection.Assembly.LoadWithPartialName method and specify only a partial
reference. The runtime checks for the assembly in the application directory and in the global
assembly cache
What is side-by-side execution? Can two application one using private assembly and other
using Shared assembly be stated as a side-by-side executables?
Side-by-side execution is the ability to run multiple versions of an application or component on the
same computer. You can have multiple versions of the common language runtime, and multiple
versions of applications and components that use a version of the runtime, on the same computer
at the same time. Since versioning is only applied to shared assemblies, and not to private
assemblies, two application one using private assembly and one using shared assembly cannot
be stated as side-by-side
executables.
What's the difference between the Debug class and Trace class?
Documentation looks the same. Use Debug class for debug builds, use Trace class for both
debug and release builds.
attribute, which can be used to specify the XML element name to be used for a particular property
or field.
Serialization via SoapFormatter/BinaryFormatter can also be controlled to some extent by
attributes. For example, the [NonSerialized] attribute is the equivalent of XmlSerializer's
[XmlIgnore] attribute. Ultimate control of the serialization process can be acheived by
implementing the the ISerializable interface on the class whose instances are to be serialized.
Code Groups:
Note the hierarchy of code groups - the top of the hierarchy is the most general ('All code'), which
is then sub-divided into several
groups, each of which in turn can be sub-divided. Also note that (somewhat counter-intuitively) a
sub-group can be associated with a more permissive permission set than its parent.
Note that the numeric label (1.3.1) is just a caspol invention to make the code groups easy to
manipulate from the command-line. The underlying runtime never sees it.
I can't be bothered with all this CAS stuff. Can I turn it off?
Yes, as long as you are an administrator. Just run: caspol -s off
Can I look at the IL for an assembly?
Yes. MS supply a tool called Ildasm which can be used to view the metadata and IL for an
assembly.
instance of the DefaultTraceListener class. This sends output to the Win32 OutputDebugString()
function and also the System.Diagnostics.Debugger.Log() method. This is useful when
debugging, but if you're trying to trace a problem at a customer site, redirecting the output to a file
is more appropriate. Fortunately, the TextWriterTraceListener class is provided for this purpose.
What are the contents of assembly?
In general, a static assembly can consist of four elements:
The assembly manifest, which contains assembly metadata.
Type metadata.
Microsoft intermediate language (MSIL) code that implements the types.
A set of resources.
[The process of transitively tracing through all pointers to actively used objects in order to locate
all objects that can be referenced, and then arranging to reuse any heap memory that was not
found during this trace. The common language runtime garbage collector also compacts the
memory that is in use to reduce the working space needed for the heap.]
Heap:
A portion of memory reserved for a program to use for the temporary storage of data structures
whose existence or size cannot be determined until the program is running.
Managed Code:
Code that runs under a "contract of cooperation" with the common language runtime. Managed
code must supply the metadata necessary for the runtime to provide services such as memory
management, cross-language integration, code access security, and
automatic lifetime control of objects. All code based on Microsoft intermediate language (MSIL)
executes as managed code.
Un-Managed Code:
Code that is created without regard for the conventions and requirements of the common
language runtime. Unmanaged code executes in the common language runtime environment with
minimal services (for example, no garbage collection, limited debugging, and so on).
each type, the signatures of each type's members, the members that your code references, and
other data that the runtime uses at
execution time. The MSIL and metadata are contained in a portable executable (PE) file that is
based on and extends the published
Microsoft PE and Common Object File Format (COFF) used historically for executable content.
This file format, which accommodates
MSIL or native code as well as metadata, enables the operating system to recognize common
language runtime images. The
presence of metadata in the file along with the MSIL enables your code to describe itself, which
means that there is no need for type libraries or Interface Definition Language (IDL). The runtime
locates and extracts the metadata from the file as needed during
execution.
that represent the type's data. Reference types can be self-describing types, pointer types, or
interface types
Value Type:
Value types are allocated on the stack just like primitive types in _VBScript, VB6 and C/C++.
Value types are not instantiated using new go out of scope when the function they are defined
within returns.
Value types in the CLR are defined as types that derive from system.valueType.
A data type that fully describes a value by specifying the sequence of bits that constitutes the
value's representation. Type information for a value type instance is not stored with the instance
at run time, but it is available in metadata. Value type instances can be treated as objects using
boxing.
What is Boxing and unboxing ?
Boxing:
The conversion of a value type instance to an object, which implies that the instance will carry full
type information at run time and will be allocated in the heap. The Microsoft intermediate
language (MSIL) instruction set's box instruction converts a value type to an object by making a
copy of the value type and embedding it in a newly allocated object.
Un-Boxing:
The conversion of an object instance to a value type.
contains file hashes for all the files that constitute the assembly implementation, it is sufficient to
generate the digital signature over just the one file in the assembly that contains the assembly
manifest. Assemblies with the same strong name are expected to be identical
What is namespace used for loading assemblies at run time and name the methods?
System.Reflection
Explain encapsulation ?
The implementation is hidden, the interface is exposed.
What data type should you use if you want an 8-bit value that's signed?
sbyte.
What is the difference between the value-type variables and reference-type variables in
terms of garbage collection?
The value-type variables are not garbage-collected, they just fall off the stack when they fall out of
scope, the reference-type objects
How can you sort the elements of the array in descending order?
By calling Sort() and then Reverse() methods.
What's the .NET datatype that allows the retrieval of data by a unique key?
HashTable.
Will finally block get executed if the exception had not occurred?
Yes.
Can multiple catch blocks be executed?
No, once the proper catch code fires off, the control is transferred to the finally block (if there are
any), and then whatever follows the finally block.
What's a delegate?
A delegate object encapsulates a reference to a method. In C++ they were referred to as function
pointers.