BUG: "System.MissingMethodException" error message when you try to build an application that hosts a licensed class (826009)



The information in this article applies to:

  • Microsoft .NET Framework 1.1
  • Microsoft .NET Framework 1.0
  • Microsoft Visual C# .NET (2003)
  • Microsoft Visual C# .NET (2002)
  • Microsoft Visual C++ .NET (2003)
  • Microsoft Visual C++ .NET (2002)
  • Microsoft Visual Basic .NET (2003)
  • Microsoft Visual Basic .NET (2002)

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 "occured" is a misspelling of the word "occurred."

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 "Applies to" 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 "MissingMethodException" error message when you compile an application that includes the licenses.licx file.

Note You must manually create the licenses.licx file.

Steps to reproduce the behavior

Create a licensed class

  1. Start Visual Studio .NET.
  2. On the File menu, point to New, and then click Project.
  3. In the New Project dialog box, click Visual C# Projects under Project Types, and then click Class Library under Templates.
  4. In the Name text box, type LicensedClass, and then click OK. By default, Class1.cs is created.
  5. In Solution Explorer, right-click Class1.cs, and then click Rename.
  6. Type LicensedClass.cs for the new file name.
  7. In the LicensedClass.cs file, replace the existing code with the following sample code:
    using System;
    using System.ComponentModel;
    
    namespace Licensing
    {
    	/// <summary>
    	/// Summary description for LicensedClass.
    	/// </summary>
    	/// 
    	[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("Hello from the licensed class.");
    		}
    
    		public void Dispose() 
    		{
    			if (license != null) 
    			{
    				license.Dispose();
    				license = null;
    			}
    		}
    	}
    }
    
  8. In Solution Explorer, right-click LicensedClass, point to Add, and then click Add New Item.
  9. In the Add New Item - LicensedClass dialog box, click Text File under Templates, and then click Open.
  10. In Solution Explorer, rename the new text file Licensing.LicensedClass.lic. In the Microsoft Development Environment message box, click Yes to rename the file.
  11. In Solution Explorer, click Licensing.LicensedClass.lic, and the press F4 to open the Properties window.
  12. In the drop-down list box for the Build Action property, click Embedded Resource.
  13. Paste the following text in the Licensing.LicensedClass.lic file:

    Licensing.LicensedClass is a licensed component.

  14. Save all the files in the LicensedClass project, and then build the project.
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

  1. In Visual Studio .NET, create a Visual C# .NET Console Application project that is named LicensedClassHost.
  2. In Solution Explorer, right-click Class1.cs, and then click Rename.
  3. Type LicensedClassHost.cs for the new file name.
  4. 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>
    	/// Summary description for LicensedClassHost.
    	/// </summary>
    	class LicensedClassHost
    	{
    		static void Main(string[] args)
    		{
    			int i = 0;
    			LicensedClass LicensedClass1 = new LicensedClass(i);
    		}
    	}
    }
    
  5. In the LicensedClassHost project, add a project reference to the LicensedClass.dll file that you created in the "Create a Licensed Class" section of this article.
  6. In Solution Explorer, right-click LicensedClassHost, point to Add, and then click Add New Item.
  7. In the Add New Item - LicensedClassHost dialog box, click Text File under Templates, and then click Open.
  8. In Solution Explorer, rename the new text file licenses.licx. In the Microsoft Development Environment message box, click Yes to rename the file.
  9. In Solution Explorer, click licenses.licx, and the press F4 to open the Properties window.
  10. In the drop-down list box for the Build Action property, click Content.
  11. Paste the following text in the licenses.licx file:

    Licensing.LicensedClass,LicensedClass

  12. Save all the files in the LicensedClassHost project, and then build the project.
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.

REFERENCES

For more information, visit the following Microsoft Web site:

Modification Type:MinorLast Reviewed:2/1/2006
Keywords:kbvs2005swept kbvs2005doesnotapply kbvs2002sp1sweep kberrmsg kbLicensing kbConsole kbbug KB826009 kbAudDeveloper