VB.Net CallByName problem with optional parameters

.NET obfuscator and automated error reporting

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

VB.Net CallByName problem with optional parameters

Postby michaelP » Thu Apr 10, 2014 9:12 am

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: Select all
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



---------------------------------------------
michaelP
 
Posts: 3
Joined: Wed Apr 09, 2014 10:22 am

Postby Chris.Allen » Fri Apr 11, 2014 11:15 am

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

.net framework update

Postby michaelP » Fri Apr 11, 2014 11:25 am

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
michaelP
 
Posts: 3
Joined: Wed Apr 09, 2014 10:22 am

Re:

Postby michaelP » Mon Apr 14, 2014 2:26 pm

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
michaelP
 
Posts: 3
Joined: Wed Apr 09, 2014 10:22 am


Return to SmartAssembly 6

Who is online

Users browsing this forum: No registered users and 1 guest