Mono.Cecil bug with parameter constants?

16 views
Skip to first unread message

Dave

unread,
Jun 15, 2009, 4:04:38 PM6/15/09
to mono-cecil
I have an assembly containing a class with a function of this
signature (VB):

Public Overridable Function GetAccounts(ByRef Optional
UseSingleAccount As Boolean = False) As String()

Whenever I modify the assembly with Mono.Cecil 0.6, the parameter
constant (False) gets lost. The new signature (disassembled using
Reflector) looks like this:
Public Overridable Function GetAccounts(ByRef Optional
UseSingleAccount As Boolean = Nothing) As String()

This is true even if I do not modify anything about the assembly
(i.e., just call AssemblyFactory.GetAssembly then
AssemblyFactory.SaveAssembly, without anything in between).

Additionally, Visual Studio gives me this error when I try to override
the function:

'Public Overrides Function GetAccounts([ByRef UseSingleAccount As
Boolean = False]) As String()' cannot override 'Public Overridable
Function GetAccounts([ByRef UseSingleAccount As Boolean = Nothing]) As
String()' because they differ by the default values of optional
parameters.

If I change my overriding signature to use Nothing as the parameter
constant, Visual Studio crashes.

Is this a known bug with Mono.Cecil?

Thanks,
Dave

Dave

unread,
Jun 15, 2009, 5:38:38 PM6/15/09
to mono-cecil
I have some more information on this behavior. I dug around through
the source code. In ReflectionWriter.GetCorrespondingType, the
fullName parameter gets compared to a list of constants. If the
parameter is passed by reference, it will have an ampersand at the end
of its fullName, so it will not match any of the constants.

I added this line to the top of the GetCorrespondingType function, and
it seems to fix the problem.
fullName = fullName.TrimEnd('&');

Please let me know if you agree that this is a bug, and if this is an
OK way to fix it.

Thanks!
Dave
Reply all
Reply to author
Forward
0 new messages