Microsoft. NET Framework FAQ (2)

Source: Internet
Author: User

What is the difference between the namespace and the Assembly name?
A namespace is a type logical naming scheme. A simple type name (such as MyType) is preceded by a hierarchical name separated by points. Such a naming scheme is completely under the control of developers. For example, if you type MyCompany. FileAccess. A and MyCompany. FileAccess. B, you will logically have file access-related functions .. The. NET Framework uses a hierarchical naming scheme to group types by logical category of related functions, such as ASP. NET application framework or remote processing. The design tool can use namespaces to make it easier for developers to browse and reference types in code. There is no connection between the concept of a namespace and the concept of an assembly. An assembly can contain the types of its hierarchical structure names with different namespaces, while a logical namespace root can span multiple assemblies. In the. NET Framework, a namespace is a convenient way to perform logical naming during design, while an Assembly creates a name scope for the type at runtime.

Application Deployment and isolation
What options can be used to deploy. NET applications?
The. NET framework simplifies the deployment by making installation and XCOPY deployment of applications unaffected. Because all requests are first parsed in the dedicated application directory, you only need to copy the directory file of an application to the disk to run the application without registration.

This solution is particularly attractive to Web applications, Web Services, and independent desktop applications. However, in some scenarios, XCOPY is not enough to serve as a distribution mechanism. For example, when an application has very little dedicated code and relies on available shared assembly, or the application is not installed locally (but downloaded on demand ). In these cases, the. NET Framework provides extended code download services and integration with Windows Installer .. NET Framework provides code download support through the current platform provides many advantages, including incremental download, code access security (there is no "Authenticode" dialog box) isolated from applications (the code downloaded for an application does not affect other applications ). Windows Installer is another powerful deployment mechanism that can be used by. NET applications. In Windows Installer 1.5, all features of Windows Installer (including release, publish, and application patching) can be used in. NET applications.

If I have compiled an assembly and want to use it in multiple applications, where should I deploy it?
The assembly to be used by multiple applications (such as shared assembly) needs to be deployed to the global assembly cache. In pre-release and Beta versions, use the/I option of the Alink SDK tool to install the Assembly into the cache:

Al/I: myDll. dll
Later versions of Windows Installer can install the Assembly into the global assembly cache.

How can I see which assembly is installed in the global assembly cache?
The. NET Framework comes with a Windows Shell extension used to view the Assembly Cache. In Windows Resource Manager, go to % windir % assembly to activate the viewer.

What is an application domain?
An application domain (usually AppDomain) is a virtual process used to isolate an application. All objects created in the same application scope (in other words, from the entry point of the application to any place in the object activation sequence) are created in the same application domain. Multiple application domains can exist in an operating system process, making them an easy way to isolate applications.

Operating system processes are isolated by using different memory address spaces. Although it is effective, it is expensive and cannot meet the needs of large Web servers. In contrast, when running in a common language, application isolation is enforced by managing the memory usage of the code running in the application domain. This ensures that it does not access the memory outside the application domain. Note that only type-safe code can be managed in this way (runtime isolation cannot be guaranteed when Insecure code is loaded in the application domain ).

Garbage Collection
What is garbage collection?
Garbage collection is a mechanism that enables computers to detect when an object is no longer accessible. It will automatically release the memory used by the object (also called the "Terminator" cleaning routine written by the user ). Some garbage collectors (such as those used by. NET) compress the memory and reduce the working sets of the program.

How does uncertain garbage collection affect code?
For most programmers, having a garbage collector (and using objects that can be recycled as garbage) means never having to worry about releasing memory or referencing counting objects, even if you use a complex data structure. However, if you usually release system resources (file handles, locks, and so on) in the same code block used to release the object memory, you need to modify the encoding style. When using garbage collection objects, you should provide a method to explicitly release system resources (that is, controlled by your program ), meanwhile, the garbage collector is allowed to release memory when compressing the working set.

Can I avoid using a heap that can be used as garbage collection?
All runtime languages allow you to allocate class objects from the heap that can be used as garbage collection. This brings benefits in fast allocation, and allows programmers not to calculate when to explicitly "free" each object on their own.

CLR also provides ValueTypes objects-they are similar to classes, but ValueType objects are allocated in the runtime stack (not heap, therefore, when your code exits the process of defining these objects, it will be automatically recycled. This is the "struct" operation method in C.

The hosting extension of C ++ allows you to select the Class Object allocation location. If the _ gc keyword is declared as a Managed class, they are allocated from the heap that can be used as garbage collection; if they do not contain the _ gc keyword, they will be allocated from the C ++ heap like normal C ++ objects, and are explicitly released using the "free" method.

For more information about garbage collection, see:

Garbage Collection: Automatic Memory Management in the Microsoft. NET Framework)


Garbage collection-Part 1: Automatic Memory Management in the Microsoft. NET Framework)

Remote Processing
How can we conduct intra-process and inter-process communication in the public language runtime?
There are two types of intra-process communication: in the context of a single application domain, or across application domains. In the context of the same application domain, the proxy is used as the listening mechanism, without sending/serializing packets. When cross-application domains are used, the runtime binary protocol is used for sending, processing, and serialization.

Inter-process communication uses a pluggable channel and formatting protocol for each specific purpose.

If a developer uses the soapsuds.exe tool to specify an endpoint to generate a metadata proxy, the default value is the HTTP channel with the SOAP formatter.


If developers execute explicit remote processing in the hosted world, you need to specify the channel and formatting program to use. This can be represented by a configuration file in a manageable way, or by calling an API to load a specific channel. The options are as follows:
HTTP channel with SOAP formatting Program (HTTP runs well on the Internet or any communication that must be performed through the firewall)

TCP channel with binary formatting (for LAN, TCP is an option with High Performance)

SMTP channel with SOAP formatting Program (valid only for cross-computer)

The COM infrastructure (especially DCOM) is used for remote processing when the hosted and unmanaged code are converted. In the intermediate version of CLR, this applies to service components (components using COM + services ). In the final version, it is possible to configure any remote components.

The distributed garbage collection of objects is managed by a system named "lease lifetime. Each object has a lease time. When it expires, the object is disconnected from the CLR remote processing infrastructure. The object has a default Update time. When the client successfully calls the object, the lease is updated. The client can explicitly update the lease.

Interoperability
Can I use COM objects in. NET Framework programs?
Yes. Any COM component you deploy now can be used in managed code. Generally, the necessary adjustments are completely automatic.

In particular, you can use runtime callable packaging (RCW) to access COM components from the. NET Framework. This package converts the COM interface provided by the COM component to an interface compatible with the. NET Framework. For OLE Automation interfaces, RCW can be automatically generated from the Type Library; for non-OLE Automation interfaces, developers can write custom RCW and manually map the types provided by the COM interface.. NET Framework compatible type.

Can I use the. NET Framework component in a COM program?
Yes. All the managed types you create can be accessed through COM. Generally, the configuration is completely automatic. Some new features of the managed development environment cannot be accessed in COM. For example, static methods and parameterized constructors cannot be used in COM. Generally, it is a good way to determine the users for a given type in advance. If the type needs to be used in COM, you will be restricted in using the accessible features of COM.

By default, the managed type may be visible or invisible, which is determined by the language used to write the managed type.

In particular, you can use COM callable packaging (CCW) to access. NET Framework components from COM. This is similar to RCW (see the previous issue), but they are in the opposite direction. Similarly, if the. NET Framework development tool cannot automatically generate packaging, or if the automatic method is not what you need, you can develop a custom CCW.

Can Win32 APIs be used in. NET Framework programs?
Yes. With P/Invoke, the. NET Framework Program can access the local code library through the static DLL entry point.

The following is an example of C # calling the Win32 MessageBox function:

Using System;
Using System. Runtime. InteropServices;

Class MainApp
{
[DllImport ("user32.dll", EntryPoint = "MessageBox")]
Public static extern int MessageBox (int hWnd, String strMessage, String strCaption, uint uiType );

Public static void Main ()
{
MessageBox (0, "Hello, this is PInvoke! ",". NET ", 0 );
}
}

Security
How can I coordinate code with the security system?
Generally, this is not a problem-most applications can run securely without being disturbed by malicious attacks. By simply using standard class libraries to access resources (such as files) or performing protected operations (such as reverse type private members), security is implemented by these libraries. One simple task that an application developer needs to do is to include permission requests (a public security) and restrict the permissions that the Code may receive to the permissions it requires. This also ensures that if the code is allowed to run, it will have all the required permissions at runtime.

Only when developers need to write new base class libraries that provide new resources, they need to directly process the security system. In this case, not all codes have potential security issues. The code access security mechanism limits them to the part of the Code that replaces the security system.

Why in the Network

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.