Bug when reflecting public method parameters of type Guid

.NET obfuscator and automated error reporting

Moderators: Luke Jefferson, melvyn.harbour, dom.smith

Bug when reflecting public method parameters of type Guid

Postby ribbles » Mon Sep 30, 2013 2:24 am

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:


Code: Select all
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:
Code: Select all
method:System.Action`1[System.Guid]
param:System.Guid arg1
RuntimeParameterInfo.DefaultValue:(null)
Success



Obfustcated result:
Code: Select all
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 ☻.♣.☺()
ribbles
 
Posts: 3
Joined: Mon Sep 30, 2013 2:09 am

Postby Chris.Allen » Tue Oct 01, 2013 12:20 pm

Can I take a wild guess that this was targeted for .Net 4.0 or above?

It seems OK for .net 3.5 which, is very strange, I know but may serve as a workaround?
Chris.Allen
 
Posts: 594
Joined: Thu Mar 12, 2009 4:17 pm

Postby ribbles » Thu Oct 03, 2013 10:57 am

Yes - 4.0
Unfortunately we are unable to target another version of the framework. Was the sample code adequate?
ribbles
 
Posts: 3
Joined: Mon Sep 30, 2013 2:09 am

Postby Chris.Allen » Thu Oct 03, 2013 12:12 pm

yes- the sample code shows the issue perfectly.

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.
Chris.Allen
 
Posts: 594
Joined: Thu Mar 12, 2009 4:17 pm

Any update on this issue?

Postby ribbles » Wed Feb 26, 2014 11:19 pm

It has been 5 months. Any updates?
ribbles
 
Posts: 3
Joined: Mon Sep 30, 2013 2:09 am

Postby mbrink » Fri Apr 18, 2014 1:03 pm

Any udates on this issue ?

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:

Code: Select all
{"Message":"An error has occurred.","ExceptionMessage":"An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)","ExceptionType":"System.BadImageFormatException","StackTrace":"   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 System.Web.Http.Internal.ParameterInfoExtensions.TryGetDefaultValue(ParameterInfo parameterInfo, Object& value)
at System.Web.Http.Controllers.ReflectedHttpParameterDescriptor.get_DefaultValue()
at System.Web.Http.ModelBinding.ModelBinderParameterBinding.ExecuteBindingAsync(ModelMetadataProvider metadataProvider, HttpActionContext actionContext, CancellationToken cancellationToken)
at System.Web.Http.Controllers.HttpActionBinding.<ExecuteBindingAsyncCore>d__0.MoveNext()\--- End of stack trace from previous location where exception was thrown ---


Thanks in advance.
mbrink
 
Posts: 1
Joined: Fri Apr 18, 2014 11:56 am

Postby Chris.Allen » Tue Apr 22, 2014 1:14 pm

No updates, sorry.
Chris.Allen
 
Posts: 594
Joined: Thu Mar 12, 2009 4:17 pm

We have the bug too

Postby emh » Tue Jun 10, 2014 10:24 am

We are getting the same error, using SmartAssembly v6.8.0.121 and .Net 4.5.1

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?
emh
 
Posts: 1
Joined: Tue Jun 10, 2014 10:17 am

Postby yauhen » Fri Jun 13, 2014 3:11 pm

We have the same problems in ASP.NET MVC with the same version of smart assembly.

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.
yauhen
 
Posts: 1
Joined: Fri Jun 13, 2014 3:08 pm


Return to SmartAssembly 6

Who is online

Users browsing this forum: No registered users and 0 guests