Microsoft. NET Framework FAQ

Source: Internet
Author: User
Tags exception handling execution file system garbage collection new features ole web services file permissions
Issue Summary: This article contains frequently asked questions about Microsoft. NET and the Microsoft. NET Framework.

Directory
Conceptual issues
Run-time technical issues
Terms
Assembly
Application Deployment and Isolation
Garbage collection
Remote processing
Interoperability
Security

Conceptual issues
What is. NET?


What is a. NET framework?


Does the. NET framework apply only to users who create Web sites?


Where can I get the. NET Framework SDK?


Which platforms can the. NET framework run on?


What programming languages are supported by the. NET framework?


What is the relationship between the. NET Framework and COM + services?


What is the relationship between the. NET framework and DCOM?


is the. NET framework just the new name for Windows DNA?
Run-time technical issues
Terms
What is the common language runtime (CLR)?


What is the common type system (CTS)?


What is the common Language specification (CLS)?


What is Microsoft Intermediate language (MSIL)?


What is managed code and managed data?
Assembly
What is an assembly?


What are private assemblies and shared assemblies?


If I want to create a shared assembly, do I need additional overhead in tagging and managing key pairs?


What is the difference between a namespace and an assembly name?
Application Deployment and Isolation
What options can I use when deploying. NET applications?


If I have written an assembly and want to use it in multiple applications, where should I deploy it?


How can I see which assemblies are installed in the global assembly cache?


What is an application domain?
Garbage collection
What is garbage collection?


How does non-deterministic garbage collection affect code?


Is it possible to avoid using a heap that can be garbage collected?
Remote processing
How do I communicate between processes and processes within the common language runtime?
Interoperability
Can I use COM objects in the. NET Framework program?


Can I use the. NET framework components in a COM program?


Can I use the Win32 API in the. NET Framework program?
Security
How do I coordinate code with the security system?


Why is there a security exception when running code on a network shared drive?


How do you write code that runs when the security system stops the code?


How do I manage the security of personal or enterprise computers?


How is evidence-based security working with Windows 2000 security?
Conceptual issues
What is. NET?
Simply put, Microsoft®.net is a strategy for Microsoft to deliver software in a service manner. For complete information, see the White Paper on this topic.

The following is a summary of the white paper that briefly describes the key elements of. NET:

Microsoft. NET Platform
Includes the. NET infrastructure and tools for creating and manipulating the next generation of services, the. NET user experience for implementing a multiple-information client, and the. NET Building block service and. NET device software for enabling a new generation of smart Internet devices.


Microsoft. NET Products and Services
Includes microsoft®windows.net (its core integrates a set of building block services), Msn.net, personal subscription services, Microsoft®office.net, Microsoft®visual Studio.NET, and Microsoft®bcentral™for. NET.


Third-party. NET Services
Partners and developers in many areas have the opportunity to provide enterprise and vertical services on the. NET platform.
This issue is for the. NET Framework. The. NET Framework is part of the. NET platform infrastructure. For more information about the. NET framework, see the next question.

Back to the top of the page

What is a. NET framework?
The. NET framework is an environment for creating, deploying, and running WEB services and other applications. It consists of three main sections: the common language runtime, the framework class, and the asp.net.

Back to the top of the page

Does the. NET framework apply only to users who create Web sites?
The. NET Framework enables you to create excellent WEB applications. But it can also help you create a variety of applications today. Compared to the way the application is currently created,. NET has a greater advantage in writing any Windows software (using atl/com, MFC, microsoft®visual basic®, or Standard microsoft®win32®). Of course, if you are developing a Web site, starting with asp.net, you will feel the power of the. NET Framework.

Back to the top of the page

Where can I get the. NET Framework SDK?
You can now download the Beta 1 version of the. NET framework SDK from the MSDN Online Downloads (English). Given its size, we offer this beta release in a variety of ways: as a download file (in MB), as a 11-part download, or to order its CDs from the Microsoft Developer Store:

United States/Canada (English)


International (English)
Back to the top of the page

Which platforms can the. NET framework run on?
Beta version 1 can run on microsoft®windows®2000, Windows 95/98/me, and Windows nt®4.0.

In addition, there is a. NET Framework version called the. NET Compact Framework. It is used to make devices such as cellular phones and enhanced televisions also have some features of the. NET Framework. The. NET Compact Framework will run on Windows CE and other embedded operating systems.

Back to the top of the page

What programming languages are supported by the. NET framework?
The. NET Framework is independent of the programming language. In fact, any language can support the. NET Framework. Currently, you can create. NET programs in many languages, including the latest language--c# for C + +, Microsoft®visual Basic.NET, jscript®, and Microsoft. Later, there will also be a large number of Third-party languages that can be used to create. NET framework applications, including COBOL, Eiffel, Perl, Python, Smalltalk, and so on.

Back to the top of the page

What is the relationship between the. NET Framework and COM + services?
In the. NET framework, not only do you have full access to COM + services, but it is also easier to create service components.

The. NET framework component can be added to a COM + application. In COM + applications,. NET Framework components can take advantage of automated Component Services, such as transactions, object pooling, queued components, events, and so on.

Back to the top of the page

What is the relationship between the. NET framework and DCOM?
DCOM is a COM infrastructure for interprocess communication. The. NET Framework supports a large number of pluggable channels and formatters for interprocess communication. When converting between managed and unmanaged code, the. NET Framework uses the COM infrastructure, especially DCOM. All scenarios using COM + services use managed to unmanaged transformations, so DCOM is used by default. The. NET Framework also supports SOAP (Simple Object Access Protocol) for interprocess communication that focuses on interoperability.

Back to the top of the page

is the. NET framework just the new name for Windows DNA?
No. Windows DNA is an architecture for creating tightly coupled distributed Web applications. Because distributed applications are becoming more loosely coupled, Microsoft has developed the architecture in. NET Frameworks. The. NET Framework is part of the. NET architecture.

Back to the top of the page

Run-time technical issues
Terms
What is the common language runtime (CLR)?
The common language runtime is the execution engine for the. NET Framework application.

It offers a number of services, including:

Code management (load and execute)


Application Memory Isolation


Type-safe authentication


IL to native code conversion


Meta-data (enhanced type information) access


Managing memory for Managed objects


Enforcing Code access security


Exception handling, including cross language exceptions


Interoperability between managed code, COM objects, and existing DLLs (unmanaged code and data)


Auto-layout of objects


Support for developer Services (configuration, debugging, etc.)
Back to the top of the page

What is the common type system (CTS)?
A common type system is a multiple-information type system that is built into the common language runtime to support types and operations in most programming languages. The common type system supports the full implementation of a large number of programming languages.

Back to the top of the page

What is the common Language specification (CLS)?
The common language specification is a set of structures and constraints that serve as a guide for library writers and compiler authors. It makes it possible for any language that supports the CLS to fully use the library, and makes these languages integrated with one another. The common language specification is a subset of the common type System. The common language specification is also important for application developers who need to write code for use by other developers. Developers who follow CLS rules to design public access APIs can easily use these APIs in any other programming language that supports the common language runtime.

Back to the top of the page

What is Microsoft Intermediate language (MSIL)?
MSIL is a CPU-independent instruction set. The. NET Framework program is compiled into MSIL. It contains instructions for loading, storing, initializing, and invoking object methods.

Combined with metadata and common type systems, MSIL allows true cross-language integration.

The MSIL is converted to machine code before execution, not as it is interpreted while executing.

Back to the top of the page

What is managed code and managed data?
Managed code is code that is written to support the common language runtime services (see "What is the common language runtime?"). ”)。 To support these services, the code must provide the minimum level of information (metadata) to the runtime. By default, all C #, Visual Basic.NET, and JScript.NET code are managed code. Visual Studio.NET C + + code is not managed code by default, but the compiler can also generate managed code by specifying a command-line switch (/clr).

Closely related to managed code is managed data. Managed data is data that is allocated and released by the common language runtime's garbage collector. By default, C #, Visual Basic, and JScript.NET data are managed data. However, by using special keywords, C # data can be marked as unmanaged data. Visual Studio.NET C + + data is unmanaged data by default (even when the/clr switch is used), but when using Managed Extensions for C + +, you can use the "__gc" keyword to mark a class as a managed class. As the name suggests, it indicates that the memory of the class instance is managed by the garbage collector. In addition, the class is fully a member of the. NET framework, along with the benefits and limitations it brings. An example of the benefit is that it can interoperate correctly with classes written in other languages (such as managed C + + classes can inherit from the Visual Basic Class); one example of a constraint is that a managed class can inherit only from one base class.

Back to the top of the page

Assembly
What is an assembly?
An assembly is the main building block of a. NET Framework application. It is a collection of features that are created, identified, and deployed as a single implementation unit (containing one or more files). All managed types and resources can be marked for access only within their implementation units, or are marked as accessible by code outside the cell.

Assemblies are used to illustrate themselves by listing. Checklists are an integral part of each assembly. Listing:

Establishes an assembly identity (in the form of a text name), version, category, and digital signature (if you want to share the assembly between applications).


Defines the files that make up an assembly implementation (hash by name and file).


Specifies the types and resources that make up the assembly, including which are exported from the assembly.


Records the dependencies of other assemblies at compile time.


Specifies the set of permissions that the assembly needs to run correctly.
This information is used at run time to resolve references, enforce version binding policies, and verify the integrity of the assemblies that are loaded. Because each type is loaded into the context of the Assembly, the runtime can determine and locate the assembly of any running object. Assemblies are also units that have code access security permissions applied to them. The identity evidence for each assembly is considered independent when determining what permissions are granted to the code it contains.

The self-explanatory features of the Assembly also contribute to the implementation of no impact installations and XCOPY deployments.

Back to the top of the page

What are private assemblies and shared assemblies?
A private assembly is used only by a single application and is stored in the installation directory of that application (or in its subdirectories). A shared assembly is an assembly that can be referenced by multiple applications. To share an assembly, the Assembly must be explicitly created for this purpose, which can be achieved by assigning it an enhanced name for encryption, which is used as the share name. Instead, the private assembly name requires only that it be unique in the application in which it is used.

By distinguishing between dedicated and shared assemblies, we introduce the key points for explicitly deciding on sharing. Simply deploying a private assembly in the application directory ensures that the application runs only in the part where it is created and deployed. References to private assemblies are parsed only within the private application directory.

There are several reasons to choose to create and use shared assemblies, such as the ability to express version policies. The fact that the shared Assembly has an encrypted, enhanced name means that only the author of the Assembly has the key to generate a new version of the assembly. Therefore, if you make a policy statement and you want to accept a new version of the assembly, you can be confident that the version update will be controlled and validated by the author. Otherwise, you will not accept them.

For applications installed locally, shared assemblies are typically explicitly installed in the global assembly cache (the local cache of the assembly is maintained by the. NET Framework). The key to the version management features of the. NET Framework is that the downloaded code does not affect the execution of locally installed applications. The downloaded code is placed in a special download cache, and even if some of the download components are compiled into shared assemblies, the code cannot be used globally on the machine.

Classes that are published with the. NET framework are compiled into shared assemblies.

Back to the top of the page

If I want to create a shared assembly, do I need additional overhead in tagging and managing key pairs?
Creating a shared assembly does involve work on encryption keys. When you create an assembly, only the public key is necessary. Compilers that support the. NET Framework provide command-line options (or use custom attributes) to provide a public key when the assembly is created. Typically, a common public key is kept in the resource database and the compilation script points to the key. Before the assembly is published, it must be fully marked with the appropriate private key. This is done through the SDK tool SN.exe (enhanced name).

Enhanced name tags do not require the use of certificates as Authenticode. It does not involve third-party organizations, does not require payment, and is not subject to certificate constraints. Additionally, the extra overhead of validating an enhanced name is much less than the cost of validating Authenticode. However, an enhanced name does not generate any statements that trust a publisher. Enhanced names allow you to be sure that the contents of a given assembly are not tampered with, and that the assembly that you load at run time comes from the publisher that you are developing against. However, it does not generate statements about whether to trust publisher identity.

Back to the top of the page

What is the difference between a namespace and an assembly name?
Namespaces are a logical naming scheme for types in which a simple type name, such as MyType, is preceded by a point-delimited hierarchy name. Such a naming scheme is entirely under the control of the developer. For example, typing MYCOMPANY.FILEACCESS.A and mycompany.fileaccess.b will logically have functionality related to file access. The. NET framework uses a hierarchical naming scheme for grouping types into logical categories of related functionality, such as , asp.net application framework or remoting capabilities. The design tool can take advantage of 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 types whose hierarchy names have different namespace roots, and a logical namespace root can span multiple assemblies. In the. NET framework, namespaces are a convenient way to make logical naming at design time, and assemblies establish name scopes for types at run time.

Back to the top of the page

Application Deployment and Isolation
What options can I use when deploying. NET applications?
The. NET framework simplifies deployment by making it possible for applications to have no impact installation and XCOPY deployment. Because all requests are first parsed in the private application directory, you can run the application without registering by simply copying the directory file of an application to disk.

This scenario is particularly appealing for Web applications, Web services, and stand-alone desktop applications. In some scenarios, however, XCOPY is not sufficient to serve as a distribution mechanism. For example, when an application has very little specialized code, it relies on the shared assembly that is available, or the application is not installed locally (but on demand). For these cases, the. NET Framework provides extended code download services and integration with Windows Installer. The. NET Framework provides code download support that offers many advantages through the current platform, including incremental downloads, code access security (No more "Authenticode" dialog box) and application isolation (code downloaded for one application does not affect other applications). Windows Installer is another powerful deployment mechanism that a. NET application can use. In Windows Installer 1.5, all the features of Windows Installer, including publishing, publishing, and application patching, can be used in. NET applications.

Back to the top of the page

If I have written an assembly and want to use it in multiple applications, where should I deploy it?
Assemblies that are to be used by multiple applications, such as shared assemblies, need to be deployed into the global assembly cache. In pre-release and beta releases, use the/I option of the Alink SDK tool to install assemblies into the cache:

Al/i:mydll.dll
Subsequent versions of Windows Installer can install assemblies into the global assembly cache.

Back to the top of the page

How can I see which assemblies are installed in the global assembly cache?
The. NET framework comes with a Windows shell extension that is used to view the assembly cache. In Windows Explorer, go to% windir%\assembly to activate the viewer.

Back to the top of the page

What is an application domain?
application domains (usually AppDomain) are virtual processes that are used to isolate applications. All objects created in the same application scope (in other words, starting from the entry point of the application, anywhere along 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.

The operating system process provides isolation by using different memory address spaces. Although it is effective, it is costly and does not meet the required number of large WEB servers. Instead, the common language runtime enforces application isolation by managing the memory usage of code running in an application domain. This ensures that it does not access memory outside the application domain. It should be noted that only type-safe code can be managed this way (when unsafe code is loaded in an application domain, the runtime cannot guarantee isolation).

Back to the top of the page

Garbage collection
What is garbage collection?
Garbage collection is a mechanism that enables a computer to detect when an object can no longer be accessed. It automatically frees the memory that is used by the object (also calls the cleanup routines that the user writes called "End"). Some garbage collector, such as used by. NET, compresses memory and therefore reduces the working set of the program.

Back to the top of the page

How does non-deterministic garbage collection affect code?
For most programmers, owning a garbage collector (and using objects that can be garbage collected) means never having to worry about freeing memory or reference counting objects, even if you use complex data structures. However, if you typically release system resources (file handles, locks, and so on) in the same block of code that frees object memory, you need to make some changes to the encoding style. When using objects that can be garbage collected, you should provide a way to explicitly free system resources (that is, your program control) while allowing the garbage collector to free up memory when the working set is compressed.

Back to the top of the page

Is it possible to avoid using a heap that can be garbage collected?
All languages that support the runtime allow you to assign class objects from a heap that can be garbage collected. This brings benefits in terms of rapid allocation, and allows programmers to calculate when each object should be explicitly "free" without themselves.

The CLR also provides ValueTypes objects-similar to classes, but ValueType objects are allocated in the Run-time stack (not the heap), so they are automatically reclaimed when your code exits the process that defines those objects. This is the "struct" mode of operation in C #.

Managed Extensions for C + + enable you to select where the class object is allocated. If declared as managed by using the __gc keyword, they will be allocated from a heap that can be garbage collected, and if they do not contain __gc keywords, they will be allocated from the C + + heap as normal C + + objects and explicitly released using the free method.

For more information about garbage collection, see:

Garbage collection: Automatic memory management in the Microsoft. NET Framework (English)


Garbage Collection-Part 2nd: Automatic memory management in the Microsoft. NET Framework (English)
Back to the top of the page

Remote processing
How do I communicate between processes and processes within the common language runtime?
There are two kinds of in-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 involving marshaling/serialization. When crossing application domains, use runtime binary protocols for marshaling/serialization.

interprocess communication uses a pluggable channel and formatter 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 perform explicit remoting in the managed world, you need to explicitly specify which channels and formatters to use. This can be represented by a configuration file in a manageable way, or by using API calls to load a specific channel. The options are as follows:
HTTP channel with SOAP formatter (HTTP is running well on the Internet or whenever it has to communicate through a firewall)

TCP channel with binary formatter (TCP is a high performance option for LAN)

SMTP Channel with SOAP formatter (meaning only for cross computers)

When converting between managed and unmanaged code, the COM infrastructure (especially DCOM) is used for remoting. In the intermediate version of the CLR, this also applies to service components (components that use COM + services). In the final release, it is possible to configure any remote components.

Distributed garbage collection for objects is managed by a system called lease lifetime. Each object has a lease time, and when it expires, the object is disconnected from the CLR's remoting infrastructure. Object has a default update time-the lease is updated when the client successfully invokes the object. The client can update the lease explicitly.

Back to the top of the page

Interoperability
Can I use COM objects in the. NET Framework program?
Is. Any COM component that you are deploying now can be used in managed code. Normally, the required adjustments are made entirely automatically.

In particular, you can use the Run-time callable Wrapper (RCW) to access COM components from the. NET framework. This wrapper converts COM interfaces provided by COM components to interfaces that are compatible with the. NET Framework. For OLE Automation interfaces, the RCW can be automatically generated from the type library, and for non-OLE automation interfaces, developers can write custom RCW that manually map the type provided by the COM interface to a type that is compatible with the. NET Framework.

Back to the top of the page

Can I use the. NET framework components in a COM program?
Is. The managed type you are creating now can be accessed through COM. Typically, the desired configuration is completely automated. Some of the new features of the managed development environment cannot be accessed in COM. For example, you cannot use static methods and parameterized constructors in COM. In general, it is a good idea to determine the user in advance for a given type. If the type needs to be used in COM, you will be limited to using COM-accessible attributes.

By default, managed types may or may not be visible, as determined by the language used to write managed types.

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

Back to the top of the page

Can I use the Win32 API in the. NET Framework program?
Is. The P/invoke,.net Framework program allows you to access the native code base by means of a 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);
}
}
Back to the top of the page

Security
How do I coordinate code with the security system?
Typically, this is not a problem-most applications run safely and are not interfered with by malicious attacks. Security is enforced by simply using standard class libraries to access resources, such as files, or by performing protected actions, such as inverting private members of a type. One of the simple tasks that an application developer needs to accomplish is to include a permission request (a public security) that restricts the permissions that the code might receive to the permissions it needs. This also ensures that if the code is allowed to run, it will have all the permissions it needs at run time.

Only when developers need to write new base class libraries that provide new types of resources do they need to deal directly with security systems. In this case, not all code has a potential security problem, and the code access security mechanism restricts it to the part of the code that replaces the security system.

Back to the top of the page

Why is there a security exception when running code on a network shared drive?
The default security policy grants limited permissions only to code from the local Intranet zone. This area is defined by Internet Explorer security settings and should be configured to match the local network within the enterprise. Because files named by UNC or mapped drives, such as the NET Use command, are required to be sent on the local network, they are also in the local Intranet zone.

The default value is set for the worst case scenario for an insecure Intranet. If your intranet is more secure, you can modify the security policy (with the CASPol tool) to grant additional permissions to the local intranet or some of its parts, such as a specific computer share name.

Back to the top of the page

How do you write code that runs when the security system stops the code?
A security exception occurs when the code attempts to perform an unauthorized operation. Permissions are granted based on the code, especially its location. For example, code that runs from the Internet has less permissions than code that runs on the local computer, because experience has shown that it has a lower reliability. Therefore, to run code that failed because of a security exception, you must increase the permissions granted to it. An easy way is to move your code to a more trusted location, such as a local file system. But this approach is not effective in any case (a good example of a WEB application is another example of an Intranet application on a corporate network). Therefore, do not change the location of the code, but instead grant more permissions to the location by changing the security policy. Do this using the Code Access Security Policy Tool (Caspol.exe) or the graphical management tool (available in Beta 2 and later). If you are a developer or publisher of code, you can also digitally sign it, and then modify the security policy to grant more permissions to code with that digital signature. However, when you do any of these things, keep in mind that this code is granted fewer permissions because it is not from a trusted source-you should make sure that the code does not perform malicious or damaging actions until you move the code to the local computer or change the security policy.

Back to the top of the page

How do I manage the security of personal or enterprise computers?
Currently, the CASPol command-line tool is the only way to manage security. The 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 edition of the. NET Framework.

Back to the top of the page

How is evidence-based security working with Windows 2000 security?
Evidence-based security, based on authorization codes, works with Windows 2000 security, which is based on a login identity. For example, to access a file, managed code must have code access security file permissions and must run under a login identity with NTFS file access. The managed libraries included in the. NET Framework also provide classes for role-based security. These enable applications to work with Windows logon identities and user groups.


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.