-1

I have a wpf application which will call a class library as a plugin to connect with wcf service every time. When call a service method in class library, it will give the above exception. And the exception message is er = {Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.}Even the stack trace also has the above message. What is the solution?

Barnee
  • 3,212
  • 8
  • 41
  • 53
Programmer
  • 390
  • 2
  • 17
  • Find out who is aborting threads and make them stop. Aborting threads is almost never a good idea. – usr Jul 28 '14 at 10:21
  • I don't abort any threads in program. Its automatically get aborted. – Programmer Jul 28 '14 at 10:27
  • Yeah, find out what component did this and why. Set the debugger to break on all exceptions and see where that exception is coming from. – usr Jul 28 '14 at 10:31
  • Voting to close because there is no information here to find the reason for this error. Add any required information and reopen. – usr Jul 28 '14 at 22:53
  • http://stackoverflow.com/questions/1472498/wpf-global-exception-handler – Stígandr Jul 29 '14 at 17:16

1 Answers1

1

I'm just guessing here, as you don't provide much code. But in your main application make sure to add the following eventhandlers;

DispatcherUnhandledException
AppDomain.CurrentDomain.UnhandledException
TaskScheduler.UnobservedTaskException

As also documented in this thread:

http://stackoverflow.com/questions/1472498/wpf-global-exception-handler

Log your exceptions with something like Log4net. Regarding WCF, all calls should be wrapped in a try catch block.

If your error is WCF related you can take your service's app.config file and add the following configuration:

<system.diagnostics>
<sources>
  <source name="System.ServiceModel"
          switchValue="Information, ActivityTracing"
          propagateActivity="true" >
    <listeners>
      <add name="xml"/>
    </listeners>
  </source>
  <source name="System.ServiceModel.MessageLogging">
    <listeners>
      <add name="xml"/>
    </listeners>
  </source>
  <source name="myUserTraceSource"
          switchValue="Information, ActivityTracing">
    <listeners>
      <add name="xml"/>
    </listeners>
  </source>
</sources>
<sharedListeners>
  <add name="xml"
       type="System.Diagnostics.XmlWriterTraceListener"
       initializeData="c:\temp\wcf.svclog" />
  </sharedListeners>

This will log all WCF activity to c:\temp\wcf.svclog which you may view using the tool SvcTraceViewer.exe located in your win sdk directory.

Hope it helps

Stian

Stígandr
  • 2,874
  • 21
  • 36