Home > Articles > Programming > Windows Programming

Like this article? We recommend

Like this article? We recommend

Managed Execution

To understand how your VB.NET applications work and just how much the code differs from the VB code that Dorothy wrote in Kansas, it's important to understand managed code and how it works. To use managed execution and get the benefits of the CLR, you must use a language that was built for, or targets, the runtime. Fortunately for you, this includes VB.NET. In fact, Microsoft wanted to make sure that VB.NET was a premier language on the .NET platform, meaning that Visual Basic could no longer be accused of being a "toy" language.

The runtime is a language-neutral environment, which means that any vendor can create a language that takes advantage of the runtime's features. Different compilers can expose different amounts of the runtime to the developer, so the tool you use and the language in which you write might still appear to work somewhat differently. The syntax of each language is different, of course, but when the compilation process occurs, all code should be compiled into something understandable to the runtime.

NOTE

Just because a language targets the runtime doesn't mean that the language can't add features that are not understood by other languages. In order to make sure that your components are completely usable by components written in other languages, you must use only types that are specified by the Common Language Specification.

Microsoft Intermediate Language (MSIL)

One of the more interesting aspects of .NET is that when you compile your code, you do not compile to native code. Before you VB developers panic and fear that you are returning to the days of interpreted code, realize that the compilation process translates your code into something called Microsoft Intermediate Language, called MSIL or just IL. The compiler also creates the necessary metadata and compiles it into the component. This IL is CPU-independent.

The IL contains the metadata, and the final file is called a portable executable, or PE. The PE is also sometimes called a physical executable. Because the PE contains your IL and metadata, it is therefore self-describing, eliminating the need for a type library or interfaces specified with the Interface Definition Language (IDL).

The Just-In-Time Compiler

Your code does not stay IL for long, however. It is this IL that can be distributed and placed with the CLR running on the .NET Framework on any operating system because the IL is platform-independent. When you run the IL, however, it is compiled to native code for that platform. Therefore, you are still running native code; you are not going back to the days of interpreted code at all. The compilation to native code occurs via another tool of the .NET Framework: the Just-In-Time (JIT) compiler.

With the code compiled, it can run within the Framework and take advantage of such low-level features as memory management and security. The compiled code is native code for the CPU on which the .NET Framework is running, meaning that you are indeed running native code instead of interpreted code. A JIT compiler will be available for each platform on which the .NET Framework runs, so you should always be getting native code on any platform.

NOTE

It is still possible to call operating system–specific APIs, which would, of course, limit your application to just that platform. That means it is still possible to call Windows APIs, but then the code would not be able to run within the .NET Framework on a non-Windows machine. At this point in time, the .NET Framework exists only on the Windows platform, but this will change in the future.

Executing Code

Interestingly, the JIT complier doesn't compile the entire IL when the component is first called. Instead, each method is compiled the first time it is called. This keeps you from having to compile sections of code that are never called. After the code is compiled, of course, subsequent calls use the compiled version of the code. This natively compiled code is stored in memory in Beta 1. However, Microsoft has promised a pre-JIT compiler that will compile all the code at once and store the compiled version on disk, so the compilation would persist over time.

After the code is executing, it can take full advantage of the CLR, with benefits such as the security model, memory management, debugging support, and profiling tools. Most of these benefits will be mentioned throughout the book.

Assemblies

One of the new structures you will create in VB.NET is the assembly. An assembly is a collection of one or more physical files. The files are most often code, such as the classes you build, but they could also be images, resource files, and other binary files associated with the code. Such assemblies are known as static assemblies because you create them and store them on disk. Dynamic assemblies are created at runtime and are not stored to disk (although they can be).

An assembly represents the unit of deployment, version control, reuse, and security. If this sounds like the DLLs you have been creating in Visual Basic for the past six years, it is similar. Just as a standard COM DLL has a type library, the assembly has a manifest that contains the metadata for the assembly, such as the classes, types, and references contained in the IL. The assembly often contains one or more classes, just like a COM DLL. Applications are built using assemblies; assemblies are not applications in their own rights.

Perhaps the most important point of assemblies is this: All runtime applications must be made up of one or more assemblies.

The Assembly Manifest

The manifest is similar in theory to the type library in COM DLLs. The manifest contains all the information about the items in the assembly, including what parts of the assembly are exposed to the outside world. The manifest also lists the assembly's dependencies on other assemblies. Each assembly is required to have a manifest.

The manifest can be part of a PE file, or it can be a standalone in an assembly with more than one file. Although this is not an exhaustive list, a manifest contains:

  • Assembly name

  • Version

  • Files in the assembly

  • Referenced assemblies

In addition, a developer can set custom attributes for an assembly, such as a title and a description.

An End to DLL Hell?

One of the great benefits of COM was supposed to be an end to DLL hell. If you think back for a moment to the days of 16-bit programming, you'll remember that you had to distribute a number of DLLs with a Windows application. It seemed that almost every application had to install the same few DLLs, such as Ctrl3d2.dll. Each application that you installed might have a slightly different version of the DLL, and you ended up with multiple copies of the same DLL, but many were different versions. Even worse, a DLL could be placed in the Windows\System directory that then broke many of your existing applications.

COM was supposed to fix all that. No longer did applications search around for DLLs by looking in their own directories, and then search the Windows path. With COM, requests for components were sent to the registry. Although there might be multiple versions of the same COM DLL on the machine, there would be only one version in the registry at any time. Therefore, all clients would use the same version. This meant, however, that each new version of the DLL had to guarantee compatibility with previous versions. This led to interfaces being immutable under COM; after the component was in production, the interface was never supposed to change. In concept, that sounds great, but developers released COM components that broke binary compatibility; in other words, their components modified, added, or removed properties or methods. The modified components then broke all existing clients. Many VB developers have struggled with this exact problem.

The .NET Framework and the CLR attempt to address this problem through the use of assemblies. Even before .NET, Windows 2000 introduced the capability to have an application look in the local directory for a DLL, instead of going to the registry. This ensured that you always had the correct version of the DLL available to the application.

The runtime carries this further by allowing components to declare dependencies on certain versions of other components. In addition, multiple versions of the same component can be run simultaneously in what Microsoft calls side-by-side instancing or side-by-side execution.

The Global Assembly Cache (GAC)

Even though components in .NET do not have to be registered, there is a similar process if you have an assembly that is to be used by multiple applications. The CLR actually has two caches within its overall code cache: the download cache and the global assembly cache (GAC). An assembly that will be used by more than one application is placed into the global assembly cache by running an installer that places the assembly in the GAC.

The GAC is where you place a component if you want multiple applications to use the same component. This is very similar to what you have with registered COM components in VB6.

Placing assemblies in the GAC has several advantages. Assemblies in the GAC tend to perform better because the runtime locates them faster and the security does not have to be checked each time that the assemblies are loaded. Assemblies can be added to or removed from the GAC only by someone with administrator privileges.

Where things get interesting is that you can actually have different versions of the same assembly in the GAC at the same time. Notice that I avoided saying "registered in the GAC" because you aren't placing anything in the registry. Even if a component is running in the GAC, you can add another version running alongside it, or you can slipstream in an emergency fix. This is all based on the version number, and you have control over whether an update becomes a newly running version or merely an upgrade to an existing version.

Assemblies can be placed in the GAC only if they have a shared name.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020