Microsoft KB Archive/826009

= BUG: &quot;System.MissingMethodException&quot; error message when you try to build an application that hosts a licensed class =

Article ID: 826009

Article Last Modified on 2/1/2006

-

APPLIES TO


 * Microsoft .NET Framework 1.1
 * Microsoft .NET Framework 1.0
 * Microsoft Visual C# .NET 2003 Standard Edition
 * Microsoft Visual C# .NET 2002 Standard Edition
 * Microsoft Visual C++ .NET 2003 Standard Edition
 * Microsoft Visual C++ .NET 2002 Standard Edition
 * Microsoft Visual Basic .NET 2003 Standard Edition
 * Microsoft Visual Basic .NET 2002 Standard Edition

-





SYMPTOMS
If you try to build an application that hosts a licensed class, and the application does not have a default (parameter-less) constructor, you receive an error message that is similar to the following:

Could not transform licenses file 'licenses.licx' into a binary resource. (1) : error LC0004 : Exception occured creating type 'System.MissingMethodException'

Note In this error message, the word &quot;occured&quot; is a misspelling of the word &quot;occurred.&quot;



RESOLUTION
To resolve this problem, add a default (parameter-less) constructor to the licensed class and then rebuild the licensed class library.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the &quot;Applies to&quot; section.



MORE INFORMATION
To embed a license key of a class library in Microsoft Visual Studio .NET, you must define a default public constructor in the class library. This default constructor is used only for licensing. If the licensed class has no default constructor, you receive a &quot;MissingMethodException&quot; error message when you compile an application that includes the licenses.licx file.

Note You must manually create the licenses.licx file.

Create a licensed class
 Start Visual Studio .NET. On the File menu, point to New, and then click Project. In the New Project dialog box, click Visual C# Projects under Project Types, and then click Class Library under Templates. In the Name text box, type LicensedClass, and then click OK. By default, Class1.cs is created. In Solution Explorer, right-click Class1.cs, and then click Rename. Type LicensedClass.cs for the new file name.</li>  In the LicensedClass.cs file, replace the existing code with the following sample code: using System; using System.ComponentModel;

namespace Licensing {   ///     /// Summary description for LicensedClass. ///    ///     [LicenseProviderAttribute(typeof(LicFileLicenseProvider))] public class LicensedClass : IDisposable {       private License license = null;

//     Uncomment the following code to resolve the error. //     public LicensedClass //     { //          license = LicenseManager.Validate(typeof(LicensedClass), this); //     }

public LicensedClass(int i)       { license = LicenseManager.Validate(typeof(LicensedClass), this); Console.WriteLine(&quot;Hello from the licensed class.&quot;); }

public void Dispose {           if (license != null) {               license.Dispose; license = null; }       }    } } </li> In Solution Explorer, right-click LicensedClass, point to Add, and then click Add New Item.</li> In the Add New Item - LicensedClass dialog box, click Text File under Templates, and then click Open.</li> In Solution Explorer, rename the new text file Licensing.LicensedClass.lic. In the Microsoft Development Environment message box, click Yes to rename the file.</li> In Solution Explorer, click Licensing.LicensedClass.lic, and the press F4 to open the Properties window.</li> In the drop-down list box for the Build Action property, click Embedded Resource.</li> Paste the following text in the Licensing.LicensedClass.lic file:

Licensing.LicensedClass is a licensed component.

</li> Save all the files in the LicensedClass project, and then build the project.</li></ol>

Note You must put the LIC file of the class library into the same folder as the assembly DLL file. If the reference is a project reference, the LIC file should be included in the obj\bin folder. If it is a file reference, it should be included in the debug\bin or release\bin folder.

Create a host for the licensed class
<ol> In Visual Studio .NET, create a Visual C# .NET Console Application project that is named LicensedClassHost .</li> In Solution Explorer, right-click Class1.cs, and then click Rename.</li> Type LicensedClassHost.cs for the new file name.</li>  In the LicensedClassHost.cs file, replace the existing code with the following sample code: using System; using System.ComponentModel; // If the following statement causes a compiler error, add a project reference to // the LicensedClass.dll file. LicensedClass.dll is located in the LicensedClass\bin\debug folder. using Licensing;

namespace LicensingHost {   ///     /// Summary description for LicensedClassHost. ///    class LicensedClassHost {       static void Main(string[] args) {           int i = 0; LicensedClass LicensedClass1 = new LicensedClass(i); }   } } </li> In the LicensedClassHost project, add a project reference to the LicensedClass.dll file that you created in the &quot;Create a Licensed Class&quot; section of this article.</li> In Solution Explorer, right-click LicensedClassHost, point to Add, and then click Add New Item.</li> In the Add New Item - LicensedClassHost dialog box, click Text File under Templates, and then click Open.</li> <li>In Solution Explorer, rename the new text file licenses.licx. In the Microsoft Development Environment message box, click Yes to rename the file.</li> <li>In Solution Explorer, click licenses.licx, and the press F4 to open the Properties window.</li> <li>In the drop-down list box for the Build Action property, click Content.</li> <li>Paste the following text in the licenses.licx file:

Licensing.LicensedClass,LicensedClass

</li> <li>Save all the files in the LicensedClassHost project, and then build the project.</li> <li></li></ol>

Note You must put the LIC file of the class library into the same folder as the assembly DLL file. If the reference is a project reference, the LIC file should be included in the obj\bin folder. If it is a file reference, it should be included in the debug\bin or release\bin folder.

<div class="references_section">