-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathBadDynamicCall.qhelp
More file actions
33 lines (26 loc) · 1.19 KB
/
BadDynamicCall.qhelp
File metadata and controls
33 lines (26 loc) · 1.19 KB
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
<!DOCTYPE qhelp PUBLIC
"-//Semmle//qhelp//EN"
"qhelp.dtd">
<qhelp>
<overview>
<p>Method calls on variables declared with type 'dynamic' are resolved at runtime rather than
compile-time - the actual type of the instance is determined, and an attempt is made to call a
method on that type with the appropriate signature. If such a method does not exist, a <code>
RuntimeBinderException</code> is thrown.</p>
<p>This rule identifies calls to instances with the <code>dynamic</code> type where it can be
statically determined that the call will throw a <code>RuntimeBinderException</code>.</p>
</overview>
<recommendation>
<p>Ensure it is not possible to make a call to a dynamic instance of a type that lacks the
appropriate method signature for handling that call.</p>
</recommendation>
<example>
<p>In this example the program attempts to call <code>Foo</code> on a class that doesn't have a
<code>Foo</code> method. This program is guaranteed to fail at runtime with a <code>
RuntimeBinderException</code>.</p>
<sample src="BadDynamicCall.cs" />
</example>
<references>
<li>MSDN: <a href="http://msdn.microsoft.com/en-gb/library/dd264741.aspx">dynamic (C# Reference)</a>.</li>
</references>
</qhelp>