Dot net Questions & Answers that can help in interviews [part 4]

301.Now let us answer What are jagged arrays?
A jagged array is an array whose elements are arrays. The elements of jagged array can be of different dimensions and sizes. A jagged array is sometimes called as “array-of-arrays”. It is called jagged because each of its rows is of different size so the final or graphical representation is not a square.
When you create a jagged array you declare the number of rows in your array. Each row will hold an array that will be on any length. Before filling the values in the inner arrays you must declare them.
Jagged array declaration in C#:
For e.g. : int [] [] myJaggedArray = new int [3][];
Declaration of inner arrays:

myJaggedArray[0] = new int[5] ; // First inner array will be of length 5.
myJaggedArray[1] = new int[4] ; // Second inner array will be of length 4.
myJaggedArray[2] = new int[3] ; // Third inner array will be of length 3.
Now to access third element of second row we write:
int value = myJaggedArray[1][2];
Note that while declaring the array the second dimension is not supplied because this you will declare later on in the code.
Jagged array are created out of single dimensional arrays so be careful while using them. Don't confuse it with multi-dimensional arrays because unlike them jagged arrays are not rectangular arrays.
For more information on arrays:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vclrfarrayspg.asp
302.What is a delegate, why should you use it and how do you call it ?
A delegate is a reference type that refers to a Shared method of a type or to an instance method of an object. Delegate is like a function pointer in C and C++. Pointers are used to store the address of a thing. Delegate lets some other code call your function without needing to know where your function is actually located. All events in .NET actually use delegates in the background to wire up events. Events are really just a modified form of a delegate.
It should give you an idea of some different areas in which delegates may be appropriate:
· They enable callback functionality in multi-tier applications as demonstrated in the examples above.
· The CacheItemRemoveCallback delegate can be used in ASP.NET to keep cached information up to date. When the cached information is removed for any reason, the associated callback is exercised and could contain a reload of the cached information.
· Use delegates to facilitate asynchronous processing for methods that do not offer asynchronous behavior.
· Events use delegates so clients can give the application events to call when the event is fired. Exposing custom events within your applications requires the use of delegates.
303.How does the XmlSerializer work?
XmlSerializer in the .NET Framework is a great tool to convert Xml into runtime objects and vice versa
If you define integer variable and a object variable and a structure then how those will be plotted in memory.
Integer , structure – System.ValueType -- Allocated memory on stack , infact integer is primitive type recognized and allocated memory by compiler itself .
Infact , System.Int32 definition is as follows :
[C#]
[Serializable]
public struct Int32 : IComparable, IFormattable, IConvertible
So , it's a struct by definition , which is the same case with various other value types .
Object – Base class , that is by default reference type , so at runtime JIT compiler allocates memory on the “Heap” Data structure .
Reference types are defined as class , derived directly or indirectly by System.ReferenceType
WebServices And Windows Services

Next>>
Can you give an example of when it would be appropriate to use a web service as opposed to non-serviced .NET component
Web service is one of main component in Service Oriented Architecture. You could use web services when your clients and servers are running on different networks and also different platforms. This provides a loosely coupled system. And also if the client is behind the firewall it would be easy to use web service since it runs on port 80 (by default) instead of having some thing else in Service Oriented Architecture applications.
304.What is the standard you use to wrap up a call to a Web service
"SOAP.
"
What is the transport protocol you use to call a Web service SOAP
HTTP with SOAP

305.What does WSDL stand for?
"WSDL stands for Web Services Dsescription Langauge. There is WSDL.exe that creates a .wsdl Files which defines how an XML Web service behaves and instructs clients as to how to interact with the service.
eg: wsdl http://LocalHost/WebServiceName.asmx"

306.Where on the Internet would you look for Web Services?
www.uddi.org

307.What does WSDL stand for?
Web Services Description Language

309.True or False: To test a Web service you must create a windows application or Web application to consume this service?
False.

310.What are the various ways of accessing a web service ?
1.Asynchronous Call
Application can make a call to the Webservice and then continue todo watever oit wants to do.When the service is ready it will notify the application.Application can use BEGIN and END method to make asynchronous call to the webmethod.We can use either a WaitHandle or a Delegate object when making asynchronous call.
The WaitHandle class share resources between several objects. It provides several methods which will wait for the resources to become available
The easiest and most powerful way to to implement an asynchronous call is using a delegate object. A delegate object wraps up a callback function. The idea is to pass a method in the invocation of the web method. When the webmethod has finished it will call this callback function to process the result

2.Synchronous Call
Application has to wait until execution has completed.

311.What are VSDISCO files?
VSDISCO files are DISCO files that support dynamic discovery of Web services. If you place the following VSDISCO file in a directory on your Web server, for example, it returns references to all ASMX and DISCO files in the host directory and any subdirectories not noted in elements:
xmlns="urn:schemas-dynamicdiscovery:disco.2000-03-17">

312.How does dynamic discovery work?
ASP.NET maps the file name extension VSDISCO to an HTTP handler that scans the host directory and subdirectories for ASMX and DISCO files and returns a dynamically generated DISCO document. A client who requests a VSDISCO file gets back what appears to be a static DISCO document.

Note that VSDISCO files are disabled in the release version of ASP.NET. You can reenable them by uncommenting the line in the section of Machine.config that maps *.vsdisco to System.Web.Services.Discovery.DiscoveryRequestHandler and granting the ASPNET user account permission to read the IIS metabase. However, Microsoft is actively discouraging the use of VSDISCO files because they could represent a threat to Web server security.

313.Is it possible to prevent a browser from caching an ASPX page?
Just call SetNoStore on the HttpCachePolicy object exposed through the Response object's Cache property, as demonstrated here:

<%@ Page Language="C#" %>

<%
Response.Cache.SetNoStore ();
Response.Write (DateTime.Now.ToLongTimeString ());
%>
SetNoStore works by returning a Cache-Control: private, no-store header in the HTTP response. In this example, it prevents caching of a Web page that shows the current time.

314.What does AspCompat="true" mean and when should I use it?
AspCompat is an aid in migrating ASP pages to ASPX pages. It defaults to false but should be set to true in any ASPX file that creates apartment-threaded COM objects--that is, COM objects registered ThreadingModel=Apartment. That includes all COM objects written with Visual Basic 6.0. AspCompat should also be set to true (regardless of threading model) if the page creates COM objects that access intrinsic ASP objects such as Request and Response. The following directive sets AspCompat to true:
<%@ Page AspCompat="true" %>
Setting AspCompat to true does two things. First, it makes intrinsic ASP objects available to the COM components by placing unmanaged wrappers around the equivalent ASP.NET objects. Second, it improves the performance of calls that the page places to apartment- threaded COM objects by ensuring that the page (actually, the thread that processes the request for the page) and the COM objects it creates share an apartment. AspCompat="true" forces ASP.NET request threads into single-threaded apartments (STAs). If those threads create COM objects marked ThreadingModel=Apartment, then the objects are created in the same STAs as the threads that created them. Without AspCompat="true," request threads run in a multithreaded apartment (MTA) and each call to an STA-based COM object incurs a performance hit when it's marshaled across apartment boundaries.
Do not set AspCompat to true if your page uses no COM objects or if it uses COM objects that don't access ASP intrinsic objects and that are registered ThreadingModel=Free or ThreadingModel=Both.

315.Can two different programming languages be mixed in a single ASMX file?
No.

316.What namespaces are imported by default in ASMX files?
The following namespaces are imported by default. Other namespaces must be imported manually.· System, System.Collections,System.ComponentModel,System.Data, System.Diagnostics,System.Web,System.Web.Services
317.How do I provide information to the Web Service when the information is required as a SOAP Header?
The key here is the Web Service proxy you created using wsdl.exe or through Visual Studio .NET's Add Web Reference menu option. If you happen to download a WSDL file for a Web Service that requires a SOAP header, .NET will create a SoapHeader class in the proxy source file. Using the previous example:
public class Service1 : System.Web.Services.Protocols.SoapHttpClientProtocol
{
public AuthToken AuthTokenValue;

[System.Xml.Serialization.XmlRootAttribute(Namespace="http://tempuri.org/", IsNullable=false)]
public class AuthToken : SoapHeader { public string Token; }}

In this case, when you create an instance of the proxy in your main application file, you'll also create an instance of the AuthToken class and assign the string:
Service1 objSvc = new Service1();
processingobjSvc.AuthTokenValue = new AuthToken();
objSvc.AuthTokenValue.Token = ;
Web Servicestring strResult = objSvc.MyBillableWebMethod();

318.What is WSDL?
WSDL is the Web Service Description Language, and it is implemented as a specific XML vocabulary. While it's very much more complex than what can be described here, there are two important aspects to WSDL with which you should be aware. First, WSDL provides instructions to consumers of Web Services to describe the layout and contents of the SOAP packets the Web Service intends to issue. It's an interface description document, of sorts. And second, it isn't intended that you read and interpret the WSDL. Rather, WSDL should be processed by machine, typically to generate proxy source code (.NET) or create dynamic proxies on the fly (the SOAP Toolkit or Web Service Behavior).

319.What is a Windows Service and how does its lifecycle differ from a "standard" EXE?
Windows service is a application that runs in the background. It is equivalent to a NT service.
The executable created is not a Windows application, and hence you can't just click and run it . it needs to be installed as a service, VB.Net has a facility where we can add an installer to our program and then use a utility to install the service. Where as this is not the case with standard exe

320.How can a win service developed in .NET be installed or used in Win98?
Windows service cannot be installed on Win9x machines even though the .NET framework runs on machine.
321.Can you debug a Windows Service? How ?
Yes we can debug a Windows Service.
Attach the WinDbg debugger to a service after the service starts
This method is similar to the method that you can use to attach a debugger to a process and then debug a process.
Use the process ID of the process that hosts the service that you want to debug
1 To determine the process ID (PID) of the process that hosts the service that you want to debug, use one of the following methods.
• Method 1: Use the Task Manager
a. Right-click the taskbar, and then click Task Manager. The Windows Task Manager dialog box appears.
b. Click the Processes tab of the Windows Task Manager dialog box.
c. Under Image Name, click the image name of the process that hosts the service that you want to debug. Note the process ID of this process as specified by the value of the corresponding PID field.
• Method 2: Use the Task List Utility (tlist.exe)
a. Click Start, and then click Run. The Run dialog box appears.
b. In the Open box, type cmd, and then click OK.
c. At the command prompt, change the directory path to reflect the location of the tlist.exe file on your computer.

Note The tlist.exe file is typically located in the following directory: C:Program FilesDebugging Tools for Windows
d. At the command prompt, type tlist to list the image names and the process IDs of all processes that are currently running on your computer.

Note Make a note of the process ID of the process that hosts the service that you want to debug.
2 At a command prompt, change the directory path to reflect the location of the windbg.exe file on your computer.

Note If a command prompt is not open, follow steps a and b of Method 1. The windbg.exe file is typically located in the following directory: C:Program FilesDebugging Tools for Windows.
3 At the command prompt, type windbg –p ProcessID to attach the WinDbg debugger to the process that hosts the service that you want to debug.

Note ProcessID is a placeholder for the process ID of the process that hosts the service that you want to debug.

Use the image name of the process that hosts the service that you want to debug

You can use this method only if there is exactly one running instance of the process that hosts the service that you want to run. To do this, follow these steps:
1 Click Start, and then click Run. The Run dialog box appears.
2 In the Open box, type cmd, and then click OK to open a command prompt.
3 At the command prompt, change the directory path to reflect the location of the windbg.exe file on your computer.

Note The windbg.exe file is typically located in the following directory: C:Program FilesDebugging Tools for Windows.
4 At the command prompt, type windbg –pn ImageName to attach the WinDbg debugger to the process that hosts the service that you want to debug.

NoteImageName is a placeholder for the image name of the process that hosts the service that you want to debug. The "-pn" command-line option specifies that the ImageName command-line argument is the image name of a process.
back to the top
Start the WinDbg debugger and attach to the process that hosts the service that you want to debug

1 Start Windows Explorer.
2 Locate the windbg.exe file on your computer.

Note The windbg.exe file is typically located in the following directory: C:Program FilesDebugging Tools for Windows
3 Run the windbg.exe file to start the WinDbg debugger.
4 On the File menu, click Attach to a Process to display the Attach to Process dialog box.
5 Click to select the node that corresponds to the process that hosts the service that you want to debug, and then click OK.
6 In the dialog box that appears, click Yes to save base workspace information. Notice that you can now debug the disassembled code of your service.
Configure a service to start with the WinDbg debugger attached
You can use this method to debug services if you want to troubleshoot service-startup-related problems.
1 Configure the "Image File Execution" options. To do this, use one of the following methods:
• Method 1: Use the Global Flags Editor (gflags.exe)
a. Start Windows Explorer.
b. Locate the gflags.exe file on your computer.

Note The gflags.exe file is typically located in the following directory: C:Program FilesDebugging Tools for Windows.
c. Run the gflags.exe file to start the Global Flags Editor.
d. In the Image File Name text box, type the image name of the process that hosts the service that you want to debug. For example, if you want to debug a service that is hosted by a process that has MyService.exe as the image name, type MyService.exe.
e. Under Destination, click to select the Image File Options option.
f. Under Image Debugger Options, click to select the Debugger check box.
g. In the Debugger text box, type the full path of the debugger that you want to use. For example, if you want to use the WinDbg debugger to debug a service, you can type a full path that is similar to the following: C:Program FilesDebugging Tools for Windowswindbg.exe
h. Click Apply, and then click OK to quit the Global Flags Editor.
• Method 2: Use Registry Editor
a. Click Start, and then click Run. The Run dialog box appears.
b. In the Open box, type regedit, and then click OK to start Registry Editor.
c. Warning If you use Registry Editor incorrectly, you may cause serious problems that may require you to reinstall your operating system. Microsoft cannot guarantee that you can solve problems that result from using Registry Editor incorrectly. Use Registry Editor at your own risk.

In Registry Editor, locate, and then right-click the following registry subkey:
HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionImage File Execution Options
d. Point to New, and then click Key. In the left pane of Registry Editor, notice that New Key #1 (the name of a new registry subkey) is selected for editing.
e. Type ImageName to replace New Key #1, and then press ENTER.

Note ImageName is a placeholder for the image name of the process that hosts the service that you want to debug. For example, if you want to debug a service that is hosted by a process that has MyService.exe as the image name, type MyService.exe.
f. Right-click the registry subkey that you created in step e.
g. Point to New, and then click String Value. In the right pane of Registry Editor, notice that New Value #1, the name of a new registry entry, is selected for editing.
h. Replace New Value #1 with Debugger, and then press ENTER.
i. Right-click the Debugger registry entry that you created in step h, and then click Modify. The Edit String dialog box appears.
j. In the Value data text box, type DebuggerPath, and then click OK.

Note DebuggerPath is a placeholder for the full path of the debugger that you want to use. For example, if you want to use the WinDbg debugger to debug a service, you can type a full path that is similar to the following: C:Program FilesDebugging Tools for Windowswindbg.exe
2 For the debugger window to appear on your desktop, and to interact with the debugger, make your service interactive. If you do not make your service interactive, the debugger will start but you cannot see it and you cannot issue commands. To make your service interactive, use one of the following methods:
• Method 1: Use the Services console
a. Click Start, and then point to Programs.
b. On the Programs menu, point to Administrative Tools, and then click Services. The Services console appears.
c. In the right pane of the Services console, right-click ServiceName, and then click Properties.

Note ServiceName is a placeholder for the name of the service that you want to debug.
d. On the Log On tab, click to select the Allow service to interact with desktop check box under Local System account, and then click OK.
• Method 2: Use Registry Editor
a. In Registry Editor, locate, and then click the following registry subkey:
HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesServiceName
Note Replace ServiceName with the name of the service that you want to debug. For example, if you want to debug a service named MyService, locate and then click the following registry key:
HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesMyService
b. Under the Name field in the right pane of Registry Editor, right-click Type, and then click Modify. The Edit DWORD Value dialog box appears.
c. Change the text in the Value data text box to the result of the binary OR operation with the binary value of the current text and the binary value, 0x00000100, as the two operands. The binary value, 0x00000100, corresponds to the SERVICE_INTERACTIVE_PROCESS constant that is defined in the WinNT.h header file on your computer. This constant specifies that a service is interactive in nature.
3 When a service starts, the service communicates to the Service Control Manager how long the service must have to start (the time-out period for the service). If the Service Control Manager does not receive a "service started" notice from the service within this time-out period, the Service Control Manager terminates the process that hosts the service. This time-out period is typically less than 30 seconds. If you do not adjust this time-out period, the Service Control Manager ends the process and the attached debugger while you are trying to debug. To adjust this time-out period, follow these steps:
a. In Registry Editor, locate, and then right-click the following registry subkey:
HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControl
b. Point to New, and then click DWORD Value. In the right pane of Registry Editor, notice that New Value #1 (the name of a new registry entry) is selected for editing.
c. Type ServicesPipeTimeout to replace New Value #1, and then press ENTER.
d. Right-click the ServicesPipeTimeout registry entry that you created in step c, and then click Modify. The Edit DWORD Value dialog box appears.
e. In the Value data text box, type TimeoutPeriod, and then click OK

Note TimeoutPeriod is a placeholder for the value of the time-out period (in milliseconds) that you want to set for the service. For example, if you want to set the time-out period to 24 hours (86400000 milliseconds), type 86400000.
f. Restart the computer. You must restart the computer for Service Control Manager to apply this change.
4 Start your Windows service. To do this, follow these steps:
a. Click Start, and then point to Programs.
b. On the Programs menu, point to Administrative Tools, and then click Services. The Services console appears.
c. In the right pane of the Services console, right-click ServiceName, and then click Start.

Note ServiceName is a placeholder for the name of the service that you want to debug.

COM And COM+

321.What are different transaction options available for services components ?
There are 5 transactions types that can be used with COM+. Whenever an object is registered with COM+ it has to abide either to these 5 transaction types.
Disabled: - There is no transaction. COM+ does not provide transaction support for this component.
Not Supported: - Component does not support transactions. Hence even if the calling component in the hierarchy is transaction enabled this component will not participate in the transaction.
Supported: - Components with transaction type supported will be a part of the transaction if the calling component has an active transaction.
If the calling component is not transaction enabled this component will not start a new transaction.
Required: - Components with this attribute require a transaction i.e. either the calling should have a transaction in place else this component will start a new transaction.
Required New: - Components enabled with this transaction type always require a new transaction. Components with required new transaction type instantiate a new transaction for themselves every time.

322.Can we use com Components in .net?.How ?.can we use .net components in vb?.Explain how ?
COM components have different internal architecture from .NET components hence they are not innately compatible. However .NET framework supports invocation of unmanaged code from managed code (and vice-versa) through COM/.NET interoperability. .NET application communicates with a COM component through a managed wrapper of the component called Runtime Callable Wrapper (RCW); it acts as managed proxy to the unmanaged COM component. When a method call is made to COM object, it goes onto RCW and not the object itself. RCW manages the lifetime management of the COM component. Implementation Steps -
Create Runtime Callable Wrapper out of COM component. Reference the metadata assembly Dll in the project and use its methods & properties RCW can be created using Type Library Importer utility or through VS.NET. Using VS.NET, add reference through COM tab to select the desired DLL. VS.NET automatically generates metadata assembly putting the classes provided by that component into a namespace with the same name as COM dll (XYZRCW.dll)
.NET components can be invoked by unmanaged code through COM Callable Wrapper (CCW) in COM/.NET interop. The unmanaged code will talk to this proxy, which translates call to managed environment. We can use COM components in .NET through COM/.NET interoperability. When managed code calls an unmanaged component, behind the scene, .NET creates proxy called COM Callable wrapper (CCW), which accepts commands from a COM client, and forwards it to .NET component. There are two prerequisites to creating .NET component, to be used in unmanaged code:
1. .NET class should be implement its functionality through interface. First define interface in code, then have the class to imlpement it. This way, it prevents breaking of COM client, if/when .NET component changes.
2.Secondly, .NET class, which is to be visible to COM clients must be declared public. The tools that create the CCW only define types based
on public classes. The same rule applies to methods, properties, and events that will be used by COM clients.
Implementation Steps -
1. Generate type library of .NET component, using TLBExporter utility. A type library is the COM equivalent of the metadata contained within
a .NET assembly. Type libraries are generally contained in files with the extension .tlb. A type library contains the necessary information to allow a COM client to determine which classes are located in a particular server, as well as the methods, properties, and events supported by those classes.
2. Secondly, use Assembly Registration tool (regasm) to create the type library and register it.
3. Lastly install .NET assembly in GAC, so it is available as shared assembly.
What is Runtime Callable wrapper?.when it will created?.
The common language runtime exposes COM objects through a proxy called the runtime callable wrapper (RCW). Although the RCW appears to be an ordinary object to .NET clients, its primary function is to marshal calls between a .NET client and a COM object. This wrapper turns the COM interfaces exposed by the COM component into .NET-compatible interfaces. For oleautomation (attribute indicates that an interface is compatible with Automation) interfaces, the RCW can be generated automatically from a type library. For non-oleautomation interfaces, it may be necessary to develop a custom RCW which manually maps the types exposed by the COM interface to .NET-compatible types.
324.What is Com Callable wrapper?when it will created?
.NET components are accessed from COM via a COM Callable Wrapper (CCW). This is similar to a RCW, but works in the opposite direction. Again, if the wrapper cannot be automatically generated by the .NET development tools, or if the automatic behaviour is not desirable, a custom CCW can be developed. Also, for COM to 'see' the .NET component, the .NET component must be registered in the registry.CCWs also manage the object identity and object lifetime of the managed objects they wrap.
326.What is a primary interop ?
A primary interop assembly is a collection of types that are deployed, versioned, and configured as a single unit. However, unlike other managed assemblies, an interop assembly contains type definitions (not implementation) of types that have already been defined in COM. These type definitions allow managed applications to bind to the COM types at compile time and provide information to the common language runtime
about how the types should be marshaled at run time.
327.What are tlbimp and tlbexp tools used for ?
The Type Library Exporter generates a type library that describes the types defined in a common language runtime assembly.
The Type Library Importer converts the type definitions found within a COM type library into equivalent definitions in a common language runtime assembly. The output of Tlbimp.exe is a binary file (an assembly) that contains runtime metadata for the types defined within the original type library.
328.What benefit do you get from using a Primary Interop Assembly (PIA)?
PIAs are important because they provide unique type identity. The PIA distinguishes the official type definitions from counterfeit definitions provided by other interop assemblies. Having a single type identity ensures type compatibility between applications that share the types defined in the PIA. Because the PIA is signed by its publisher and labeled with the PrimaryInteropAssembly attribute, it can be differentiated from other interop assemblies that define the same types.
Remoting FAQ's

329.What distributed process frameworks outside .NET do you know?
Distributed Computing Environment/Remote Procedure Calls (DEC/RPC), Microsoft Distributed Component Object Model (DCOM), Common Object Request Broker Architecture (CORBA), and Java Remote Method Invocation (RMI).

330.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.

331.When would you use .NET Remoting and when Web services?
Use remoting for more efficient exchange of information when you control both ends of the application. Use Web services for open-protocol-based information exchange when you are just a client or a server with the other end belonging to someone else.

332.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.

333.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.

334.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.

335.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.

336.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.

337.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.

338.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.

339.How do you define the lease of the object?
By implementing ILease interface when writing the class code.

340.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.

341.How can you automatically generate interface for the remotable object in .NET with Microsoft tools?
Use the Soapsuds tool.

342.What are CAO's i.e. Client Activated Objects ?
Client-activated objects are objects whose lifetimes are controlled by the calling application domain, just as they would be if the object were local to the client. With client activation, a round trip to the server occurs when the client tries to create an instance of the server object, and the client proxy is created using an object reference (ObjRef) obtained on return from the creation of the remote object on the server. Each time a client creates an instance of a client-activated type, that instance will service only that particular reference in that particular client until its lease expires and its memory is recycled. If a calling application domain creates two new instances of the remote type, each of the client references will invoke only the particular instance in the server application domain from which the reference was returned.
In COM, clients hold an object in memory by holding a reference to it. When the last client releases its last reference, the object can delete itself. Client activation provides the same client control over the server object's lifetime, but without the complexity of maintaining references or the constant pinging to confirm the continued existence of the server or client. Instead, client-activated objects use lifetime leases to determine how long they should continue to exist. When a client creates a remote object, it can specify a default length of time that the object should exist. If the remote object reaches its default lifetime limit, it contacts the client to ask whether it should continue to exist, and if so, for how much longer. If the client is not currently available, a default time is also specified for how long the server object should wait while trying to contact the client before marking itself for garbage collection. The client might even request an indefinite default lifetime, effectively preventing the remote object from ever being recycled until the server application domain is torn down. The difference between this and a server-activated indefinite lifetime is that an indefinite server-activated object will serve all client requests for that type, whereas the client-activated instances serve only the client and the reference that was responsible for their creation. For more information, see Lifetime Leases.
To create an instance of a client-activated type, clients either configure their application programmatically (or using a configuration file) and call new (New in Visual Basic), or they pass the remote object's configuration in a call to Activator.CreateInstance. The following code example shows such a call, assuming a TcpChannel has been registered to listen on port 8080.

343.How many processes can listen on a single TCP/IP port?
One.

344.What technology enables out-of-proc communication in .NET?
Most usually Remoting;.NET remoting enables client applications to use objects in other processes on the same computer or on any other computer available on its network.While you could implement an out-of-proc component in any number of other ways, someone using the term almost always means Remoting.

345.How can objects in two diff. App Doimains communicate with each other?
.Net framework provides various ways to communicate with objects in different app domains.
First is XML Web Service on internet, its good method because it is built using HTTP protocol and SOAP formatting.
If the performance is the main concern then go for second option which is .Net remoting because it gives you the option of using binary encoding and the default TcpChannel, which offers the best interprocess communication performance
346.What is the difference between .Net Remoting and Web Services?
Although we can develop an application using both technologies, each of them has its distinct advantages. Yes you can look at them in terms of performance but you need to consider your need first. There are many other factors such authentications, authorizing in process that need to be considered.
Point Remoting Webservices
If your application needs interoperability with other platforms or operating systems No Yes, Choose Web Services because it is more flexible in that they are support SOAP.
If performance is the main requirement with security You should use the TCP channel and the binary formatter No
Complex Programming Yes No
State Management Supports a range of state management, depending on what object lifetime scheme you choose (single call or singleton call). Its stateless service management (does not inherently correlate multiple calls from the same user)
Transport Protocol It can access through TCP or HTTP channel. It can be access only through HTTP channel.
WinForms FAQ :

347.What base class do all Web Forms inherit from?
System.Windows.Forms.Form

348.What is the difference between Debug.Write and Trace.Write? When should each be used?
The Debug.Write call won't be compiled when the DEBUGsymbol is not defined (when doing a release build). Trace.Write calls will be compiled. Debug.Write is for information you want only in debug builds, Trace.Write is for when you want it in release build as well.

349.Difference between Anchor and Dock Properties?
Dock Property->Gets or sets which edge of the parent container a control is docked to. A control can be docked to one edge of its parent container or can be docked to all edges and fill the parent container. For example, if you set this property to DockStyle.Left, the left edge of the
control will be docked to the left edge of its parent control. Additionally, the docked edge of the control is resized to match that of its container
control.
Anchor Property->Gets or sets which edges of the control are anchored to the edges of its container. A control can be anchored to one or more edges of its parent container. Anchoring a control to its parent ensures that the anchored edges remain in the same position relative to the edges of the parent container when the parent container is resized.

350.When would you use ErrorProvider control?
ErrorProvider control is used in Windows Forms application. It is like Validation Control for ASP.NET pages. ErrorProvider control is used to provide validations in Windows forms and display user friendly messages to the user if the validation fails.
E.g
If we went to validate the textBox1 should be empty, then we can validate as below
1). You need to place the errorprovide control on the form
private void textBox1_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{
ValidateName();
}
private bool ValidateName()
{
bool bStatus = true;
if (textBox1.Text == "")
{
errorProvider1.SetError (textBox1,"Please enter your Name");
bStatus = false;
}
else
errorProvider1.SetError (textBox1,"");
return bStatus;
}
it check the textBox1 is empty . If it is empty, then a message Please enter your name is displayed.

350.Can you write a class without specifying namespace? Which namespace does it belong to by default??
Yes, you can, then the class belongs to global namespace which has no name. For commercial products, naturally, you wouldn't want global namespace.

You are designing a GUI application with a windows and several widgets on it. The user then resizes the app window and sees a lot of grey space, while the widgets stay in place. What's the problem?
One should use anchoring for correct resizing. Otherwise the default property of a widget on a form is top-left, so it stays at the same location when resized.

351.How can you save the desired properties of Windows Forms application?
.config files in .NET are supported through the API to allow storing and retrieving information. They are nothing more than simple XML files, sort of like what .ini files were before for Win32 apps.

So how do you retrieve the customized properties of a .NET application from XML .config file?
Initialize an instance of AppSettingsReader class. Call the GetValue method of AppSettingsReader class, passing in the name of the property and the type expected. Assign the result to the appropriate variable.

352.Can you automate this process?
In Visual Studio yes, use Dynamic Properties for automatic .config creation, storage and retrieval.

My progress bar freezes up and dialog window shows blank, when an intensive background process takes over.
Yes, you should've multi-threaded your GUI, with taskbar and main form being one thread, and the background process being the other.

353.What's the safest way to deploy a Windows Forms app?
Web deployment: the user always downloads the latest version of the code, the program runs within security sandbox, properly written app will not require additional security privileges.

354.Why is it not a good idea to insert code into InitializeComponent method when working with Visual Studio?
The designer will likely through it away, most of the code inside InitializeComponent is auto-generated.

355.What's the difference between WindowsDefaultLocation and WindowsDefaultBounds?
WindowsDefaultLocation tells the form to start up at a location selected by OS, but with internally specified size. WindowsDefaultBounds delegates both size and starting position choices to the OS.

356.What's the difference between Move and LocationChanged? Resize and SizeChanged?
Both methods do the same, Move and Resize are the names adopted from VB to ease migration to C#.

357.How would you create a non-rectangular window, let's say an ellipse?
Create a rectangular form, set the TransparencyKey property to the same value as BackColor, which will effectively make the background of the form transparent. Then set the FormBorderStyle to FormBorderStyle.None, which will remove the contour and contents of the form.

358.How do you create a separator in the Menu Designer?
A hyphen '-' would do it. Also, an ampersand '&' would underline the next letter.

359.How's anchoring different from docking?
Anchoring treats the component as having the absolute size and adjusts its location relative to the parent form. Docking treats the component location as absolute and disregards the component size. So if a status bar must always be at the bottom no matter what, use docking. If a button should be on the top right, but change its position with the form being resized, use anchoring.

360.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.

361.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.

362.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.

363.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.

364.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.

365.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.

1-100 Questions | 101-200 Questions | 201-300 Questions | 301- 350+ Questions |

Web Page of Naseem Amjad (Computer Software Developer of Pakistan)