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.
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 == "System.Windows.Forms")
// Set the path of the assembly here.
MessageBox.Show (x.Location);