softwaregreenhouses.com Blog

February 1, 2008

Handling .NET Assembly Licenses (.licx, .license) Dynamically at Runtime

Filed under: .LICX, ComponentModel, Licensing — Marty Nelson @ 10:30 pm

One of the frustrating things about the .NET licensing system is that although you can embed the licenses into a non-executable assembly, they will not be loaded and recognized at runtime.  The must also be embedded into the running executable.

This can be a real hassle if you are loading types dynamically from dll’s that may contained valid licensed third-party components.

After experimenting a bit, deugging through the LicenseManager, LicenseContext, and other .NET classes using the new nifty VS2008 source files, here is a simple solution that works.  And we didn’t even need to use Reflection :) .

It turns out that when you call GetSavedLicenseKey() on the statically scoped CurrentContext LicenseContext class, it actually reads the embedded licenses keys from the supplied resource assembly and stores them.

Assembly assembly = Assembly.LoadFrom(@”C:\Your\assembly\path”);

LicenseManager.CurrentContext.GetSavedLicenseKey(typeof(string), assembly);

Notice that the type doesn’t matter, it just needs to be a non-null value.  Of course if you have the type, you may end up writing something more like:

Type type = Type.GetType(typeName);

LicenseManager.CurrentContext.GetSavedLicenseKey(type, type.Assembly);

//This will not throw a licensing exception:

object instance = Activator.CreateInstance(typeName);

Enjoy…

January 13, 2008

Part II – Windows Controls Extensibility with .NET 3.5 CLR Add-Ins using WPF and Crossbow

Filed under: .NET 3.5 CLR AddIn, Crossbow, WPF — Marty Nelson @ 8:59 pm

In an earlier post, I described a method of hosting windows controls that relied on a hidden form on the add-in side that hosted the add-in control, but appeared in a designated area of the host form.

There has been continued interest in using CLR Add-Ins with Windows Form, see the CLR Team’s post Support for Windows Forms in Hosts and Add-Ins.

While it work well graphically, some of the more detailed integration of ALT+ and CTRL+ keys, tab order, etc. did not work entirely well.

Following the advice of the Jesse Kaplan at the Microsoft CLR Add-In team, I have created a new sample using WPF and Crossbow to handle the pseudo-marshalling of the windows control.

This example uses VS2005 and, other than the add-in pipeline itself, it is, from the perspective of the host and add-in developer, a *pure* Windows Forms experience.

>>Download Solution Here (more…)

November 10, 2007

Integrating Testers into the Agile Environment (James Shore @ XP PDX)

Filed under: Agile, Test-Driven Development, XP — Marty Nelson @ 6:24 pm

On October 24th, James Shore gave a presentation to the XP PDX group on testing in the agile environment.  This was part of a series of events Jim is giving in anticipation of his new book co-authored with Shane Warden, The Art of Agile Development.

By using XP practices as a defect prevention measure, defects are much lower than in traditional development environments and fewer tester resources are required.  Jim is seeing in projects that are using this type of agile defect prevention that:

  • Defects have been reduced to “a couple a month.”
  • The ratio of testers to programmers is 1:4, significantly lower than the 2:1 or 1.5:1 ratio seen in large development organizations.

Why It Works

XP agile engineering practices are a way to produce quality code by preventing defects as part of the software development process.  Jim sited two studies to support this position:    (more…)

October 20, 2007

Windows Controls Extensibility with .NET 3.5 CLR Add-Ins Using a “Leased-Space” Model

Filed under: .NET 3.5 CLR AddIn — Marty Nelson @ 3:52 pm

Please Read

I wrote this initial example before Jesse Kaplan suggested using WPF and Crossbow to implement Windows Control Add-in integration.  My newer post here describes this technique.  The approach below may still be valid if seen as a *lightweight* technique if the overhead of loading WPF is too great and Hot Key integration is not important.

UI Integration for Add-Ins 

With the release of .NET 3.5 Beta 2, Jack Gudenkauf touted the inclusion of the highly requested UI integration feature for System.AddIns, for WPF only.  While from a .NET 3.5 perspective it looks attractive to leave Windows Forms behind, the reality is that:

  1. Microsoft has done an excellent job making new .NET Framework versions additive and pseudo-backwards compatible, thus it has become easier to use the best of the new without needing to fully migrate to the bleeding edge.
  2. Windows Forms has been around a long time.  There’s plenty of legacy code, and perhaps more importantly, legacy developer skills.

Even with an eventually migration to WPF in the near-term future, I needed a Windows Form extensibility story now.   (more…)

Powered by WordPress