Microsoft. NET Framework FAQ (2)

Source: Internet
Author: User
Tags ole

Microsoft. NET Framework FAQ (2)

(Www.jojoo.net) 2001-3-27 (double-click the automatic scrolling screen to watch it, click stop, and then click ..)

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 is a security exception occurring when running code in a network shared drive?
By default, the security policy only grants limited permissions to codes from the local Intranet region. This region is defined by Internet Explorer security settings and should be configured to match the local network in the enterprise. Because files named by UNC or ing drives (such as using the net use command) need to be sent over the local network, they are also in the Local intranet region.

The default value is set for the worst case of insecure intranet. If your intranet is secure, you can modify the Security Policy (using the caspol tool) and grant more permissions to the local Intranet or a part of it (such as a specific computer sharing name.

How do I write code so that it runs when the security system stops the code?
Security exceptions occur when the Code tries to perform unauthorized operations. Permissions are granted based on code (especially its location. For example, the permission for Running code on the internet is less than that for Running code on a local computer. This is because experience has proved that it is less reliable. Therefore, to run code that fails due to a security exception, you must grant it the permission. A simple method is to move the code to a more trusted location (such as a local file system ). However, this method is not always effective in any situation (web applications are a good example, and intranet applications on the enterprise network are another example ). Therefore, do not change the code location, but grant more permissions to the location by changing the security policy. Use the code access security policy tool (caspol.exe) or graphical management tool (available in Beta 2 and later versions) to perform this operation. If you are a code developer or publisher, you can also sign the Code, modify the Security Policy, and grant more permissions to the Code with the digital signature. However, when performing any of the preceding operations, remember that this code has been granted fewer permissions, it is because it is not from a trusted source-before moving code to a local computer or changing security policies, you should ensure that the Code does not perform malicious or corrupt operations.

How to manage the security of personal or enterprise computers?
Currently, the caspol command line tool is the only way to manage security. A security policy consists of two levels: by computer and by user. We plan to provide comprehensive management tools and enterprise policy management support in the first version of the. NET Framework.

How does evidence-based security work with Windows 2000 Security?
Evidence-based security (based on authorization code) can work with Windows 2000 Security (based on logon identity. For example, to access a file, the managed code must have the security file access permission for the code, and must also run under the login identity with the NTFS file access permission .. The role library included in the. NET Framework also provides classes for role-based security. These enable the application to work with the Windows logon identity and user group.

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.