.NET Framework Interview Questions and Answers (547) - Page 21

What is Export Attribute in MEF?

MEF is a framework for creating extensible applications that allows developers to discover and use extensions with no configuration required.Part is an object (e.g. a class, a method or a property) that can be imported or exported to the application.The parts are discovered dynamically via catalogs.In MEF parlance, Import attribute defines the need that a part has.The Export attribute fulfills that. It exposes those parts that will participate in the composition.

e.g. say we have an interface as under

public interface ICalculator

{
int GetNumber(int num1, int num2);
}

any object that wants to be a part (Export component) of MEF composition has to satisfy this Interface

e.g.

[Export(typeof(ICalculator))]

public class Add:ICalculator
{
#region Interface members
public int GetNumber(int num1, int num2)
{
return num1 + num2;
}
#endregion
}


is a valid Export component but not the below

[Export(typeof(ICalculator))]

public class Add:INonMEFCalculator
{
#region Interface members
public void SayHello()
{
//do something
}
#endregion
}


because it does not satisfy the need that a part need in this scenario.

Multiple values can be imported by using the [ExportMany] attribute.
What is Compose in MEF?

MEF is a framework for creating extensible applications that allows developers to discover and use extensions with no configuration required.Part is an object (e.g. a class, a method or a property) that can be imported or exported to the application.The parts are discovered dynamically via catalogs.Import attribute defines the need that a part has.The Export attribute fulfills that. It exposes those parts that will participate in the composition.In MEF jargon, Compose is that area where the Exported parts will be assembled with the imported ones.

e.g. say we have an interface as under

public interface ICalculator

{
int GetNumber(int num1, int num2);
}

any object that wants to be a part (Export Part) of MEF composition has to satisfy this Interface

e.g.

[Export(typeof(ICalculator))]

public class Add:ICalculator
{
#region Interface members
public int GetNumber(int num1, int num2)
{
return num1 + num2;
}
#endregion
}


The import part will be as under

[Import(typeof(ICalculator))]

public ICalculator CalciPlugin { get; set; }

and the composition part will be as under

public void AssembleCalculatorComponents()

{
try
{
//Step 1: Initializes a new instance of the
// System.ComponentModel.Composition.Hosting.AssemblyCatalog
// class with the current executing assembly.
var catalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());

//Step 2: The assemblies obtained in step 1 are added to the
//CompositionContainer
var container = new CompositionContainer(catalog);

//Step 3: Composable parts are created here i.e.
//the Import and Export components
// assembles here
container.ComposeParts(this);
}
catch (Exception ex)
{
throw ex;
}
}


In the AssembleCalculatorComponent function we are first looking for the catalogs (here Assembly Catalogs) from where the parts are coming. Once identified, the catalogs are held in a container and lastly the parts are composed.
What are the advantages of MEF?

MEF is a framework for creating extensible applications that allows developers to discover and use extensions with no configuration required.That means at runtime, this framework has got the capability to discover extensibile components.
There are some benefits of using this some of them are enumerated as under -

a.MEF breaks the tightly coupled dependencies across the application but respects the type checking of the loosely coupled parts.

b.Applications can be extended.

c.Components can be added at runtime.

d.Dynamic discovery of the components.

e.Great piece of reusability.
Explain about .edmx file..

It is an extension for a file where the visual studio saves the entire Entity Data Model Configurations.
This file has an XML format.
This extension file consists of 3 sections as storage schema, conceptual schema, and the mappings.
Explain about NHibernate..

For .NET framework, this NHibernate acts as a open source object relational mapper.
This framework will support the connectivity to multiple databases, as it is simply a matter of updating the driver configuration.
It has to be dowloaded first and then the NHibernate.dll has to be referred by adding a reference in your visual studio.
What is the reason for using an IDE?

We should use IDE at least for the below reasons.
1) Automatic code generation.
2) Debugging is integrated which indicates that the step debugger actually uses your in-place editor to visually show you which code is executed.
3) Integrated source control.
4) Compiling is usually "on the fly" which indicates no more switching to the command line to compile.
5) Filesystem explorer.
6) Quickly navigating to a type without needing to worry about namespace, project etc.
7) Navigating to members by treating them as hyperlinks.
8) Refactoring.
9) Organize imports.
10) Ease of running unit tests from the same window.
Expand pdb file.

NOTE: This is objective type question, Please click question title for correct answer.
Explain .pdb file.

When the project is built under "Debug" mode, .pdb files will get created.

When compiled with debugging information, an executable file contains two references to the associated PDB file:

• Local variable names.
• The full path of the associated PDB file that will be used during the debugging session.

The other information is not required in the PDB file because it is available in metadata file.

When a program to be debugged is launched, the debugger goes into the executable file and tries to locate the correct PDB file to proceed to the debugging session.
What is GAC?

GAC (Global Assembly Cache) is where all shared .NET assembly reside. GAC is used in the
following situations:-
• If the application has to be shared among several application.
• If the assembly has some special security, requirements like only administrators can remove the assembly. If the assembly is private then a simple delete of assembly the assembly file will remove the assembly.
What is the meaning of Dot(.) in Dot Net?????

According to me Dot(.) mean accessors . Dot Net framework provides the facility of accessor. Help of Dot(.) we can access the properties,classes and method. This is inbuilt mechanism of Dot Net Framework.
What is Nancy ?

It is open-source lightweight, low-ceremony, web framework for building HTTP based services on .Net and Mono Platform.

Mainly intended for handle various kinds of HTTP request (DELETE, GET,POST, PUT etc).

Primary focused of the framework is leaving developer with more time to focus on the your code and your application.

It is Built with the .NET framework client profile and you can download latest version from Nuget and Source code from GitHub repositories.
What is dotCover ?

It is a .NET code coverage and unit testing tool from JetBrain,which you can easily integrate into visual studio (2005-2012).

It supports several unit testing frameworks such as MSTest, NUnit, xUnit, and MSpec.

You can generate code coverage reports into various format like XML, HTML, or JSON.

It is an all-in-one tool for running unit tests, analyzing code coverage results, and improving tests.
Why you must close and dispose the resources in the finally block instead of catch block?

NOTE: This is objective type question, Please click question title for correct answer.
which of the following are reference types ?

NOTE: This is objective type question, Please click question title for correct answer.
Correct order for catch clauses when handling different exception types ?

NOTE: This is objective type question, Please click question title for correct answer.
which of the following are built-in generic types ?

NOTE: This is objective type question, Please click question title for correct answer.
What are the common uses attributes ?

Used to specify which security privileges a class requires.

Used to declare capabilities (e.g: supporting serialization)

Used to describe the assembly.(e.g: provides a title,description, copyright etc)
What is Type Forwarding ?

It is an attribute that allows you to move a type from one assembly into another assembly and to do so in such a way that it is not necessary to recompile clients that consume assembly.

To move a type from one class lib to another, follow below steps

1) Add a TypeForwardedTo attribute to source class lib assembly.
2) cut the type definition from source class lib.
3) paste the type defintion into destination class lib.
4) rebuild both lib
What is Spring.Net ?

It is open source framework for building enterprise level application in .Net. It consist of 14 modules (Spring.Core,Spring.Aop,Spring.Data,Spring.Data.NHibernate etc).

You can integrated into all tiers of your application architecture.

You can use the functionality in its modules independently. All module have been developed using proven design pattern.
Found this useful, bookmark this page to the blog or social networking websites. Page copy protected against web site content infringement by Copyscape

 Interview Questions and Answers Categories