BUG: You receive a "does not implement interface member" compilation error message in a JLCA-converted Visual J++ project with a class that implements java.io.Serializable (814903)



The information in this article applies to:

  • Microsoft Visual J++ 6.0
  • Microsoft Visual C# .NET (2003)
  • Microsoft Visual C# .NET (2002)
  • Microsoft Visual J++ 1.0

SYMPTOMS

You may receive the following error message:
'Class Name' does not implement interface member 'System.Runtime.Serialization.ISerializable.GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)'
You may receive this error message if all the following conditions are true:
  • You have a Visual J++ project with a class that implements the java.io.Serializable interface.
  • You convert your Visual J++ project to a Visual C# .NET project by using the Java Language Conversion Assistant (JLCA).
  • You try to compile the generated Visual C# .NET project.

CAUSE

In the Microsoft .NET Framework, the equivalent for the java.io.Serializable interface is the System.Runtime.Serialization.ISerializable interface. However, when you convert the Visual J++ project, JLCA does not add the implementation for the GetObjectData method of the ISerializable interface.

WORKAROUND

To work around this problem, implement the GetObjectData method in the generated Visual C# .NET class. To do so, follow these steps after you convert the Visual J++ project based on the steps in the "Steps to Reproduce the Behavior" section of this article:
  1. On the View menu, click Class View.
  2. In the Class View pane, expand the following nodes:
    • MyVJTestApplication
    • Employee
    • Bases and Interfaces
  3. Right-click ISerializable, point to Add, and then click Implement Interface.
Note A default implementation is added to the GetObjectData method in step 6 of the steps in the "Steps to Reproduce the Behavior" section of this article. You may not receive any compilation errors when you add the default implementation. However, you may add required information to the SerializationInfo object.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

In the .NET Framework, you can mark any class that may be serialized with the SerializableAttribute class. However, if a class controls the serialization process, the class implements the ISerializable interface. The Formatter calls the GetObjectData method during serialization and populates the supplied serialization information with all the required data to represent the object.

Steps to Reproduce the Behavior

  1. Start Visual J++ 6.0.
  2. On the File menu, click New Project.
  3. On the New tab, expand Visual J++ Projects, and then click Applications.
  4. In the right pane, click Console Application.
  5. In the Name box, type MyVJTestApplication, and then click Open.
  6. Replace the existing code with the following code for Class1.java:
    import java.util.*;
    import java.io.*;
    
    // Class that implements the Serializable interface
    class Employee implements Serializable
    {
    	private int empId;
    	private String name;
    	private int basicSalary;
    	
    	// Default constructor
    	// It is not a good idea to use this constructor.
    	// Always use the constructor with three parameters.
    	public Employee()
    	{
    	}
    	
    	// A constructor with three parameters
    	public Employee(int empId, String name, int basicSalary)
    	{
    		this.empId = empId;
    		this.name = name;
    		this.basicSalary = basicSalary;
    	}
    	
    	// A Setter method to set BasicPay
    	public void SetBasic(int newBasic)
    	{
    		this.basicSalary = newBasic;
    	}
    	
    	// A Print method to display the details of the Employee
    	public void PrintDetails()
    	{
    		System.out.println("Employee ID       : "+ empId);
    		System.out.println("Employee Name     : "+ name);
    		System.out.println("Employee Basic Pay: "+ basicSalary);
    	}
    	
    }
    
    //A class with the Main method
    public class Class1
    {
    	public static void main(String[] args)
    	{
    		Employee employee = new Employee(80366, "Peter", 3700);
    		employee.PrintDetails();
    	}
    }
    
  7. On the File menu, click Save All.
  8. Quit Visual J++.
  9. Start Microsoft Visual Studio .NET 2003.
  10. On the File menu, point to Open, and then click Convert.
  11. Click Java Language Conversion Assistant in the Available Converters list, and then click OK.
  12. Follow the instructions in JLCA Wizard to convert the Visual J++ project that you created earlier in these steps.
  13. On the Build menu, click Build Solution. You receive the compilation error message that is listed in the "Symptoms" section of this article.

REFERENCES

For more information about the Java Language Conversion Assistant (JLCA), visit the following Microsoft Developer Network (MSDN) Web site:

Modification Type:MinorLast Reviewed:1/19/2006
Keywords:kberrmsg kbCodeGen kbconvert kbSerial kbJava kbbug KB814903 kbAudDeveloper