Bug when reflecting public method parameters of type Guid
ribbles
Posts: 4
Product: Smart Assembly Professional 6.8.0.121
This bug came up while using Microsofts WebAPI framework. It occurs when an interface method has either a Nullable<Guid> or Guid = default(Guid) parameter. Here is a console app to reproduce the issue:
Unobfustcated result:
Obfustcated result:
This bug came up while using Microsofts WebAPI framework. It occurs when an interface method has either a Nullable<Guid> or Guid = default(Guid) parameter. Here is a console app to reproduce the issue:
using System; using System.Reflection; namespace ObfustactionTest { [Obfuscation(Exclude=true)] class Program { static void Main() { var method = new Action<Guid>(MyMethod); Console.Write("method:"); Console.WriteLine(method); var param = method.Method.GetParameters()[0]; Console.Write("param:"); Console.WriteLine(param); Console.Write("RuntimeParameterInfo.DefaultValue:"); Console.WriteLine(param.DefaultValue ?? "(null)"); Console.WriteLine("Success"); Console.ReadLine(); } public static void MyMethod(Guid arg1 = default(Guid)) { Console.WriteLine(arg1); } } }
Unobfustcated result:
method:System.Action`1[System.Guid] param:System.Guid arg1 RuntimeParameterInfo.DefaultValue:(null) Success
Obfustcated result:
method:System.Action`1[System.Guid] param:System.Guid ☻ RuntimeParameterInfo.DefaultValue: Unhandled Exception: System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B) at System.Reflection.MetadataImport._GetDefaultValue(IntPtr scope, Int32 mdToken, Int64& value, Int32& length, Int32& corElementType) at System.Reflection.MdConstant.GetValue(MetadataImport scope, Int32 token, RuntimeTypeHandle fieldTypeHandle, Boolean raw) at System.Reflection.RuntimeParameterInfo.GetDefaultValueInternal(Boolean raw) at System.Reflection.RuntimeParameterInfo.GetDefaultValue(Boolean raw) at ☻.♣.☺()
Comments
It seems OK for .net 3.5 which, is very strange, I know but may serve as a workaround?
Unfortunately we are unable to target another version of the framework. Was the sample code adequate?
We seem to have an issue with default parameters generally- I have created a new bug but there were some existing bugs of this nature too.
I'm having the same problem with a .NET 4.5.1 targetted MVC / WebAPI project, so i'm unable to run this project through SmartAssembly.
The response i get calling a WebAPI method results in:
Thanks in advance.
Do you know how can I report this error to redgate? I have been told that redgate priorities errors due to the amount of reports submitted.
Anyone knows?
As far as I could see problem appears for us only in case of nullable parameters with default value null. So as workaround we just removed default null value.