Microsoft .NET framework is common problem

zhaozj2021-02-11  175

Conceptual problem

What is .NET?

Simply put, Microsoft® .NET is a policy that Microsoft submits software in a service manner. For complete information, see White Paper on this topic (English).

The following is a summary of the white paper, briefly introduce the key content of .NET:

Microsoft .NET platforms include .NET infrastructure and tools for creating and operating a new generation of services, for implementing multi-information clients .NET user experience, and .NET construction block services for enabling a new generation of smart Internet devices. NET device software. Microsoft .NET products and services include Microsoft® Windows.net (its core integration a set of construction block services), MSN.NET, personal subscription service, Microsoft® Office.Net, Microsoft® Visual Studio.NET, and Microsoft® BcentralTM for .NET. Third-party .NET services Many partners and developers have the opportunity to provide companies and vertical services on the .NET platform.

This issue is for .NET framework. The .NET framework is part of the .NET platform infrastructure. See the next question for more information on the .NET framework.

Back to top

What is .NET framework?

The .NET framework is an environment created, deployed, and running web services and other applications. It consists of three main parts: time, framework and ASP.NET.

Back to top

Is the .NET framework only applies to the user who creates a Web site?

The .NET Framework allows you to create an excellent web application. But it can also help you create a variety of applications. 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 from ASP.NET, you will feel the powerful attraction of the .NET framework.

Back to top

Where can I get the .NET framework SDK?

You can now download the Beta 1 version of the .NET Framework SDK from MSDN Online Downloads (English). In view of its size, we offer this Beta version in a variety of ways: as a download file (106 MB), divided into 11 sections, or order its CD from the Microsoft Developer Store:

USA / Canada (English) International (English)

Back to top

Which platforms can the .NET framework run?

The Beta 1 version can run on Microsoft® Windows® 2000, Windows 95/98 / ME, and Windows NT® 4.0.

In addition, there is a .NET framework called .NET streamlined frame. It is used to make cellular phones and enhanced televisions and other features of the .NET framework. The .NET streamlined frame will run on a Windows CE and other embedded operating systems.

Back to top

What programming languages ​​supported by .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, including: C , Microsoft® Visual Basic.NET, JScript®, and Microsoft's latest language - C #. There will be a large number of third-party languages ​​can be used to create .NET framework applications, including Cobol, Eiffel, Perl, Python, SmallTalk, and more. Back to top

What is the relationship between .NET framework and COM services?

In the .NET framework, not only you can access the COM service, but also easier to create service components.

The .NET Framework component can be added to the COM application. In the COM application, .NET Framework components can utilize automatic component services, such as transactions, object pools, queuing components, events, and more.

Back to top

What is the relationship between .NET framework and DCOM?

DCOM is a COM infrastructure for inter-process communication. The .NET Framework supports a large number of plug-in channels and formatting programs for inter-process communication. When converting between managed code and non-hosting code, the .NET framework uses a COM infrastructure, especially DCOM. All schemes that use COM services use managed to unmanaged conversion, so DCOM is used by default. For inter-interoperability communication, .NET framework also supports SOAP (Simple Object Access Protocol).

Back to top

Is the .NET framework is just a new name for Windows DNA?

Do not. Windows DNA is an architecture for creating a tightly coupled distributed web applications. Since distributed applications require more loose coupling principle, Microsoft has developed the architecture in .NET. The .NET frame is part of the .NET architecture.

Back to top

Runtime technical problem

the term

What is the public language runtime (CLR)?

The public language is running the .NET Framework application execution engine.

It provides a number of services, including:

Code Management (Loading and Execution) Application Inscription Isolation Type Security Validation IL to Native Code Converter Transformation Data (Enhanced Type Information) Access to managed object management memory enforce code Access security exception handling, including cross-language exception hosted code, COM Interoperability between objects and existing DLLs (non-hosting code and data) Automatic object layout supports developer service (configuration, commissioning, etc.)

Back to top

What is a public type system (CTS)?

The public type system is a multi-information type system, which is built into public language runtime, supports the types and operations in most programming languages. Public Type Systems support a full implementation of a large number of programming languages.

Back to top

What is the Public Language Normative (CLS)?

Public language norms are a set of structures and restrictions, used as a guide to library writers and compiler. It makes any language that supports CLS fully uses the library, and these languages ​​can be integrated with each other. The public language norm is a subset of public types. For applications developers who need to write code for other developers, the public language specification is also very important. If developers follow CLS rules to design public access API, you can easily use these APIs in any other programming language that supports the runtime of public language.

Back to top

What is Microsoft Intermediate Language (MSIL)?

MSIL is an instruction set that is not related to the CPU. The .NET framework program is compiled into MSIL. It contains instructions that load, store, initialize, and call the object method.

Combined with metadata and public types, MSIL allows real cross-language integration.

MSIL is converted to machine code before execution instead of explaining one side. Back to top

What is managed code and managed data?

The hosting code is written as code to support the public language runtime service (see "What is the public language runtime?"). In order to support these services, the code must provide minimum level 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 hosting code by default, but by specifying a command line switch (/ CLR), the compiler can also generate a managed code.

It is closely related to the hosted code. The hosted data is data that is allocated and released by the garbage collector during the public language. By default, C #, Visual Basic and JScript.net data are managed data. However, by using a special keyword, C # data can be marked as unmanaged data. Visual Studio.NET C data is non-managed data by default (even when using the / CLR switch), but when using C hosted, you can use the "__gc" key to mark the class as a hosted class. As is shown in the name, it represents the memory of the class instance by garbage collector. In addition, this class is also a member of the .NET framework, and has the benefits and restrictions thereof. An example of the benefit is that it can correct interoperability with the classes written in other languages ​​(such as inheriting from Visual Basic class); one example of the restriction is: The hosted class can only be inherited from one base class.

Back to top

Assembly

What is the assembly?

The assembly is the main construction block of the .NET framework application. It is a single implementation unit (including one or more files) to create, identify, and deployment. All managed types and resources can be marked as accessible only within its actual unit, or marked as a code that can be enabled by the unit.

The assembly is self-description by a list. The list is an indispensable component of each assembly. List:

Establish an assembly ID (in the format of the text name), version, category, and digital signature (if you want to share the assembly between the application). Define files that make up the assembly implementation (through name and file hashing). Specify the type and resources of the set assembly, including which are exported from the program. Record the dependency of other assemblies by recording compile. Specifies the collection of permissions required to run the assembly correctly.

This information is used to resolve reference, enforce version binding strategies, and the integrity of the assembly loaded loaded. Because each type is loaded into the context of the assembly, you can determine and locate the assembly of any running objects when runtime. The assembly is also a unit that applies code access security privileges. When determining which privileges are granted, the identification evidence of each assembly is considered to be independent.

The self-description feature of the assembly also helps achieve no impact installation and XCOPY deployment.

Back to top

What is a special assembly and shared assembly?

The dedicated assembly is only used by a single application and stored in the installation directory of the application (or in its subdirectory). The shared assembly is a set of assemblies that can be referenced by multiple applications. To share an assembly, the assembly must be created for this purpose, which can be implemented by assigning an encrypted reinforced name (used as a shared name). Conversely, the dedicated assembly name only requires unique in the application that uses it.

By distinguishing between dedicated and sharing assemblies, we introduce the key points that clearly determine the sharing. Simply simply deploy the private assembly in the application directory, make sure the application is only running in that section created and deployed. References to private apps are only parsed within the dedicated application directory. Selecting to create and use shared assemblies for a variety of reasons, such as the ability to express version strategies. The shared assembly has an encrypted enhanced name, which means that only the author set has a key to generate a new version of the assembly. Therefore, if you make a policy declaration, you want to accept the new version of the assembly, you can confirm that the version update will be controlled and verified by the author. Otherwise, you will not accept them.

For applications installed locally, shared assemblies are often explicitly installed in the global program cache (the local cache of the assembly is maintained by .NET framework). The key to the version of the .NET framework is the key to the downloaded code does not affect the execution of the application where the local installation is. The downloaded code is placed in a special download cache, even if some download components are compiled into shared assemblies, they cannot use these code on the machine.

The classes published with the .NET framework are compiled into a shared assembly.

Back to top

If I want to create a shared assembly, do you need additional overhead in terms of tag and management key?

Creating a shared assembly does involve work in encryption keys. When you create an assembly, only the public key is necessary. Support the compiler of the .NET framework to provide command line options (or use custom properties) to provide public keys when creating an assembly. A commonly used public key is typically retained in the resource database, and the compilation script points to this key. Before the publish assembly, you must use the appropriate private key to fully mark it. This is done by the SDK tool sn.exe (enhanced name).

The enhanced name tag is not like Authenticode. It does not involve a third party organization, does not need to pay, and is not subject to certificate. In addition, the extra overhead of the enhanced name is much smaller than the cost of verifying Authenticode. However, the enhanced name does not generate any statement trust a publisher. The enhanced name allows you to confirm that the content of the given assembly is not tampered, the assembly that is loaded at runtime comes from the publisher of your development. But it does not generate a statement about whether to trust the identity of the publisher.

Back to top

What is the difference between the namespace and assembly name?

Namespace is a logical naming scheme of the type, where simple type names (such as MyType) have a hierarchy name separated by point. Such a naming scheme is completely under the control of the developer. For example, type mycompany.fileAccess.a and mycompany.fileAccess.b will have functions that are logically accessible to file access. The .NET framework uses a hierarchical naming scheme to group the type by the logical category of the relevant function, for example, an ASP.NET application framework or remote processing. Design tools can make developers easier to browse and reference types in your code. There is no connection between the concept of name space and the concept of the assembly. A assembly can include the type of its hierarchical name has different namespace roots, and a logical namespace root can span multiple assemblies. In the .NET framework, the namespace is a convenient way to logically naming during design, and the assembly establishes a name roof in the runtime.

Back to top

Application deployment and isolation

Which options can I use when deploying .NET applications?

The .NET framework simplifies deployment by making the application's non-affected installation and XCOPY deployment. Because all requests are first parsed in the dedicated application directory, just simply copy the directory files of an application to the disk, you can run the application without requiring registration.

This solution is particularly attractive for web applications, web services, and separate desktop applications. However, in some scenarios, Xcopy is not enough to take the distribution mechanism. For example, when the application has few special code, depending on the available shared assembly; or the application is not installed locally (but downloaded on demand). For these cases, the .NET framework provides an extended code download service and integration with Windows Installer. The code download support provided by the .NET framework provides many advantages through the current platform, including incremental downloads, code access security (no longer "Authenticode" dialog box) and application isolation (code downloaded for an application does not affect Other applications). Windows Installer is another powerful deployment mechanism that .NET application can use. In Windows Installer 1.5, all features of Windows Installer (including issues, publishing, and application patches) can be used in .NET applications. Back to top

If I have written an assembly, I hope to use it in multiple applications, what should I deploy it?

To be deployed to the global program cache by multiple applications (such as shared assemblies). In the pre-release and beta, the / i option using the Alink SDK tool can install the assembly to the cache:

Al /i::dll.dll

The subsequent versions of Windows Installer can install the assembly into the global program cache.

Back to top

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

The .NET frame comes with a Windows housing extension to view the program set cache. In the Windows Explorer, turn to% Windir% / Assembly to activate the viewer.

Back to top

What is the application domain?

Application domains (usually appdomain) are virtual processes used to isolate applications. All objects created in the same application scope (in other words, starting from the application's entry point) will be created in the same application domain anywhere along the object activation sequence. Multiple application domains can exist in an operating system process that makes 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 also expensive, and cannot meet the number of large web servers. Instead, the application isolation is enforced by managing memory usage of code running in the application domain. This ensures that it does not access memory than the application domain. It should be noted that only types of secure code can be managed in this way (isolation is not guaranteed when running inactive code in the application domain).

Back to top

Garbage collection

What is garbage recovery?

Garbage Recycling is a mechanism that allows your computer to detect when to access an object. It will automatically release the memory used by the object (also calling the user's clearing routine). Some garbage collectors (as used by .NET) will compress memory and thus reduce the work set of the program.

Back to top

How does non-deterministic garbage recovery affect code?

For most programmers, there is a garbage collector (and objects that can be used as garbage) means that it will never be worried to release memory or reference count objects, even if you use a complex data structure. However, if you usually release system resources (file handle, lock, etc.) in code blocks used to release objects, then you need to make some modifications in coding style. When using objects that can be used as garbage, you should provide a way to explicitly release system resources (that is, controlled by your program) while allowing the garbage collector to release memory during compressed work set. Back to top

Can you avoid the use of a pile that can be recovered as garbage?

All languages ​​that support runtime allow you to assign a class object from a stack that can be recovered as garbage. This has brought benefits in rapid distribution and makes programmers do not need to calculate when they should explicit "free".

The CLR also provides a ValueTypes object - they are similar to the class, but the valueetype object is allocated in the runtime stack (not pile), so when your code exits defines these objects, they will be automatically recovered. This is the mode of operation of "struct" in C #.

C hosted extensions allow you to select the location of the class object assignment. If the __gc keyword is declared as a hosted class, they will be allocated from a heap that can be recovered as garbage; if they do not include the __gc keyword, they will allocate from the C bile as the normal C object, and use "free "The method explicitly released.

For more information on garbage collection, see:

Automatic memory management in Microsoft .NET framework - Part 2: Automatic Memory Management in Microsoft .NET Framework (English)

Back to top

Remote processing

How to communicate between processes and processes during the public language runtime?

There are two communication in the process: in the context of a single application domain, or cross-use program domain. In the context of the same application domain, the agent is used as the listening mechanism without related to sealing processing / serialization. When using the application domain, use the runtime binary protocol to seal processing / serialization.

Inter-process communication uses an insertable channel and formatting program protocol for each particular purpose.

If the developer specifies the endpoint to generate a metadata agent using the SOAVSUDS.EXE tool, the default value is an HTTP channel with the SOAP formatting program. If the developer performs explicit remote processing in the hosted world, it is necessary to specify the channels and formatting programs used. This can be represented by the configuration file, or use API calls to load a specific channel. The options are as follows: HTTP channel with SOAP formatted program (HTTP is running well on the Internet or anyway to communicate with firewall) TCP channel with binary formatting program (for local area network, TCP is optional) SMTP channel with SOAP formatting program (meaning only across computers)

When the transition is performed between the managed code and the non-hosting code, the COM infrastructure (especially DCOM) is used for remote processing. In the intermediate version of the CLR, this also applies to service components (components of COM services). In the final version, all remote components are all possible.

The distributed garbage collection of objects is managed by systems named "leased survival". Each object has a rental time that is disconnected from the CLR remote processing infrastructure when expired. The object has a default update time - the rent will be updated when the client successfully calls an object. The client can explicitly update rental. Back to top

Interoperability

Can I use COM objects in the .NET framework?

Yes. Any COM components you are now deploying can be used in managed code. Normally, the required adjustment is completely automated.

In particular, you can use the runtime to call the COM component from the .NET framework. This packaging converts the COM interface provided by the COM component to an interface compatible with the .NET framework. For OLE Automation Interfaces, RCW can automatically generate from the type library; for non-OLE automation interfaces, developers can write custom RCWs, manually map the type of types provided by the COM interface to the type compatible with the .NET framework.

Back to top

Can I use the .NET Framework component in a COM program?

Yes. You can use the managed type you now access to COM. Normally, the required configuration is completely automated. Some new features of the hosted development environment cannot be accessed in COM. For example, a static method and a parameterized constructor cannot be used in COM. Typically, it is a good way to determine the user for a given type in advance. If the type needs to be used in COM, you will be restricted to use COM accessible features.

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

In particular, you can use COM to access the .NET framework component from the COM. This is similar to RCW (see the previous problem), but their direction is opposite. Similarly, if the .NET framework development tool cannot automatically generate a package, or if the automatic mode is not what you need, you can develop a custom CCW.

Back to top

Can I use Win32 API in the .NET framework?

Yes. Using P / Invoke, the .NET Framework program can access the native code base by static DLL entry points.

Below is an example of C # calling the win32 messagebox function:

Using system;

Using system.Runtime.InteropServices;

Class Mainapp

{

[DLLIMPORT ("User32.dll", entrypoint = "mess")]]

Public Static Extern Int MessageBox (int hwnd, strmessage, string strcaption, uint uitype);

Public static void main ()

{

Messagebox (0, "Hello, this is pinvoke!", ".NET", 0);

}

}

Back to top

safety

How to make the code and security system work?

Usually, this is not problematic - Most applications can run safely and will not be disturbed by malicious attacks. Security is implemented by these libraries by simply using standard class libraries to access resources (such as files) or perform protected operations (such as reverse type private members). A simple job that application developers need to complete is to include permission requests (a disclosed security), which limits the permissions that the code may receive within the permission range it needs. This also ensures that if the code is allowed to run, it will have the required permissions when runtime.

They only need to directly process the security system only when developers need to write new base libraries that provide new resources. In this case, not all the code has potential security issues, and the code access security mechanism limits it on the part of the security system. Back to top

Why do security exceptions occur when running code in a network shared drive?

The default security policy only grants limited permissions from the code from the local intranet area. This area is defined by Internet Explorer security settings, which should be configured to match the local network within the company. Since files named by UNC or mapping drives (eg, using NET USE commands) need to be sent on the local network, they are also in the local Intranet area.

The default is set for unsafe intranet this worst case. If your intranet is secure, you can modify the security policy (with the Caspol tool) to grant more permissions to local intranet or part (such as a specific computer sharing name).

Back to top

How to write code so that it runs when the security system stops this code?

Safety exceptions will occur when the code is attempting to perform unauthorized operations. Permissions are granted based on code (especially its location). For example, the permissions obtained from the code running in the Internet are less than the permissions resulting from the code running on the local computer, because of the proven, its reliability is low. Therefore, you have to run the code that failed due to safety exceptions, you must add permission to grant it. A simple way is to move the code to a more trusted location (such as a local file system). But this method is not effective in any case (the web application is a good example, and the intranet application on the enterprise network is another example). Therefore, do not change the code location, but give this location more permissions by changing security policies. Use the code access security policy tool (Caspol.exe) or graphical management tool (available in Beta 2 and later) to do this. If you are a developer or issuer of the code, you can also digitally sign it, then modify the security policy, grant more permissions to the code with the digital signature. However, when performing any of the above operations, remember that this code is granted less permissions because it is not from trusted sources - before moving the code, you should make sure you should make sure these code Will not perform malicious or damaged operations.

Back to top

How to manage personal or corporate computers?

Currently, the Caspol command line tool is the only way to manage security. The security policy consists of two levels: pressing the computer and by the user. We plan to provide comprehensive management tools and enterprise policy management support in the first edition of the .NET Framework.

Back to top

How is the security of evidence work with Windows 2000 security work?

Evidence-based security (based on the authorization code) can work with Windows 2000 security (based on login identity). For example, to access a file, the hosted code must have code access security file permissions, and must also run under the login identity of NTFS file access. The checkered library included in the .NET framework provides classes for role-based security. These make the application work with Windows login identity and user group work.

转载请注明原文地址:https://www.9cbs.com/read-5493.html

New Post(0)