
Best Practices for Assembly Development
• All .NET assemblies (*.dll or *.exe) should be assigned a strong name.
• Typically, developers assume the only reason to assign a strong name is to deploy the assembly to the
GAC.
• In reality, strongly named assemblies have built in security traits.
• Specifically, the CLR will be able to detect if the assembly has been tampered with via a roundtrip
engineering attempt.
• You’ll see this in action later during our examination of .NET security.
• As a rule, mark your assemblies as CLS-compliant.
• When enabled, the compilers will emit compiler errors when exposing non-CLS compliant programming
techniques.
• C# and VB 2005 (but not VB 2003) both support a number of techniques which fall outside of the
realm of CLS-compliance.
• If you make use of such code (such as exposed unsigned data), your code will not be usable from all .
NET programming languages.
' VB 2005
<Assembly: System.CLSCompliant(True)>
// C#
[assembly: System.CLSCompliant(true)]
• Only deploy to the GAC when necessary. On the positive side:
• The CLR can find and load assemblies deployed in the GAC very quickly.
• Assemblies in the GAC are protected from end user deletion, as you must have admin rights to interact
with the GAC.
• Assemblies deployed to the GAC support side-by-side execution.
• On the negative side:
• You no longer can rely on XCOPY deployment, and must therefore design an installer script to
correctly deploy your shared assemblies.
• Don’t assume that pre-JITed assemblies will always execute faster.
• The ngen.exe utility can be used to pre-compile assemblies upon installation.
• However, this technique is really only beneficial if the assembly is a UI-intensive Windows Forms
application (as it will decrease load up time).
• For non-UI applications, you may run slower as ngen-ed assemblies are not optimized in the same way
as non-Jitted assemblies.
• Always run some benchmarks to see if ngen-ing is right for your application.
Assembly Development
Table of Contents
Copyright (c) 2008. Intertech, Inc. All Rights Reserved. This information is to be used exclusively as an
online learning aid. Any attempts to copy, reproduce, or use for training is strictly prohibited.
Courseware
Training Resources
Tutorials