Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all articles
Browse latest Browse all 8156

mscorlib recursive resource lookup bug

$
0
0

Hi all,

I have an issue with a WindowsForms application, using .NET 4.0 running under Windows 7 on 32 bits. The application is started automatically at Windows start-up and it crashes with the stack trace attached below. Then, the application is started manually and it works fine.

Error stack trace

From the stack trace above I can see that we're logging something which will do:

StackTrace.ToString() (StackTrace.cs line 510, word_At = Environment.GetRuntimeResourceString("Word_At");)

=> ...  

=> Environment.ResourceHelper.GetResourceStringCode(..)

=> ...

=> Windows.Forms.Application.ThreadContext.OnThreadException(...) which throws another exception for unknown reasons

=> ...

=> StackTrace.ToString()

=> ...

=> Environment.ResourceHelper.GetResourceStringCode(..) line 215 Assert.Fail("[mscorlib recursive resource lookup bug]", message, Assert.COR_E_FAILFAST, System.Diagnostics.StackTrace.TraceFormat.NoResourceLookup);

I couldn't reproduce the issue described above, but I've made a test application and I could obtain the exception only in Debug with breakpoints in Environment.ResourceHelper.GetResourceStringCode method. The exception was not with "Resource name: Word_At" but with "Resource name: Arg_AccessViolationException".

Here's the stack trace that I've obtain in debug mode:


"

[Window Title]
StackTraceError.vshost.exe - Assert Failure

[Main Instruction]
StackTraceError.vshost.exe - Assert Failure

[Content]
Expression: [mscorlib recursive resource lookup bug]
Description: Infinite recursion during resource lookup within mscorlib.  This may be a bug in mscorlib, or potentially in certain extensibility points such as assembly resolve events or CultureInfo names.  Resource name: Arg_AccessViolationException

[Expanded Information]
Stack Trace:
   at System.Environment.ResourceHelper.GetResourceStringCode(Object userDataIn)
   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
   at System.Environment.ResourceHelper.GetResourceString(String key, CultureInfo culture)
   at System.Environment.GetResourceStringLocal(String key)
   at System.Environment.GetResourceFromDefault(String key)
   at System.AccessViolationException..ctor()
   at System.Environment.ResourceHelper.GetResourceStringCode(Object userDataIn)
   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
   at System.Environment.ResourceHelper.GetResourceString(String key, CultureInfo culture)
   at System.Environment.GetResourceStringLocal(String key)
   at System.Environment.GetResourceFromDefault(String key)
   at System.AccessViolationException..ctor()
   at System.Environment.ResourceHelper.GetResourceStringCode(Object userDataIn)
   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
   at System.Environment.ResourceHelper.GetResourceString(String key, CultureInfo culture)
   at System.Environment.GetResourceStringLocal(String key)
   at System.Environment.GetResourceFromDefault(String key)
   at System.AccessViolationException..ctor()
   at System.Environment.ResourceHelper.GetResourceStringCode(Object userDataIn)
   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
   at System.Environment.ResourceHelper.GetResourceString(String key, CultureInfo culture)
   at System.Environment.GetResourceStringLocal(String key)
   at System.Environment.GetResourceFromDefault(String key)
   at System.AccessViolationException..ctor()
   at System.Environment.ResourceHelper.GetResourceStringCode(Object userDataIn)
   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
   at System.Environment.ResourceHelper.GetResourceString(String key, CultureInfo culture)
   at System.Environment.GetResourceStringLocal(String key)
   at System.Environment.GetResourceFromDefault(String key)
   at System.AccessViolationException..ctor()
   at System.Environment.ResourceHelper.GetResourceStringCode(Object userDataIn)
   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
   at System.Environment.ResourceHelper.GetResourceString(String key, CultureInfo culture)
   at System.Environment.GetResourceStringLocal(String key)
   at System.Environment.GetResourceFromDefault(String key)
   at System.AccessViolationException..ctor()
   at System.Environment.GetResourceFromDefault(String key)
   at System.AccessViolationException..ctor()
   at System.Environment.ResourceHelper.GetResourceStringCode(Object userDataIn)
   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
   at System.Environment.ResourceHelper.GetResourceString(String key, CultureInfo culture)
   at System.Environment.GetResourceStringLocal(String key)
   at System.Environment.GetResourceFromDefault(String key)
   at System.AccessViolationException..ctor()
   at System.Environment.ResourceHelper.GetResourceStringCode(Object userDataIn)
   at System.Runt

"

The test application is a simple WindowsForms app, made with Visual Studio 2013, .NET 4.0 on Windows 7, 64 bits. Visual Studio 2013 ran with Admin rights.

In this application I've tried to follow the pattern that I've seen in the initial stack trace. StackTrace.ToString()... code ... another exception that leads to another StackTrace.ToString().

I've created a form with a button. On button handler I do a Trace.WriteLine.

Previously, I've registered a custom TraceListener that overrides WriteLine which calls base.WriteLine and then throws an exception that is caught and on catch I do another Trace.WriteLine.

Program.cs

static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Trace.Listeners.Add(new CustomTraceListener());

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }

Form.cs

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Trace.WriteLine("ex.ToString()");
        }
    }

CustomTraceListener.cs

public class CustomTraceListener : ConsoleTraceListener
    {
        private bool traced = false;

        public override void WriteLine(string message)
        {
            if (traced)
            {
                base.WriteLine(message);
                return;
            }

            try
            {
                traced = true;

                base.WriteLine(message);
                throw new ArgumentException("Test");
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.ToString());
            }
        }
    }

The issue seems related to this post but I cannot apply the same solution since the exception that triggers the second StackTrace.ToString() from the first stack trace, is thrown in Windows.Forms.Application and not my code.

Any ideas/advices/work-arounds are highly appreciated.

Thansk!





Viewing all articles
Browse latest Browse all 8156

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>