Showing posts with label .NET Fundamentals. Show all posts
Showing posts with label .NET Fundamentals. Show all posts

February 9, 2015

Assembly versioning the right way

When I started working on projects that matter and people actually use, I also started use assembly versioning system provided by the .NET Framework. For one thing, I like seeing a version number increase because it reminds me of how much work I’ve done. For another, it helps me solve problems when someone reports a bug and I can just ask for a version being used. But thruth to be said, there’s more to it than just increasing numbers, I learned my lesson and I share the experience through this article.

AssemblyInfo

assemblyinfo Every new project you create in Visual Studio has a file called AssemblyInfo with an extension depending on a language you use. For C#, it’s .cs extension. This file is located in a special project folder called Properties.
It’s information in this file that affects what you can see in assembly details when you right-click it in Windows Explorer and select Properties and navigate to Details tab


props

or when you reference it from another project and inpsect it in Properties window.

vsprops

Versions

There are 3 different versions that assembly can have.

AssemblyInformationalVersion

[assembly: AssemblyInformationalVersion("2.0 beta")]

This is the Product version in assembly properties details and it’s by default not included in AssemblyInfo file because it’s ment to be consistent across a whole product, which can consist of many different assemblies. Typically, a build server adjusts this version. It does not have to be a number, it can be just any string. The default value is the same as AssemblyVersion.

AssemblyFileVersion

[assembly: AssemblyFileVersion("2.0.1.5")]

This is the File version in assembly properties details and is the same as AssemblyVersion if not specified otherwise. Its format should abide by the major.minor.build.revision convention. Typically, you set the major and minor numbers the same as in AssemblyVersion and the last two are incremented with each build. However, there’s no trivial way how to specify this behaviour unless you are using a build server to do it for you. If you don’t use a build server and still want to achieve auto-incrementing, I recommend this CodeProject article that I followed with success.

Remember, this is the version you should be using for problem solving.

AssemblyVersion

[assembly: AssemblyVersion("2.0.0.0")]

This version is not visible in assembly properties details, but you can see it in VS reference properties, for instance. Its format should abide by the major.minor.build.revision convention and if not specified, it’s 0.0.0.0. This version is probably the most important one, because it’s used by the .NET Framework runtime to bind to strongly named assemblies, which means, that even a slightest change in the version can result in a compile time error or a runtime exception in a project that references it, if there’s a version mismatch while loading assemblies to an AppDomain. This version supports auto-increment directly by setting the two first number manually and replacing the rest with an asterisk.
[assembly: AssemblyVersion("2.0.*")]

I use this notation in many internal tools because they are not being built by a build server and no other projects depend on them. Once, I created a shared library, forgot about the rule emphasized above and it cost me and some of my colleagues many hours every time I did some small yet important changes, and committed a new assembly to projects I was familiar with. Finally, one day someone drew my attention to this issues and I decided to write an article about it.

What exactly can cause such problems? Let’s say you have a logging library that a project CoreLib uses. There’s also a console project SomeConsole and it uses both CoreLib and the logging library. But you are only the author of the logging library and you know about CoreLib. So when you add a new cool logging feature, rebuild the project, commit the new assembly to a repository and rebuild CoreLib to use it, now you have a problem. A person who maintains SomeConsole starts using a newer version of CoreLib but does not know about a new version of the logging library will get a compile time error. And that’s just one dependency. Now imagine, that SomeConsole also uses few other core libraries some of which discovered your logging library in a different time and therefore use a different version each. There’s a true madness.

For more explanations, navigate to this SO question. I find particularly answer from Daniel Fortunov very explaining and I like his example of mscorlib.dll.

January 5, 2015

.NET Fundamentals MTA certification experience

MTA logoI recently took a Microsoft exam 98-372, also known as Microsoft Technology Associate for .NET Fundamentals, and passed it with a score of 78%. I have to admit that I expected a better result after I made it through questions in 30 minutes or so without much sweating. In this article, I'll briefly describe the exam, how did I prepare for it and give away some tips (nothing that an NDA paper I had to sign doesn't allow me to anyway).

You can take the exam either in C# or VB.NET but from my experience, if you are comfortable reading code in both of them, it does not matter which one you choose, because there's no code writting and only handful of code understanding questions. The exam primarily consists of questions with answers provided to pick the best one. Questions are from the following areas:
  • Understanding .NET Framework concepts
    • Understand basic application settings
    • Understand events and event handling in the .NET Framework
    • Understand structured exception handling in the .NET Framework
  • Understanding namespaces and classes in the .NET Framework
    • Understand .NET class hierarchies
    • Understand object oriented concepts in the .NET Framework
    • Understand .NET namespaces
    • Understand and create class libraries
    • Understand and use different data types in the .NET Framework
    • Understand generics
  • Understanding .NET code compilation
    • Understand the fundamentals of Microsoft Intermediate Language (MSIL) and Common Language Infrastructure (CLI)
    • Understand the use of strong naming
    • Understand version control
    • Understand assemblies and metadata
  • Understanding I/O classes in the .NET Framework
    • Understand .NET file classes
    • Understand console I/O
    • Understand XML classes in the .NET Framework
  • Understanding security
    • Understand the System Security namespace
    • Understand authentication and authorization
  • Understanding .NET languages
    • Understand language interoperability
    • Understand type safety
  • Understanding memory management
    • Understand resource allocation
    • Understand the difference between managed and unmanaged applications
Now, you might think that that's quite a lot of area covered, but I would say that it's roughly 15% of the .NET Framework core (no web, desktop, mobile, ...) if not even less. The structure probably has not been changed since it was created. There are no questions on goodies from the latest versions of the .NET Framework like LINQ or TPL. And that is why I do not take the certificate too seriously. It's a great start if you are new to .NET but I would sure want to see more if I should take you aboard.

If you are a .NET newbie who needs to prepare for the exam, I recommend going carefully through every "Preparation resource" provided by Microsoft (you will find link at the end of the article) and trying out every code snippet available there. To get even better understanding, reading most of the articles referred to from those resources is highly recommended.

If you develop on the .NET platform at least few years, you probably know most of the covered topics already. Just go through the list and if you are not really sure that you know enough, read the resources.

I originally thought that I could do the exam without any additional studies whatsoever, but I found out that "Understanding security" includes many subareas I'm not experienced in. I read everything I could get my hands on but it still was my weakest area in which I scored only half of the percentage allocated. So if you have never worked on an application with a security part in it, do not underestimate this area.

I also stumbled in interoperability and event handling, because I never played with things like COM and didn't expect questions on events and delegates be so oddly described. If you know how to work with events and delegates, I still recommend reading this preparation resource and focus on how things are called.

Memory management and code compilation are my favourite areas so no problem there, but I guess they are not widely popular amongst developers, so be cautious there, learns some fundamentals.

Probably the easiest area is "namespaces and classes". You would have to be a real newcomer to make a mistake there. Or I can imagine that if you are not very comfortable reasoning about code outside Visual Studio that you might get easily confused by some questions.

That's about it. Do not underestimate it even if you are a seasoned .NET developer, particularly if you joined the community in last few years and some concepts from the .NET 2.0 are still not very clear to you. If you search the internet you might find some exam examples and get feeling about how questions look like. If you want to know more about the exam, visit the official website, please.