summaryrefslogtreecommitdiff
path: root/tests/src/Loader/classloader/regressions/dev11_95728/dev11_95728.cs
blob: 7c27539deb078276163a920b0bbf971d558f71b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

/* Regression Test for Dev11 bug #95728: LINQ/CLR :: Accessing a static generic field <String> causes CLR to crash with FatalExecutionEngineError
* 
* Comments from bug: FatalExecutionEngineError: The runtime has encountered a fatal error. The address of the error was at 0x71ff5dcd, 
* on thread 0x7f4. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user 
* code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.
*/

using System;
using System.Linq.Expressions;

namespace StaticFieldBug
{
    public class StubClass<T>
    {
        public StubClass(T value)
        {
            StubClass<T>.StaticField = value;
        }
        public static T StaticField = default(T);
        public static T StaticProperty
        {
            get { return StaticField; }
        }
    }
        
    class Program
    {
        static int Main(string[] args)
        {
            Foo<string>("Run me to crash LINQ...");
            
            Console.WriteLine("PASS (we didn't crash)!");
            return 100;
        }
        public static void Foo<T>(T value)
        {
            Expression<Func<int, T>> lambda;
            StubClass<T> foo = new StubClass<T>((T)value);
            lambda = i => StubClass<T>.StaticField;            
        }
    }
}