Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/standard/analyzers/platform-compat-analyzer.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,11 @@ The following code snippet shows how you can combine attributes to set the right

The recommended way to deal with these diagnostics is to make sure you only call platform-specific APIs when running on an appropriate platform. Following are the options you can use to address the warnings; choose whichever is most appropriate for your situation:

- **Guard the call**. You can achieve this by conditionally calling the code at run time. Check whether you're running on a desired `Platform` by using one of platform-check methods, for example, `OperatingSystem.Is<Platform>()` or `OperatingSystem.Is<Platform>VersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0)`. [Example](#guard-platform-specific-apis-with-guard-methods).
- **Guard the call**. You can achieve this by conditionally calling the code at runtime. Check whether you're running on a desired `Platform` by using one of platform-check methods, for example, `OperatingSystem.Is<Platform>()` or `OperatingSystem.Is<Platform>VersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0)`. [Example](#guard-platform-specific-apis-with-guard-methods).

- **Mark the call site as platform-specific**. You can also choose to mark your own APIs as being platform-specific, thus effectively just forwarding the requirements to your callers. Mark the containing method or type or the entire assembly with the same attributes as the referenced platform-dependent call. [Examples](#mark-call-site-as-platform-specific).

- **Assert the call site with platform check**. If you don't want the overhead of an additional `if` statement at run time, use <xref:System.Diagnostics.Debug.Assert(System.Boolean)?displayProperty=nameWithType>. [Example](#assert-the-call-site-with-platform-check).
- **Assert the call site with platform check**. If you don't want the overhead of an additional `if` statement at runtime, use <xref:System.Diagnostics.Debug.Assert(System.Boolean)?displayProperty=nameWithType>. [Example](#assert-the-call-site-with-platform-check).

- **Delete the code**. Generally not what you want because it means you lose fidelity when your code is used by Windows users. For cases where a cross-platform alternative exists, you're likely better off using that over platform-specific APIs.

Expand Down
4 changes: 2 additions & 2 deletions docs/standard/assembly/create-use-strong-named.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ The following scenario outlines the process of signing an assembly with a strong

3. Assembly B is a consumer of Assembly A. The reference section of Assembly B's manifest includes a token that represents Assembly A's public key. A token is a portion of the full public key and is used rather than the key itself to save space.

4. The common language runtime verifies the strong name signature when the assembly is placed in the global assembly cache. When binding by strong name at run time, the common language runtime compares the key stored in Assembly B's manifest with the key used to generate the strong name for Assembly A. If the .NET security checks pass and the bind succeeds, Assembly B has a guarantee that Assembly A's bits have not been tampered with and that these bits actually come from the developers of Assembly A.
4. The common language runtime verifies the strong name signature when the assembly is placed in the global assembly cache. When binding by strong name at runtime, the common language runtime compares the key stored in Assembly B's manifest with the key used to generate the strong name for Assembly A. If the .NET security checks pass and the bind succeeds, Assembly B has a guarantee that Assembly A's bits have not been tampered with and that these bits actually come from the developers of Assembly A.

> [!NOTE]
> This scenario doesn't address trust issues. Assemblies can carry full Microsoft Authenticode signatures in addition to a strong name. Authenticode signatures include a certificate that establishes trust. It's important to note that strong names don't require code to be signed in this way. Strong names only provide a unique identity.
Expand Down Expand Up @@ -68,7 +68,7 @@ This feature can be disabled for individual applications or for a computer. See
|[How to: Create a public-private key pair](create-public-private-key-pair.md)|Describes how to create a cryptographic key pair for signing an assembly.|
|[How to: Sign an assembly with a strong name](sign-strong-name.md)|Describes how to create a strong-named assembly.|
|[Enhanced strong naming](enhanced-strong-naming.md)|Describes enhancements to strong-names in the .NET Framework 4.5.|
|[How to: Reference a strong-named assembly](reference-strong-named.md)|Describes how to reference types or resources in a strong-named assembly at compile time or run time.|
|[How to: Reference a strong-named assembly](reference-strong-named.md)|Describes how to reference types or resources in a strong-named assembly at compile time or runtime.|
|[How to: Disable the strong-name bypass feature](disable-strong-name-bypass-feature.md)|Describes how to disable the feature that bypasses the validation of strong-name signatures. This feature can be disabled for all or for specific applications.|
|[Create assemblies](create.md)|Provides an overview of single-file and multifile assemblies.|
|[How to delay sign an assembly in Visual Studio](/visualstudio/ide/managing-assembly-and-manifest-signing#how-to-sign-an-assembly-in-visual-studio)|Explains how to sign an assembly with a strong name after the assembly has been created.|
Expand Down
2 changes: 1 addition & 1 deletion docs/standard/assembly/file-format.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ Assembly Headers from ECMA 335 II.25.1, Structure of the runtime file format.

## Process the assemblies

It is possible to write tools or APIs to process assemblies. Assembly information enables making programmatic decisions at run time, rewriting assemblies, providing API IntelliSense in an editor, and generating documentation. <xref:System.Reflection?displayProperty=nameWithType>, <xref:System.Reflection.MetadataLoadContext?displayProperty=nameWithType>, and [Mono.Cecil](https://www.mono-project.com/docs/tools+libraries/libraries/Mono.Cecil/) are good examples of tools that are frequently used for this purpose.
It is possible to write tools or APIs to process assemblies. Assembly information enables making programmatic decisions at runtime, rewriting assemblies, providing API IntelliSense in an editor, and generating documentation. <xref:System.Reflection?displayProperty=nameWithType>, <xref:System.Reflection.MetadataLoadContext?displayProperty=nameWithType>, and [Mono.Cecil](https://www.mono-project.com/docs/tools+libraries/libraries/Mono.Cecil/) are good examples of tools that are frequently used for this purpose.
2 changes: 1 addition & 1 deletion docs/standard/assembly/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ In C#, you can use two versions of the same assembly in a single application. Fo
|[Assembly placement](../../framework/app-domains/assembly-placement.md)|Where to locate assemblies.|
|[Assemblies and side-by-side execution](side-by-side-execution.md)|Use multiple versions of the runtime or an assembly simultaneously.|
|[Emit dynamic methods and assemblies](../../fundamentals/reflection/emitting-dynamic-methods-and-assemblies.md)|How to create dynamic assemblies.|
|[How the runtime locates assemblies](../../framework/deployment/how-the-runtime-locates-assemblies.md)|How the .NET Framework resolves assembly references at run time.|
|[How the runtime locates assemblies](../../framework/deployment/how-the-runtime-locates-assemblies.md)|How the .NET Framework resolves assembly references at runtime.|

## Reference

Expand Down
52 changes: 26 additions & 26 deletions docs/standard/assembly/reference-strong-named.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,55 @@
title: "How to: Reference a strong-named assembly"
description: This article shows you how to reference types or resources in a strong-named .NET assembly, either at compile time or runtime.
ms.date: "08/20/2019"
helpviewer_keywords:
helpviewer_keywords:
- "strong-named assemblies, compile-time references"
- "compile-time assembly referencing"
- "assemblies [.NET], strong-named"
- "assembly binding, strong-named"
ms.topic: how-to
dev_langs:
dev_langs:
- "csharp"
- "vb"
- "cpp"
---
# How to: Reference a strong-named assembly

The process for referencing types or resources in a strong-named assembly is usually transparent. You can make the reference either at compile time (early binding) or at run time.
The process for referencing types or resources in a strong-named assembly is usually transparent. You can make the reference either at compile time (early binding) or at runtime.

A compile-time reference occurs when you indicate to the compiler that the assembly to be compiled explicitly references another assembly. When you use compile-time referencing, the compiler automatically gets the public key of the targeted strong-named assembly and places it in the assembly reference of the assembly being compiled.

> [!NOTE]
> A strong-named assembly can only use types from other strong-named assemblies. Otherwise, the security of the strong-named assembly would be compromised.
## Make a compile-time reference to a strong-named assembly
> A strong-named assembly can only use types from other strong-named assemblies. Otherwise, the security of the strong-named assembly would be compromised.

## Make a compile-time reference to a strong-named assembly

At a command prompt, type the following command:
At a command prompt, type the following command:

\<*compiler command*> **/reference:**\<*assembly name*>
\<*compiler command*> **/reference:**\<*assembly name*>

In this command, *compiler command* is the compiler command for the language you are using, and *assembly name* is the name of the strong-named assembly being referenced. You can also use other compiler options, such as the **/t:library** option for creating a library assembly.
In this command, *compiler command* is the compiler command for the language you are using, and *assembly name* is the name of the strong-named assembly being referenced. You can also use other compiler options, such as the **/t:library** option for creating a library assembly.

The following example creates an assembly called *myAssembly.dll* that references a strong-named assembly called *myLibAssembly.dll* from a code module called *myAssembly.cs*.
The following example creates an assembly called *myAssembly.dll* that references a strong-named assembly called *myLibAssembly.dll* from a code module called *myAssembly.cs*.

```cmd
csc /t:library myAssembly.cs /reference:myLibAssembly.dll
```
csc /t:library myAssembly.cs /reference:myLibAssembly.dll
```

## Make a runtime reference to a strong-named assembly

## Make a run-time reference to a strong-named assembly

When you make a run-time reference to a strong-named assembly, for example by using the <xref:System.Reflection.Assembly.Load%2A?displayProperty=nameWithType> or <xref:System.Reflection.Assembly.GetType%2A?displayProperty=nameWithType> method, you must use the display name of the referenced strong-named assembly. The syntax of a display name is as follows:
When you make a runtime reference to a strong-named assembly, for example by using the <xref:System.Reflection.Assembly.Load%2A?displayProperty=nameWithType> or <xref:System.Reflection.Assembly.GetType%2A?displayProperty=nameWithType> method, you must use the display name of the referenced strong-named assembly. The syntax of a display name is as follows:

\<*assembly name*>**,** \<*version number*>**,** \<*culture*>**,** \<*public key token*>
\<*assembly name*>**,** \<*version number*>**,** \<*culture*>**,** \<*public key token*>

For example:
For example:

```console
myDll, Version=1.1.0.0, Culture=en, PublicKeyToken=03689116d3a4ae33
```
```

In this example, `PublicKeyToken` is the hexadecimal form of the public key token. If there is no culture value, use `Culture=neutral`.
In this example, `PublicKeyToken` is the hexadecimal form of the public key token. If there is no culture value, use `Culture=neutral`.

The following code example shows how to use this information with the <xref:System.Reflection.Assembly.Load%2A?displayProperty=nameWithType> method.
The following code example shows how to use this information with the <xref:System.Reflection.Assembly.Load%2A?displayProperty=nameWithType> method.

```cpp
Assembly^ myDll =
Expand All @@ -67,13 +67,13 @@ Dim myDll As Assembly = _
Assembly.Load("myDll, Version=1.0.0.1, Culture=neutral, PublicKeyToken=9b35aa32c18d4fb1")
```

You can print the hexadecimal format of the public key and public key token for a specific assembly by using the following [Strong Name (Sn.exe)](../../framework/tools/sn-exe-strong-name-tool.md) command:
You can print the hexadecimal format of the public key and public key token for a specific assembly by using the following [Strong Name (Sn.exe)](../../framework/tools/sn-exe-strong-name-tool.md) command:

**sn -Tp \<** *assembly* **>**
**sn -Tp \<** *assembly* **>**

If you have a public key file, you can use the following command instead (note the difference in case on the command-line option):
If you have a public key file, you can use the following command instead (note the difference in case on the command-line option):

**sn -tp \<** *public key file* **>**
**sn -tp \<** *public key file* **>**

## See also

Expand Down
2 changes: 1 addition & 1 deletion docs/standard/assembly/set-attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ You can use informational attributes to provide additional company or product in
| <xref:System.Reflection.AssemblyCompanyAttribute> | String value specifying a company name. |
| <xref:System.Reflection.AssemblyCopyrightAttribute> | String value specifying copyright information. |
| <xref:System.Reflection.AssemblyFileVersionAttribute> | String value specifying the Win32 file version number. This normally defaults to the assembly version. |
| <xref:System.Reflection.AssemblyInformationalVersionAttribute> | String value specifying version information that is not used by the common language runtime, such as a full product version number. **Note:** If this attribute is applied to an assembly, the string it specifies can be obtained at run time by using the <xref:System.Windows.Forms.Application.ProductVersion%2A?displayProperty=nameWithType> property. The string is also used in the path and registry key provided by the <xref:System.Windows.Forms.Application.UserAppDataPath%2A?displayProperty=nameWithType> and <xref:System.Windows.Forms.Application.UserAppDataRegistry%2A?displayProperty=nameWithType> properties. |
| <xref:System.Reflection.AssemblyInformationalVersionAttribute> | String value specifying version information that is not used by the common language runtime, such as a full product version number. **Note:** If this attribute is applied to an assembly, the string it specifies can be obtained at runtime by using the <xref:System.Windows.Forms.Application.ProductVersion%2A?displayProperty=nameWithType> property. The string is also used in the path and registry key provided by the <xref:System.Windows.Forms.Application.UserAppDataPath%2A?displayProperty=nameWithType> and <xref:System.Windows.Forms.Application.UserAppDataRegistry%2A?displayProperty=nameWithType> properties. |
| <xref:System.Reflection.AssemblyProductAttribute> | String value specifying product information. |
| <xref:System.Reflection.AssemblyTrademarkAttribute> | String value specifying trademark information. |

Expand Down
14 changes: 7 additions & 7 deletions docs/standard/assembly/side-by-side-execution.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
title: "Assemblies and side-by-side execution"
description: Learn about side-by-side execution, which is the ability to store and run multiple versions of an application or component on the same computer.
ms.date: "08/20/2019"
helpviewer_keywords:
helpviewer_keywords:
- "side-by-side execution [.NET]"
- "assemblies [.NET], side-by-side execution"
ms.assetid: e42036ee-7590-47d1-b884-cc856e39bd5d
---
# Assemblies and side-by-side execution

Side-by-side execution is the ability to store and execute multiple versions of an application or component on the same computer. This means that you can have multiple versions of the runtime, and multiple versions of applications and components that use a version of the runtime, on the same computer at the same time. Side-by-side execution gives you more control over what versions of a component an application binds to, and more control over what version of the runtime an application uses.
Support for side-by-side storage and execution of different versions of the same assembly is an integral part of strong naming and is built into the infrastructure of the runtime. Because the strong-named assembly's version number is part of its identity, the runtime can store multiple versions of the same assembly in the global assembly cache and load those assemblies at run time.
Although the runtime provides you with the ability to create side-by-side applications, side-by-side execution is not automatic. For more information on creating applications for side-by-side execution, see [Guidelines for creating components for side-by-side execution](../../framework/deployment/guidelines-for-creating-components-for-side-by-side-execution.md).
Side-by-side execution is the ability to store and execute multiple versions of an application or component on the same computer. This means that you can have multiple versions of the runtime, and multiple versions of applications and components that use a version of the runtime, on the same computer at the same time. Side-by-side execution gives you more control over what versions of a component an application binds to, and more control over what version of the runtime an application uses.

Support for side-by-side storage and execution of different versions of the same assembly is an integral part of strong naming and is built into the infrastructure of the runtime. Because the strong-named assembly's version number is part of its identity, the runtime can store multiple versions of the same assembly in the global assembly cache and load those assemblies at runtime.

Although the runtime provides you with the ability to create side-by-side applications, side-by-side execution is not automatic. For more information on creating applications for side-by-side execution, see [Guidelines for creating components for side-by-side execution](../../framework/deployment/guidelines-for-creating-components-for-side-by-side-execution.md).

## See also

- [How the runtime locates assemblies](../../framework/deployment/how-the-runtime-locates-assemblies.md)
Expand Down
Loading
Loading