0
votes

We have an application (written in C# on .NET Framework 3.5) that is licensed using our custom licensing mechanism. In the current implementation, in each method we first check for if the machine has valid license or not. To me, it is little bit awkward. Is there any way to let the runtime check for the license before creating the object or excuting a method? Will writing a custom attribute solves this problem?

Any ideas or solutions are greatly appreciated.

Thank you, Suresh

3
You check for a licence at the begining of each and every method call (what about Properties? Those get compiled as methods after all). Why not just check once when the executable is first launched? Is there really a risk of the licence becoming invalid or tampered with while the program is running?FrustratedWithFormsDesigner
@FrustratedWithFormsDesigner I presume that this is intended to prevent people patching the assembly to skip the license checking code. Strongly naming an assembly should prevent a tampered version from running but I'm not sure if there are ways around that.Martin Smith
Thank you for the answers. My product is a WCF server and some services need license and some services are not. So whatever the services require the license we do check there for license. I am thinking of having a custom security attribute to decorate the class. Will that work?jaklucky

3 Answers

1
votes

Maybe static constructor will help you

0
votes

You can either check in main method/static constructor.

If it does not suit you (license is for year and it is a server which can be run years without restart - unlikely for Windows but still possible) check if AOP is not what you want. This would be a direct one-to-one refactoring (however much cleaner).

0
votes

Perhaps you could check to make sure that the person has a valid licence when the code is imported. Say, it will decrypt the libraries when the proper licence is there.