Ads by Lake Quincy Media
Gibraltar - Learn about the best analysis tool for NLog

Support for .NET Framework 4 Client Profile in NLog 2.0

.NET Framework 4 client profile is a subset of .NET framework used for client programming. It’s a smaller download, because it does not have some server-specific assemblies such as System.Web.dll, compilers and design-time components. When your project targets the client profile, VS and the compiler will validate that it can actually run in that environment. Your application cannot (statically) reference any system DLLs which are not available in the client profile or any other dlls which may depend on such system assemblies.

Why am I writing about this and how is it related to NLog?

Historically NLog has been distributed as a single assembly with static references to all the required system assemblies, including ones which will no longer be available in the client profile:

image

As you can see, we have System.Web.dll (because of ASP.NET-specific layout renderers and modules) and System.Messaging.dll (because of MSMQ target) which are from extended profile. If I were to distribute NLog 2.0 with those dependencies, people would not be able to compile their client applications using it- this is bad.

Difficult choice

Since people use NLog for both client-side and server-side deployments (and removing ASP.NET support is not an option) I need to have builds of NLog which support both environments. There are 3 options I’m considering:

  1. Release two versions of NLog.dll – one for .NET 4.0 Extended profile and one for .NET 4.0 Client profile
  2. Remove static dependencies and release single NLog.dll which detects the profile at runtime and invokes System.Web/System.Messaging through reflection.
  3. Release NLog.dll which would be client-only subset and NLog.Extended.dll which would include features specific to extended profile. This would mean that NLog 2.0 for other versions of the framework would also be split into NLog.dll and NLog.Extended.dll

Each option has different pros and cons, which makes this a hard choice:

Option 1 has the following advantages:

  • Single assembly to deploy in all scenarios (now that NLog.ComInterop.dll has been merged with NLog.dll there is truly a singly dll)
  • Relatively simple code – stuff which does not compile on client profile will be simply #ifdef-ed.
  • No dynamic invocation

But there is possible confusion because of existence of two different builds of the same component (with the same name, version numbers and everything else) with slightly different feature set.

Option 2 means single assembly, but potentially slower and harder-to-maintain reflection code

Option 3 is probably the cleanest (there is no conditional compilation and no dynamic invocation), but it means that there will be sometimes 2 assemblies to deal with – in client apps you would reference NLog.dll and in extended profile apps, you can (optionally) use NLog.Extended.dll.

What do you think? Which of those options should I choose? Would you prefer a single assembly over multiple ones? Do you think reflection is a good practice to avoid having to deal with client profile limitations?

Please post your thought in comments.

Ads by Lake Quincy Media

11 Responses to “Support for .NET Framework 4 Client Profile in NLog 2.0”

  1. Ahmet KARA says:

    Hi,

    I prefer number 1, but with a naming convesion extension. Like the one that uses client profile will be named as NLogLite.dll, and the one with extended profile will be NLog.dll.

    NLog.dll will include all features in NLogLite.dll with the addition of web and MSMQ features.

    Thanks for your good work.

  2. Robert A. McCarter says:

    I think that option #3 is the best.

    Two DLLs is really a non-issue, so to me option 3 has no drawbacks.

    This would probably be significantly easier to maintain as well. As you point out, there are no compiler directives mucking up the code, and you can provide a single help file that details both assemblies. This is the natural way that .NET projects are intended to be built.

    I think option 2 is going to really complicate development while providing very little benefit.

    I think the a only benefit of option 1 (single DLL) is outweighed by the complexity – especially for new NLog users – of ensuring they have the correct DLL. Figuring out if somebody has accidentally pulled in the wrong DLL is difficult, and requires looking at the size of the DLLs! That is not pretty. This could be fixed by using Ahmet’s suggestion of two separate DLL names, but you still code cluttered with compiler directives, and you still make people think about which DLL they need. So I think option 3 is still better than Ahmet’s suggestion (nothing personlal Ahmet :-)

    You need to consider your ability to maintain the code as well as considering ease-of-use. Because I think referencing 2 DLLs is very easy, and maintaining code with compiler directives gets really messy really fast (I’ve tried this, it isn’t pretty) I vote for option 3.

    Robert

  3. Jarek Kowalski says:

    I am not a big fan of NLogLite.dll – the reason for that is that if you have compiled your app against NLogLite.dll you’re stuck and you cannot move to full NLog.dll without recompiling, even when you install extended framework.

  4. CHill says:

    I’ll second Robert’s comments. #3 looks like the best balance between ease of implementation and ease of maintenance.

  5. ZorroB says:

    I Like option 3, thanks for the updates.

  6. Audun says:

    I would go for option 3. I se no problems in handling two dll’s

  7. Artem says:

    Option 3 looks the best of these, isn’t it what Client profile was designed for?

  8. Jarek Kowalski says:

    I’ve released a preview of NLog 2.0 which implements option #3. Check it out here:
    http://nlog-project.org/2010/03/12/first-preview-build-of-nlog-2-0-is-available.html

  9. Well, you went for Option 3…you can still provide a single assembly version as the result of an ILMerge…

  10. Frun says:

    Choice #3 is for the best.

  11. ano says:

    Option #3 Please.

Leave a Comment