Saturday, June 16, 2012

LinqDataSource Control "Exception has been thrown by the target of an invocation."

Symptom


  • You are running Visual Studio 2010 SP1
  • You have an ASP.NET web page
  • You have dragged the LinqDataSource onto the design surface
  • You try to Configure Data Source and get the following error message
 Exception has been thrown by the target of an invocation

Root Cause

  • Appears to be Related to .NET Framework 4.5 present (as a result of installing Visual Studio 2012).

Fixes That Would Not Work

I have tried the following and none worked. So you may not want to go down the same path.
  • Use devenv /Log to find out what's happening.: It will not log anything useful.
  • Start devenv in /Safemode.: No effect
  • Repair Visual Studio 2010
  • Uninstall Visual Studio 2010 (note if you do this you will have to apply SP1 which takes a long time)
  • Remove or Repair Sliverlight SDKs
  • Remove or Repair .NET Framework 4.5

Possible Fix If You Do Not Need VS 2012

The following steps fixed my situation. You do not need to uninstall SQL 2012 Express
  • Uninstall VS 2012
  • Uninstall .NET Framework 4.5
  • Uninstall .NET 4.0 Multi-Traget Pack
  • Using VS 2010 Installer, Perform the Repair of VS 2010

Workaround If You Need VS 2012

  • Try another machine or a VM you have not installed anything "2012" on it, you should be able to continue to work on LinqDataSource. Once the LinqDataSource is configured, check the code in and it should work on your "corrupted" environment, though you won't be able to change anything in the data source. You can still work with the Data Grid to which the data source is connected and do add/remove columns and such. You can manually edit the web page source code to change minor things like some query changes.
  • If you can safely move up to VS 2012, then the LinqDataSource will work perfectly fine there.







Post a Comment