Freigeben über


DA0012: Significant amount of Reflection

Applies to: yesVisual Studio noVisual Studio for Mac

Note

This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

Item Value
Rule Id DA0012
Category .NET Framework Usage
Profiling methods Sampling
Message You may be using Reflection excessively. It is an expensive operation.
Rule type Warning

Cause

Calls to the System.Reflection methods such as InvokeMember and GetMember or to Type methods such as MemberInvoke are a significant proportion of the profiling data. When possible, consider replacing these methods with early binding to the methods of dependent assemblies.

Rule description

Reflection is a flexible facility of the .NET Framework that can be used to perform late binding of your application to a dependent run-time Assembly or to create and dynamically execute new types during run-time. However, these techniques can decrease performance if they are used frequently or called in tight loops.

For more information, see the Reflection and Late Binding section of Chapter 5 — Improving Managed Code Performance in the Improving .NET Application Performance and Scalability volume of the Microsoft Patterns and Practices library on MSDN.

How to investigate a warning

Double-click the message in the Errors List window to navigate to the Function Details View of the profiling data. Examine the calling functions of the System.Type or System.Reflection method to find the sections of the program that make the most frequent use of .NET Reflection APIs. Avoid using methods that return metadata. When the performance of your application is critical, you might need to avoid using late binding and creating types dynamically at run-time.