openGenericCERCall MDA

The openGenericCERCall managed debugging assistant is activated to warn that a constrained execution منطقة (CER) graph مع generic type متغيرات at the جذر method is being processed at JIT-compilation or أصلي image generation الوقت and at least one of the generic type متغيرات is an object مرجع type.

الأعراض

CER تعليمات برمجية does not تشغيل when a مؤشر ترابط هو aborted أو when an مجال تطبيق هو unloaded.

السبب

في وقت التحويل البرمجي JIT، يحتوي على كائن مثيل نوع المرجع لأنه ممثل فقط مشاركة تعليمات برمجية الناتجة، وعلى كل من الكائن نوع المرجع قد تكون المتغيرات أي كائن نوع المرجع. This can prevent the preparation of some تشغيل-الوقت موارد ahead of الوقت.

في وظائف معينة، بعامة متغيرات نوع يمكن ببط بتخصيص موارد في الخلفية. These are referred إلى كـ generic dictionary entries. For مثيل, for the كشف List<T> list = new List<T>(); الموقع T هو a generic نوع متغير the وقت التشغيل must بحث و possibly إنشاء the exact instantiation at تشغيل الوقت, for مثال, List<Object>, List<String>,و so forth. This can فشل for a variety of reasons beyond the developer's عنصر تحكم, such كـ تشغيل خارج of ذاكرة.

This MDA should فقط be activated at JIT-compilation الوقت, not when there هو an exact instantiation.

When this MDA هو activated, the likely symptoms are that CERs are not functional for the bad instantiations. في fact, the وقت التشغيل has not attempted إلى implement a CER under the circumstances that caused the MDA إلى be activated. So if the developer uses a shared instantiation of the CER, then JIT-compilation أخطاء, عام نوع تحميل أخطاء, أو مؤشر ترابط aborts within the منطقة of the intended CER are not caught.

الدقة

Do not استخدم generic نوع متغيرات that are of كائن مرجع نوع for وظائف that may contain a CER.

التأثير تشغيل وقت التشغيل

MDA هذا أي تأثير تشغيل CLR.

الإخراج

The following هو a نموذج of إخراج من this MDA.

Method 'GenericMethodWithCer', which contains at least one constrained execution region, cannot be prepared automatically since it has one or more unbound generic type parameters.

The caller must ensure this method is prepared explicitly at run time prior to execution.

method name="GenericMethodWithCer"

declaringType name="OpenGenericCERCall"

التكوين

<mdaConfig>
  <assistants>
    <openGenericCERCall/>
  </assistants>
</mdaConfig>

مثال

التعليمة البرمجية CER هو لم يتم تنفيذه.

using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;

class Program
{
    static void Main(string[] args)
    {
        CallGenericMethods();
    }
    static void CallGenericMethods()
    {
        // This call is correct. The instantiation of the method
        // contains only nonreference types.
        MyClass.GenericMethodWithCer<int>();

        // This call is incorrect. A shared version of the method that
        // cannot be completely analyzed will be JIT-compiled. The 
        // MDA will be activated at JIT-compile time, not at run time.
        MyClass.GenericMethodWithCer<String>();
    }
}

    class MyClass
{
    public static void GenericMethodWithCer<T>()
    {
        RuntimeHelpers.PrepareConstrainedRegions();
        try
        {

        }
        finally
        {
            // This is the start of the CER.
            Console.WriteLine("In finally block.");
        }
    }
}

راجع أيضًا:

المرجع

PrepareMethod

System.Runtime.ConstrainedExecution

المبادئ

تشخيص الأخطاء مع المساعدين التصحيح مدارة