Evaluation requires a thread to run temporarily. Use the Watch window to perform the evaluation
Asked Answered
C

4

18

I'm completely stuck. I'm testing MetaTrader API and getting next error when tries to run a method in the Immediate Window of VS 2010:

A first chance exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll

A first chance exception of type 'System.Threading.ThreadAbortException' occurred in System.Runtime.Remoting.dll

Evaluation requires a thread to run temporarily. Use the Watch window to perform the evaluation.

What does it mean? Can it happens because of runtime versions difference (api 2.0, app 4.0)?

Cacia answered 25/11, 2010 at 20:20 Comment(0)
C
0

That's because the server is running under .NET 2.0 and a client (thru .NET Remoting) - under .NET 4.0.

Switching client to .NET 2.0/3.5 fixed the problem.

Cacia answered 10/2, 2011 at 10:37 Comment(0)
S
7

I believe the method you are calling through the Immediate Window ends up calling Debugger.NotifyOfCrossThreadDependency. This method was only introduced in .NET 4.0, so it makes sense that the problem won't reproduce itself when using an older version of the runtime. This blog post explains NotifyOfCrossThreadDependency in detail, but the gist of it is that it causes the Watch window to show a Refresh button which must be pressed before the evaluation occurs. If it is evaluated through the Immediate Window, though, you get the "Evaluation requires a thread to run temporarily. Use the Watch window to perform the evaluation" error.

Here's an example property that reproduces this error:

    public int CauseError
    {
        get 
        {                
            Debugger.NotifyOfCrossThreadDependency();
            return 5;
        }
    }
Scraperboard answered 8/12, 2013 at 13:37 Comment(1)
Following the advice in the error, I copy the method I'm calling in the Immediate Window to the Watch window, But then I get a dialog saying: "To prevent an unsafe abort when evaluating the function 'OpenQA.Selenium.Remote.RemoteWebDriver.FindElementByClassName' all threads were allowed to run. This may have changed the state of the process and any breakpoints encountered have been skipped.". Then I see this in the Watch window: "The function evaluation requires all threads to run.". Am I doing something wrong or the error message in question is misleading? How do I evaluate this method call?Dogwatch
G
6

I believe that error means that the method you are trying to execute is spawning a thread. However, since the program is in Break mode, it can't run. To avoid a deadlock (where the method will wait forever for a thread that won't run), Visual Studio kills any spawned threads.

My suggestion is to move the call into the program, and use some other means to execute it.

Gamopetalous answered 25/11, 2010 at 21:12 Comment(4)
Sounds promising, but I did a test and found: this occurs only if app is targeted 4.0, nothing like that in case of 2.0/3.5! How can it be? Different thread/thread debug model?Cacia
Could be. Honestly, I have very little knowledge of how VS debugs the .NET runtime. Maybe this threading situation was permitted in 3.5, but for whatever reason was deemed dangerous in 4.0? shrug Sorry I can't be more helpful...Gamopetalous
Thanks anyway for interesting assumption and suggestion! :)Cacia
@MikeCaron I don't think that's the case: If I evaluate public int StartNewThread { get { new Thread(new ThreadStart(() => Console.WriteLine())).Start(); return 5; } } through the Immediate Window, it works fine without giving this error.Scraperboard
C
0

That's because the server is running under .NET 2.0 and a client (thru .NET Remoting) - under .NET 4.0.

Switching client to .NET 2.0/3.5 fixed the problem.

Cacia answered 10/2, 2011 at 10:37 Comment(0)
T
-2

do not remove the app.config which will contain information like follows:

<configuration>
  <configSections>
    <sectionGroup name="userSettings" 
                  type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
      <section 
               name="MySolution.Properties.Settings"
               type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 
               allowExeDefinition="MachineToLocalUser" 
               requirePermission="false" />
    </sectionGroup>
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
</configuration>
Transcendentalistic answered 30/10, 2011 at 9:52 Comment(1)
What exactly you think will fix that? supportedRuntime section?Cacia

© 2022 - 2024 — McMap. All rights reserved.