Microsoft KB Archive/814740

= You receive an &quot;System.ArgumentException&quot; exception on a Microsoft Windows 98 operating system when you set the CurrentInputLanguage property =

Article ID: 814740

Article Last Modified on 11/14/2007

-

APPLIES TO


 * Microsoft Visual Basic 2005
 * Microsoft Visual Basic .NET 2003 Standard Edition
 * Microsoft Visual Basic .NET 2002 Standard Edition
 * Microsoft Visual C# .NET 2003 Standard Edition
 * Microsoft Visual C# .NET 2002 Standard Edition
 * Microsoft Windows 98 Standard Edition

-





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 &quot;More Information&quot; section of this article, follow these steps:   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;  On the Build menu, click Build Solution. In Solution Explorer, expand Setup1. Right-click Primary output from ConsoleApplication1, and then click Remove. Install the setup project on the destination computer.

<div class="status_section">

STATUS
This behavior is by design.

<div class="moreinformation_section">

Steps to Reproduce the Behavior
 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.</li> In Solution Explorer, right-click ConsoleApplication1, click Properties, and then click to select Configuration Properties.</li> In the Configuration list box, click to select Release, and then click OK</li> In Solution Explorer, right-click ConsoleApplication1, and then click Add Reference.</li> Click the .NET tab, click to select System.Windows.Forms.dll, and then click Select.</li>  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); } } } </li> On the Build menu, click Build Solution.</li> On the File menu, point to Add Project, and then click New Project.</li> 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.</li> Under Templates, click to select Setup Project.

By default, Setup1 is created.</li> In Solution Explorer, click to select Setup1.</li> On the View menu, point to Editor, and then click File System.</li> Under File System on Target Machine, click to select Application Folder.</li> On the Action menu, point to Add, and then click Project Output.</li> In the Add Project Output Group dialog box, click to select Primary output.</li> <li>On the Build menu, click Build Setup1.</li> <li>On the Project menu, click Install.</li> <li>On the Welcome to the Setup1 Setup Wizard panel, click Next.</li> <li>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.</li> <li>On the Confirm Installation panel, click Next.</li> <li>Locate the Setup1 folder that you created. Copy the folder to a computer that runs the Windows 98 operating system.</li> <li>Right-click ConsoleApplication1, and then click Open.

You receive the exception mentioned in the &quot;Symptoms&quot; section of this article.</li></ol>

<div class="references_section">