Red Gate forums :: View topic - Bug when reflecting public method parameters of type Guid
Return to www.red-gate.com RSS Feed Available

Search  | Usergroups |  Profile |  Messages |  Log in  Register 
Go to product documentation
SmartAssembly 6
SmartAssembly 6 forum

Bug when reflecting public method parameters of type Guid

Search in SmartAssembly 6 forum
Post new topic   Reply to topic
Jump to:  
Author Message
ribbles



Joined: 30 Sep 2013
Posts: 3

PostPosted: Mon Sep 30, 2013 2:24 am    Post subject: Bug when reflecting public method parameters of type Guid Reply with quote

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



Obfustcated result:
Code:
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 ☻.♣.☺()
Back to top
View user's profile Send private message
Chris.Allen



Joined: 12 Mar 2009
Posts: 586

PostPosted: Tue Oct 01, 2013 12:20 pm    Post subject: Reply with quote

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?
Back to top
View user's profile Send private message
ribbles



Joined: 30 Sep 2013
Posts: 3

PostPosted: Thu Oct 03, 2013 10:57 am    Post subject: Reply with quote

Yes - 4.0
Unfortunately we are unable to target another version of the framework. Was the sample code adequate?
Back to top
View user's profile Send private message
Chris.Allen



Joined: 12 Mar 2009
Posts: 586

PostPosted: Thu Oct 03, 2013 12:12 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
ribbles



Joined: 30 Sep 2013
Posts: 3

PostPosted: Wed Feb 26, 2014 11:19 pm    Post subject: Any update on this issue? Reply with quote

It has been 5 months. Any updates?
Back to top
View user's profile Send private message
mbrink



Joined: 18 Apr 2014
Posts: 1

PostPosted: Fri Apr 18, 2014 1:03 pm    Post subject: Reply with quote

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:
{"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.
Back to top
View user's profile Send private message
Chris.Allen



Joined: 12 Mar 2009
Posts: 586

PostPosted: Tue Apr 22, 2014 1:14 pm    Post subject: Reply with quote

No updates, sorry.
Back to top
View user's profile Send private message
emh



Joined: 10 Jun 2014
Posts: 1

PostPosted: Tue Jun 10, 2014 10:24 am    Post subject: We have the bug too Reply with quote

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?
Back to top
View user's profile Send private message
yauhen



Joined: 13 Jun 2014
Posts: 1

PostPosted: Fri Jun 13, 2014 3:11 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic All times are GMT + 1 Hour
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group