"The invocation of the constructor on type 'TestWPF.MainWindow' that matches the specified binding constraints threw an exception."- how to fix this?

77,816

Solution 1

I fixed the problem by adding the below content in app.config,

<configuration> <startup useLegacyV2RuntimeActivationPolicy="true" /> </configuration>

I found this via a community addition by user FCAA below the article " Troubleshooting Exceptions: System.IO.FileLoadException" on MSDN.

Solution 2

If you click on View Detail... from the exception window you can look at the InnerException. Expand that node and you will see exactly what went wrong.

Solution 3

In my specific case, I was getting this because I had a few of my referencing assemblies mismatched between x64 and x86. Apparently I was binding to something that needed to be loaded by the runtime.

I mention this here as a reminder to check your build configurations if you've looked everywhere else!

Solution 4

The mentioned exeption is quite generic and you can receive it, for instance, when code fails in the constructor. I had a case of an IO exception that showed up with a similar text. Stepping into the code may provide hints to fix this that may not be obvious otherwise.

Solution 5

I got the same error and, after wasting about 2 hours with it, found that it is my SQL Server service that's not running. Not sure if this can ever help someone, but it did solve my problem to just start the service.

Share:
77,816
Abdul Ahad
Author by

Abdul Ahad

working with C#, ASP.NET, MVC, javascript, Angularjs, bootstrap, MS SQL Server, Android, Action Script 3, DevExpress .... love to face new challenges.

Updated on December 03, 2021

Comments

  • Abdul Ahad
    Abdul Ahad over 2 years

    I'm working with WPF. When I'm trying to declare SQLiteConnection in the code, the problem arises-

    The invocation of the constructor on type 'TestWPF.MainWindow' that matches the specified binding constraints threw an exception.
    
    InnerException: Make sure that the file is a valid .NET Framework assembly.
    

    can anyone tell me, how to fix it?