• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 294
  • Last Modified:

Protecting class library DLL from design time use

I'm currently developing a VB.NET class library DLL which I'm going to use with an application... however I want to protect others from referencing it and using it during design time.

Does anyone know of a way to do this?
2 Solutions
add one member variabe in  dll's class
 which will contain applications name
  whenever u use that dll u should provide application name in constructor
  if provided application name is application n name for which u want to give access to dll then only allow user to use this dll

class testdll
  private ApplicationName;
   public testdll(string Appname)
  public string MemberFun()
        return "U r not Allow to use this dll";
There are many ways to protect your components and to manage licenses.  I like to inherit from the LicenseProvider class because you can implement a simple code or a very complex algorithm.
You should read about the LicenseProvider class and it's implementation, but I will show you the general concepts to implement the class and the basic considerations you must have.

1.  Create a class that inherits from System.ComponentModel.LicenseProvider and override the GetLicense method.
How your component validates in DesignTime or Runtime it's up to you, but remember to throw an exception inside the GetLicense method when the code is not correct or the computer doesn't match the criteria or whatever your like.

For example:

Friend Class MyLicenser
     Inherits System.ComponentModel.LicenseProvider
   Public Overrides Function GetLicense(ByVal context As System.ComponentModel.LicenseContext, ByVal [type] As System.Type, ByVal instance As Object, ByVal allowExceptions As Boolean) As System.ComponentModel.License
    'Check the LicenseKey specified in step 2.
    'Returns true when the code is validated
   End Function

End Class


2. Create a public class to specify the LicenseKey to validate:
The user can change this licensekey and it is needed to validate your classes.
For example:

Public NotInheritable Class Licenser
      Private Shared mvarKey As String = String.Empty
      Public Shared Property LicenseKey() As String
                  Return mvarKey
            End Get
            Set(ByVal Value As String)
                  mvarKey = Value
            End Set
      End Property
End Class

'The implementation must be set before the user create your class, for example:
Public Sub New
      Dim control as MyUserControl
      control= New MyUserControl
End Sub

3. Implement the license to your class  
<LicenseProviderAttribute(GetType(MyLicenser))> Public NotInheritable Class MyUserControl
     Private _license As License = Nothing
     '**The license object must be validated in the constructor**
     Public Sub New()
          _license = LicenseManager.Validate(GetType(MyUserControl), Me)
          'An exception is thrown is the code is incorrect.
     End Sub

     '**The license object must be destroyed**
     Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
      If Not _license Is Nothing Then
         _license = Nothing
      End If
     End Sub
End Class

To read more information about licensing, see: http://www.developer.com/net/net/article.php/11087_3074001_1
This link include information about registry licensing, license file licensing and other methods.  You can download a sample application.
Another usefull link: http://msdn2.microsoft.com/en-US/library/fe8b1eh9(VS.80).aspx


Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Tackle projects and never again get stuck behind a technical roadblock.
Join Now