This error message popped up after the Lightswitch 2011 application was deployed on a new server and when the application was started for the first time. The default screen comes up, but without data in the screen, then the messagebox with the error:
An error occurred while running the screen.
Error details: Exception has been thrown by the target of an invocation.
After clicking ‘Close Screen’ a second messagebox pops up with the message:
Invalid operation. Dispatcher has been stopped.
The problem in this case is not as much correcting the error, but finding out what the error actually is. To do so we need to turn diagnostics on
To diagnose this kind of error in Lightswitch, diagnostics needs to be enabled. See the MSDN article How to: Enable Diagnostics
Since this problem did not occur on my development computer, but after deployment on the new Windows Server, we can turn the diagnostics on in the server without redeploying the solution. Either way do not forget to switch diagnostics off on the server once the cause of the error has been found.
To enable diagnostics on the server
The diagnostics feature will generate a Trace.axd file in the directory where the app is deployed.
- Use IIS Manager and connect remotely or log on to the server and start IIS Manager on the server.
- In the Connections treeview, under <your server>/sites/Default Web site/<your app>
- In the features view, click on Application Settings
- In the Application settings pane, change Microsoft.LightSwitch.Trace.Enabled to true,
- Set …trace.Lavel to Error
- Set …trace.LocalOnly to false. If you leave this to true then you can only browse on the server to localhost to look at the diagnostics, in my case security settings on the server browser did not allow me to do this. So when set to false I can browse the trace file from the client PC.
- This is the Applications settings panel after applying the changes
- On the client PC browse to the app to invoke the error once more.
- Then browse to the same URL with the trace file name appended http://myserver/myapp/Trace.axd
- The last line of the trace log most probably contains the error information (in my case it did). Click on the view details link to open.
- The error shows that there is a SQLconnection problem.
finally the solution was that the SQLserver could not be connected from the new app server unless the full domain name was used. I fixed the connection string in visual studio accordingly and all worked fine.