6

I have project with FiddlerApplication that saves some sessions for me. When I start the program first launch after restart 100% fails and then 10% fails 90% works.

The biggest problem that when it fails it doesn't catch any exceptions in try/catch. Here is my code

static class Program
{
    [STAThread]
    static void Main(string[] args)
    {
        try
        {
            browserToRun.GoTo("www.test.com"); 
            FiddlerApplication.AfterSessionComplete +=  FiddlerApplication_AfterSessionComplete;

            //HERE it fails
            FiddlerApplication.Startup(8888, true, true, true);
            FiddlerApplication.Shutdown();
        }
        catch (Exception ex)
        {
            // it is not getting to here
            FiddlerApplication.AfterSessionComplete -= FiddlerApplication_AfterSessionComplete;
            FiddlerApplication.Shutdown();
        }
    }

    public static void FiddlerApplication_AfterSessionComplete(Session sess)
    {
        try
        {
            if (!sess.fullUrl.Contains("test"))
            return;
            GlobalDownloadLink = sess.fullUrl;
        }
        catch (Exception ex)
        {
            successful = false;

            throw new System.ArgumentException(ex.Message, "FiddlerApplication_AfterSessionComplete");
        }
    }
}

My new Updated Apconfigwith new error Configuration System Failed to Initialize

<configuration>

  <runtime>
    <legacyCorruptedStateExceptionsPolicy enabled="true" />
  </runtime>
<configSections>

</configSections>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>

  <appSettings>
    <add key="BrowserShow" value="Y"/>
    <add key="DebugCreate" value="true"/>
    <add key="FileName10" value="AccountActivity"/>
    <add key="FileName20" value="ForeignActivities"/>
    <add key="FileNameShar" value="MatbeotSchirim"/>
  </appSettings>
</configuration>
Vladimir Potapov
  • 2,347
  • 7
  • 44
  • 71
  • What exception is being thrown? If you do not specify the exception (for example a `NullReferenceException e` catch), that will never be managed. – Ben May 28 '15 at 06:28
  • Additionally - I noticed you have a line `GlobalDownloadLink = sess.fullUrl;`. This is after your `return;` are you sure that's right? – Ben May 28 '15 at 06:31
  • By specifying Exception it doesn't catch every exception without distinction ? – Guillaume Beauvois May 28 '15 at 06:32
  • "What exception is being thrown?" This is the problem i have brakePoints all over the functions and catch it is just fails with out catch exception – Vladimir Potapov May 28 '15 at 06:39
  • "GlobalDownloadLink " yes it is right if fullUrl.Contains("test") i dont need the url – Vladimir Potapov May 28 '15 at 06:41

3 Answers3

7

Some Exceptions are not getting caught by try..catch blocks unless you specify the attribute [HandleProcessCorruptedStateExceptions] on the function (Main function in your code). Of couse, the same could be accomplished by modifying the config file as Oxoron described.

Peter Brennan
  • 1,366
  • 12
  • 28
  • 1
    one specifies this `[HandleProcessCorruptedStateExceptions]` attribute to catch `Exception` that corrupt the applications memory state, like a 'AccessViolationException`. – Amit Kumar Ghosh May 28 '15 at 06:30
  • Can you re-check if the exception is caugth or not, by adding a Console.Writeline? I also do not understand the purpose of re-throwing the exeption in the catch-block of FiddlerApplication_AfterSessionComplete... – Peter Brennan May 28 '15 at 07:13
  • i think i found the problem i have watIn object and it is thead and this FiddlerApplication is thear too,sow i need to seperate it to another class ,but thanx any way – Vladimir Potapov May 28 '15 at 08:12
  • 1
    @VovaPotapov , didn't understand what your real problem is, could you please describe your solution more? I guess you have separated FiddleApplicatio to an another class or something like that right? Having the same issue and Fiddler freezes my app so your answer will help me a lot. – Bahadir Tasdemir Sep 30 '16 at 08:27
6

Try to add <runtime> <legacyCorruptedStateExceptionsPolicy enabled="true" /> </runtime>

to the config file. Source here.

Community
  • 1
  • 1
Oxoron
  • 664
  • 1
  • 7
  • 26
1

One problem in your code is that you're throwing System.ArgumentException from the background thread on which Sessions are processed; such exceptions aren't going to be caught by an exception handler on your main thread.

Beyond that, the way your code is written right now is just wrong; calling Startup and then immediately calling Shutdown will do nothing useful.

EricLaw
  • 56,563
  • 7
  • 151
  • 196