Protecting class library DLL from design time use

Posted on 2006-04-11
Last Modified: 2011-10-03
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?
Question by:khooc
    LVL 1

    Assisted Solution

    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";
    LVL 3

    Accepted Solution

    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:
    This link include information about registry licensing, license file licensing and other methods.  You can download a sample application.
    Another usefull link:


    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    Suggested Solutions

    Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
    This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    This video discusses moving either the default database or any database to a new volume.

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now