You want to know the pros and cons of registering your DLL assemblies in the GAC.
The pros of registering are 1. The .NET runtime finds GAC assemblies more quickly and loads them faster because it doesn’t have to check their integrity. 2. Assemblies in the GAC are protected from accidental deletion because only an administrator can access the GAC directory. The cons of registering are 1. More complicated deployments since you can’t rely on XCOPY to automatically register the assembly for you. 2. Having to uninstall the previous version from the GAC each time you recompile.
You don’t want to use the GAC if your sole purpose is to share types among different applications; there are better ways to accomplish this goal. You can share an assembly, including private ones, among different applications if all applications’ executable files are deployed in the same directory. Or, using a different approach, you can reference a strong-named assembly that is located outside the application’s main directory by using the element in the application’s configuration file.
There are ways to make GAC registration simpler. There’s a utility named Gacutil that comes with the Windows SDK and is automatically installed with Visual Studio. If you’re not a Visual Studio user like me, you can simply get it with the Windows SDK. You can configure Gacutil to run as a post-build event. In Visual Studio, you can configure the command to run in the Project Properties dialog box. Otherwise, you can add it to the .csproj file like so:
<Exec Command="Path to SDK\...\Gacutil.exe" /i $(TargetPath)" Condition="" />
You want to know the recommended .NET library to work with application configuration settings.
Consider using the System.Configuration namespace to store and retrieve configuration settings.
.NET programming guidelines recommend against storing data in INI files or the Windows Registry.
You want to know the best way to mark your main assembly for a given locale.
Use the NeutralResourcesLanguage attribute on the main assembly. This will inform the resource manager about the language for neutral resources that are embedded in the main assembly.
Using this attribute speeds up resource loading when the current user’s locale matches the culture used for resources in the main assembly. Don’t use the AssemblyCultureAttribute in the main assembly. The main assembly should only contain neutral resources (for example, strings and images related to the default language).
// This particular assembly contains resources for the US English culture.
You want to know the benefits of using resource (.resx) files.
Resource files provide a simple way to localize your .NET applications by automatically determining the .resx file to use based on a user’s locale. In addition, resource files provide a central location to store strings, files, and other scripts that can be referenced in a strongly-typed way. Another advantage is they can be compiled into satellite assemblies, making them easier to modify in a production environment.
String resources are great for error messages and user interface elements. Use them for human-readable text and not constants to be accessed programmatically.
You want to know the recommended naming convention for resources.
Use PascalCase for resource names. In general, you’ll want to follow the same guidelines you use when naming public fields.
1. Use descriptive names.
2. Don’t include spaces or punctuation marks.
3. Don’t start the name with a digit.
4. Avoid keyword names like long.
For example, ChromeDriver is a good resource name, whereas chromeDriver and Chrome:Driver aren’t. In addition, feel free to include dots to specify the property of an object (e.g. lblSearch.Text) or to separate elements in a hierarchy, such as Menus.Edit.Reformat.Text.
You want to know when and how to embed resources in your project.
You should favor using embedded resources for read-only data that will never change during your application’s lifetime. Use separate files to store data that the application can change or that you may want to deploy independently of the main application.
Pros & Cons
Resources that are embedded in the main assembly’s manifest can be located and loaded faster. They are also protected from accidental deletion. This technique is not best used when you have resources that are locale-dependent and should be localized for each language you support.
You can embed any data file in the assembly’s manifest by following these steps:
1. Add the file to the project.
2. Right-click the file and choose Properties.
3. Set the Build Action to Embedded Resource.
The following code demonstrates how to programmatically access a text file named TestData.txt from inside an assembly whose default (root) namespace is TestAutomation.
string dataFile = "TestAutomation.TestData.txt";
// Get a reference to the assembly.
Assembly assembly = Assembly.GetExecutingAssembly();
Stream stream = assembly.GetManifestResourceStream(dataFile);
// Read the contents of the embedded file and close it.
StreamReader reader = new StreamReader(stream);
string text = reader.ReadToEnd();
You want to know how to version your assemblies and any potential pitfalls.
Edit the AssemblyVersion(“18.104.22.168”) attribute in the AssemblyInfo.cs file, and give the assembly a specific version number. Change the version number when you publish a new version of the assembly.
Specifying a version number is important because it gives the assembly a strong name. One gotcha: If you use an asterisk in the version number, the version number changes each time you recompile the assembly. As a result, all client assemblies have to be recompiled and the identity of any enclosed types will change. Further, this will lead to problems when deserializing an object that was serialized by a previous version of the same assembly.
// Incorrect. Uses an asterisk.
// Correct. Remember to change as needed.
You want to ensure your types and their members are compliant with the Common Language Specification (CLS) and can be called by any .NET language.
Mark assemblies for class libraries with the CLSCompliant attribute.
// Add the following to the AssemblyInfo.cs file.
You want to know how to deal with the anxiety and stress of exams.
Acknowledge that being stressed is normal. It’s how you respond to stress that makes all the difference. Alter your thinking from “being afraid” to “being excited.” For example, swap “I’m afraid of not passing” with “I’m excited to do my best.”
Turn to deep breathing to calm yourself if you get stressed during an exam. It’s a good idea to give your brain a rest the day before an exam. Simply give the material a quick and final review. Be sure to double check your answers when taking an exam. Glance away, shift your attention, and then recheck.
You want to know how to approach difficult and simple exam problems.
When given an exam, take a quick glance at the entire thing to determine what’s involved. Start with the hardest problem. If you get stuck on it for more than two minutes, switch to an easier problem. Continue to solve what you can and then come back to the difficult one.
This strategy can be employed to practice exercises as well. When you begin with a hard problem, your brain loads your focused mode. When you switch attention away from it, your diffused mode kicks in. Turning to an easier problem allows different parts of your brain to work simultaneously on different thoughts.