Red Gate forums :: View topic - VB.Net CallByName problem with optional parameters
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

VB.Net CallByName problem with optional parameters

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



Joined: 09 Apr 2014
Posts: 3

PostPosted: Thu Apr 10, 2014 9:12 am    Post subject: VB.Net CallByName problem with optional parameters Reply with quote

Hi,

I've encountered a problem when calling an obfuscated vb.net 2012 DLL

Product: SmartAssembly standard v6.7.0.239 (also have the same issue with SmartAssembly Developer v6.8.0.121)


I'm making a late bound call to a public method with optional parameter(s)

When the call fails, the following error is returned:

"An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)"


Example method signature that fails:

Public Sub BrokenMethod(Optional ByVal badParameter As SqlConnection = Nothing)


I have identified that some optional parameter types (string and primitive types, from what I can tell) seem to be handled correctly. The issue seems to relate to more complex objects.



Any advice to address this issue would be gratefully received. We need to obfuscate our binaries before sending the out to customers and we use CallByName with optional parameters a lot.



Thanks,
Michael


---------------------------------------------



Sample code to replicate this error:


Code:

CallingApplication.vbproj
-------------------------

Module CallingModule

    Sub Main()
        Dim objExec As Object = LoadByName("Assembly1.dll", "Assembly1.Broken")
        Dim o As Object = CallByName(objExec, "BrokenMethod", CallType.Method)
    End Sub

    Public Function LoadByName( _
            ByVal assemblyName As String, _
            ByVal className As String) _
            As Object

        Try
            Dim assem1 As Reflection.Assembly = Reflection.Assembly.LoadFrom(assemblyName)
            Return assem1.CreateInstance(className)

        Catch ex As Exception
            Console.WriteLine("bad times...")
        End Try

        Return Nothing

    End Function

End Module



Assembly1.VBproj
----------------

Imports System.Data.SqlClient


Public Class Broken

    Public Sub New()

        Console.WriteLine("Broken::c'tor()")

    End Sub


    Public Sub BrokenMethod(Optional ByVal badParameter As SqlConnection = Nothing)

        Console.WriteLine("BrokenMethod() has been called")

        If badParameter Is Nothing Then

            badParameter = New SqlConnection()
        End If

    End Sub

End Class



---------------------------------------------
Back to top
View user's profile Send private message
Chris.Allen



Joined: 12 Mar 2009
Posts: 594

PostPosted: Fri Apr 11, 2014 11:15 am    Post subject: Reply with quote

H- truly sorry about this. There is a long-standing bug regarding optional parameters. Can you test without optional parameters. I can test too but it might take a little longer getting my environment set up.
Back to top
View user's profile Send private message
michaelP



Joined: 09 Apr 2014
Posts: 3

PostPosted: Fri Apr 11, 2014 11:25 am    Post subject: .net framework update Reply with quote

Hi,

I forgot to mention ... this issue doesn't appear to occur with framework 3.5.

Frameworks 4.0 and 4.5 do exhibit this unwanted behaviour

Thanks,
Michael
Back to top
View user's profile Send private message
michaelP



Joined: 09 Apr 2014
Posts: 3

PostPosted: Mon Apr 14, 2014 2:26 pm    Post subject: Re: Reply with quote

Hi Chris,

Thanks for your reply

Chris.Allen wrote:
H- truly sorry about this. There is a long-standing bug regarding optional parameters. Can you test without optional parameters. I can test too but it might take a little longer getting my environment set up.



Unfortunately we have quite a number of places where we use late bound optional parameters.
Just as unfortunately, we originally evaluated SmartAssembly using .net 3.5 and that was fine.

I think I'll see what Red Gate's support team say
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