You receive an "System.ArgumentException" exception on a Microsoft Windows 98 operating system when you set the CurrentInputLanguage property (814740)



The information in this article applies to:

  • Microsoft Visual Basic 2005
  • Microsoft Visual Basic .NET (2003)
  • Microsoft Visual Basic .NET (2002)
  • Microsoft Visual C# .NET (2003)
  • Microsoft Visual C# .NET (2002)
  • the operating system: Microsoft Windows 98

SYMPTOMS

You set the CurrentInputLanguage property of the InputLanguage class in a console application or in a class library application. Your application does not show a form or a message box before it sets the property. When you run your application on a Microsoft Windows 98 operating system, you receive the following exception:
System.ArgumentException: This inputLanguage is not recognized by the system. Parameter name: value
at System.Windows.Forms.InputLanguage.set_CurrentInputLanguage(InputLanguage value)

CAUSE

When you set the CurrentInputLanguage property in your application, .NET runtime calls the ActivateKeyBoardLayout method in User32.dll. This method requires OLE to be initialized. ActivateKeyBoardLayout returns a null handle because OLE is not initialized for the current thread. Therefore, you receive an exception when you run the application on a Windows 98 operating system.

RESOLUTION

To resolve the problem as it is described in the "More Information" section of this article, follow these steps:
  1. In the Main procedure of Class1, add the following statement before the InputLanguage.CurrentInputLanguage property.

    Microsoft Visual Basic .NET or Microsoft Visual Basic 2005 Code
    'Initializes the OLE
    Application.DoEvents()
    Microsoft Visual C# .NET Code
    //Initializes the OLE
    Application.DoEvents();
  2. On the Build menu, click Build Solution.
  3. In Solution Explorer, expand Setup1.
  4. Right-click Primary output from ConsoleApplication1, and then click Remove.
  5. Install the setup project on the destination computer.

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce the Behavior


  1. In Microsoft Visual Studio .NET or in Microsoft Visual Studio 2005, start a new console application by using Visual Basic .NET, Visual Basic 2005, or Visual C# .NET.

    Note By default, Module1.vb is created in Visual Basic .NET or in Visual Basic 2005, and Class1.cs is created in Visual C# .NET.
  2. In Solution Explorer, right-click ConsoleApplication1, click Properties, and then click to select Configuration Properties.
  3. In the Configuration list box, click to select Release, and then click OK
  4. In Solution Explorer, right-click ConsoleApplication1, and then click Add Reference.
  5. Click the .NET tab, click to select System.Windows.Forms.dll, and then click Select.
  6. Replace the existing code with the following code in the Code editor.

    Visual Basic .NET or Visual Basic 2005 Code

    Replace the code in Module1 with the following code:
    Imports System
    Imports System.Windows.Forms
    Module Module1
        Sub Main()
            Try
                'Sets the input language for the current thread.
                InputLanguage.CurrentInputLanguage = InputLanguage.InstalledInputLanguages(0)
            Catch e As Exception
                'Displays the exception received.
                MsgBox(e.ToString())
            End Try
        End Sub
    End Module
    Visual C# .NET Code

    Replace the code in Class1 with the following code:
    using System;
    using System.Windows.Forms;
    class Class1
    {
        static void Main()
     {  
        try
        {
          //Sets the input language for the current thread.
          InputLanguage.CurrentInputLanguage =InputLanguage.InstalledInputLanguages [0];
        }
        catch(Exception e)
       {
           //Displays the exception received.
           MessageBox.Show(e.ToString());
       }
     }
    }
  7. On the Build menu, click Build Solution.
  8. On the File menu, point to Add Project, and then click New Project.
  9. Under Project Types, click to select Setup and Deployment Projects.

    Note In Visual Studio 2005, click to select Other Project Types, and then click Setup and Deployment.
  10. Under Templates, click to select Setup Project.

    By default, Setup1 is created.
  11. In Solution Explorer, click to select Setup1.
  12. On the View menu, point to Editor, and then click File System.
  13. Under File System on Target Machine, click to select Application Folder.
  14. On the Action menu, point to Add, and then click Project Output.
  15. In the Add Project Output Group dialog box, click to select Primary output.
  16. On the Build menu, click Build Setup1.
  17. On the Project menu, click Install.
  18. On the Welcome to the Setup1 Setup Wizard panel, click Next.
  19. On the Select Installation Folder panel, type the path where you want to install the setup folder in the Folder text box, and then click Next.
  20. On the Confirm Installation panel, click Next.
  21. Locate the Setup1 folder that you created. Copy the folder to a computer that runs the Windows 98 operating system.
  22. Right-click ConsoleApplication1, and then click Open.

    You receive the exception mentioned in the "Symptoms" section of this article.

Modification Type:MinorLast Reviewed:10/3/2006
Keywords:kbvs2005swept kbvs2005applies kbprb kbsetup kbDeployment kbForms kbWindowsForms kbInput KB814740 kbAudDeveloper