Referencing Assemblies from Markup

To reference assemblies from markup, use assembly://. For example, the following statement maps the System namespace to the cor prefix:

xmlns:cor="assembly://MSCorLib/System"

You can also reference assemblies using the strong name, for example:

xmlns:btn="res://Sampler, Version=7.0.2009.0228,Culture=neutral,PublicKeyToken=31bf3856ad364e35!Scenarios.SimpleButton.mcml"

Assemblies must meet the following requirements:

  • The assembly needs to be strong-name signed.
  • The assembly needs to be in the global assembly cache (GAC).

When to use strong and weak assembly references

A weak assembly reference is the assembly name, for example:

res://Sampler!Scenarios.SimpleButton.mcml

A strong assembly reference is the full assembly identity, for example:

res://Sampler,Version=7.0.2009.0228,Culture=neutral,PublicKeyToken=31bf3856ad364e35!Scenarios.SimpleButton.mcml

MCML supports both types of syntax to refer to resources and assemblies.

A weak assembly reference can be replaced with a strong assembly reference, and the application will continue to work as expected. However, the reverse is not always true. Use strong and weak assembly references as follows:

  • When referring to resources within an assembly that is currently loaded, including your application assembly, you can use a weak or strong assembly reference.
  • When referring to resources that are within the same assembly as the code or markup, it is recommended you use weak assembly references for readability purposes.
  • When referring to resources in an assembly that is outside of the assembly that is currently loaded, use a strong reference.
  • When referring to code or markup that is located in an external assembly, use strong assembly names and ensure that those external assemblies are installed into the GAC.

Sample Explorer

  • Fundamentals > Resource Access

See Also