System.IO.FileNotFoundException in C#

Hi All,

Iam trying to load a WPF on to Window Forms.
I have created a control created using XAML and I have the project compiled with the 'Output Type' as 'Class Library'.

I have another project that displays Windows Form.
Iam adding the dll of the WPF control in the add reference of this project.
(The directory structure is also fine.)

When I complie and run the project, i have the runtime error.

"System.IO.FileNotFoundException: Could not load file or assembly ' XXX, Version=1.0.3219.20825, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
File name: XXX, Version=1.0.3219.20825, Culture=neutral, PublicKeyToken=null'
at MainWindow_Load(Object sender, EventArgs e) "

The code of my Window_Load looks like this.

       private MyControls.Page1 wpfAddressCtrl;

        private void MainWindow_Load(object sender, EventArgs e)
            ctrlHost = new ElementHost();
            ctrlHost.Dock = DockStyle.Fill;
            wpfAddressCtrl = new MyControls.Page1(); //(Page1 is the class name in MyControls project)
            ctrlHost.Child = wpfAddressCtrl;

Could any one solve this problem.?

Thanks in Advance
Who is Participating?
yateeshConnect With a Mentor Author Commented:
I displayed the WPF user control directly instead of loading this on the form. and this helped me in serving my purpose.
thanks TechTiger007 for your comments.
Your application is trying to load the assembly"XXX" and it is unable to find it. Check if this assembly is in bin folder or GAC
yateeshAuthor Commented:
The assembly file 'xxx.dll' is present in my bin\Debug and bin\Release folder.
I didnt get what does "GAC" it compulsary to load here also.?
7 new features that'll make your work life better

It’s our mission to create a product that solves the huge challenges you face at work every day. In case you missed it, here are 7 delightful things we've added recently to monday to make it even more awesome.

do you have this dll in bin/debug and bin/release folder of the project that you are running?
GAC - global assembly cache, ie. c:\windows\assembly.
if you have the dll in bin folders then its fine you dont have to look in GAC
yateeshAuthor Commented:
No..the dll is in its own project folder(XXXProj).
But the project folder which iam running and the folder containing the project for 'xxx.dll' are in the same folder called "New Folder''.

NewFolder\NowRunnning  and  NewFolder\XXXProj.
Copy this dll to now running application's bin folder. Because now running application will look into its bin folder for the dlls
yateeshAuthor Commented:
Hi TechTiger007,

When I added the XXX.dll as the reference, the dll is automatically gets added  to the running application's 'bin' folder.
I also crossed checked and i could see that the XXX.dll is present in the running application's 'bin' folder.
So now we have the dll in bin folder but still visual studio gives this error. hmm.

Probably this could be due to the bug in visual studio.  Try to disable the binding exception as mentioned in the below link
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.