Microsoft KB Archive/922274

= Error message when you add an ActiveX control to a Visual C# application: &quot;FileNotFoundException&quot; =

Article ID: 922274

Article Last Modified on 8/14/2006

-

APPLIES TO


 * Microsoft Visual Studio .NET 2003 Professional Edition
 * Microsoft Visual Studio .NET 2003 Enterprise Architect
 * Microsoft Visual Studio .NET 2003 Enterprise Developer
 * Microsoft Visual C# .NET 2003 Standard Edition

-





SYMPTOMS
When you add an ActiveX control to a Microsoft Visual C# application, you may receive an error message that resembles the following:

File not found: System.IO.FileNotFoundException: Could not find file 'C:\Program Files\Microsoft Visual Studio 7\Common7\IDE\Sample1.txt'.

File name: 'C:\Program Files\Microsoft Visual Studio 7\IDE\Sample1.txt'

at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)

at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)

at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)

at System.IO.StreamReader..ctor(String path) at MyNamespace.UserControl1..ctor in C:\VS Projects\UserControlTest\WindowsControlLibrary\UserControl1.cs:line 60

Additionally, you may receive the following error message in the Error List dialog box in the IDE:

The referenced component 'WindowsControlLibrary' could not be found.

This behavior occurs when you are developing the application in the IDE. When you run the application, the application correctly locates the file.



CAUSE
This behavior occurs because the application sets a property that returns the path of the Microsoft Visual Studio IDE executable file (Devenv.exe) at design time. However, at run time, the same property returns the path of the executable file that is in the application directory.



WORKAROUND
To work around this behavior, set the path of the assembly in the application. To do this, include the following code in the application. System.Reflection.Assembly [] group = AppDomain.CurrentDomain.GetAssemblies ; foreach (System.Reflection.Assembly x in group)

{    System.Reflection.AssemblyName name = x.GetName ;

// Set the name of the form here. if (name.Name == &quot;System.Windows.Forms&quot;)

// Set the path of the assembly here. MessageBox.Show (x.Location);



STATUS
This behavior is by design.

Keywords: kbexpertiseinter kberrmsg kbprb kbtshoot KB922274

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.