Sunteți pe pagina 1din 3

.

NET and COM interop questions

1. Describe the advantages of writing a managed code application


instead of unmanaged one. What’s involved in certain piece of code
being managed? The advantages include automatic garbage collection,
memory management, support for versioning and security. These advantages
are provided through .NET FCL and CLR, while with the unmanaged code
similar capabilities had to be implemented through third-party libraries or as a
part of the application itself.
2. Are COM objects managed or unmanaged? Since COM objects were
written before .NET, apparently they are unmanaged.

3. So can a COM object talk to a .NET object? Yes, through Runtime Callable
Wrapper (RCW) or PInvoke.
4. How do you generate an RCW from a COM object? Use the Type Library
Import utility shipped with SDK. tlbimp COMobject.dll /out:.NETobject.dll or
reference the COM library from Visual Studio in your project.

5. I can’t import the COM object that I have on my machine. Did you write
that object? You can only import your own objects. If you need to use a COM
component from another developer, you should obtain a Primary Interop
Assembly (PIA) from whoever authored the original object.

6. How do you call unmanaged methods from your .NET code through
PInvoke? Supply a DllImport attribute. Declare the methods in your .NET
code as static extern. Do not implement the methods as they are
implemented in your unmanaged code, you’re just providing declarations for
method signatures.

7. Can you retrieve complex data types like structs from the PInvoke
calls? Yes, just make sure you re-declare that struct, so that managed code
knows what to do with it.

8. I want to expose my .NET objects to COM objects. Is that possible?


Yes, but few things should be considered first. Classes should implement
interfaces explicitly. Managed types must be public. Methods, properties,
fields, and events that are exposed to COM must be public. Types must have
a public default constructor with no arguments to be activated from COM.
Types cannot be abstract.

9. Can you inherit a COM class in a .NET application? The .NET Framework
extends the COM model for reusability by adding implementation inheritance.
Managed types can derive directly or indirectly from a COM coclass; more
specifically, they can derive from the runtime callable wrapper generated by
the runtime. The derived type can expose all the method and properties of
the COM object as well as methods and properties implemented in managed
code. The resulting object is partly implemented in managed code and partly
implemented in unmanaged code.
10. Suppose I call a COM object from a .NET applicaiton, but COM object
throws an error. What happens on the .NET end? COM methods report
errors by returning HRESULTs; .NET methods report them by throwing
exceptions. The runtime handles the transition between the two. Each
exception class in the .NET Framework maps to an HRESULT.

COM/COM+ services and components in .NET

1. Explain transaction atomicity. We must ensure that the entire transaction


is either committed or rolled back.

2. Explain consistency. We must ensure that the system is always left at the
correct state in case of the failure or success of a transaction.

3. Explain integrity. Ensure data integrity by protecting concurrent


transactions from seeing or being adversely affected by each other’s partial
and uncommitted results.

4. Explain durability. Make sure that the system can return to its original state
in case of a failure.

5. Explain object pooling. With object pooling, COM+ creates objects and
keeps them in a pool, where they are ready to be used when the next client
makes a request. This improves the performance of a server application that
hosts the objects that are frequently used but are expensive to create.

6. Explain JIT activation. The objective of JIT activation is to minimize the


amount of time for which an object lives and consumes resources on the
server. With JIT activation, the client can hold a reference to an object on the
server for a long time, but the server creates the object only when the client
calls a method on the object. After the method call is completed, the object is
freed and its memory is reclaimed. JIT activation enables applications to scale
up as the number of users increases.

7. Explain role-based security. In the role-based security model, access to


parts of an application are granted or denied based on the role to which the
callers belong. A role defines which members of a Windows domain are
allowed to work with what components, methods, or interfaces.

8. Explain queued components. The queued components service enables you


to create components that can execute asynchronously or in disconnected
mode. Queued components ensure availability of a system even when one or
more sub-systems are temporarily unavailable. Consider a scenario where
salespeople take their laptop computers to the field and enter orders on the
go. Because they are in disconnected mode, these orders can be queued up in
a message queue. When salespeople connect back to the network, the orders
can be retrieved from the message queue and processed by the order
processing components on the server.
9. Explain loosely coupled events. Loosely coupled events enable an object
(publisher) to publish an event. Other objects (subscribers) can subscribe to
an event. COM+ does not require publishers or subscribers to know about
each other. Therefore, loosely coupled events greatly simplify the
programming model for distributed applications.

10. Define scalability. The application meets its requirement for efficiency even
if the number of users increases.

11. Define reliability. The application generates correct and consistent


information all the time.

12. Define availability. Users can depend on using the application when needed.

13. Define security. The application is never disrupted or compromised by the


efforts of malicious or ignorant users.

14. Define manageability. Deployment and maintenance of the application is as


efficient and painless as possible.

15. Which namespace do the classes, allowing you to support COM


functionality, are located? System.EnterpriseServices

16. How do you make a NET component talk to a COM component? To


enable the communication between COM and .NET components, the .NET
Framework generates a COM Callable Wrapper (CCW). The CCW enables
communication between the calling COM code and the managed code. It also
handles conversion between the data types, as well as other messages
between the COM types and the .NET types.

S-ar putea să vă placă și