We help IT Professionals succeed at work.
Get Started

Running .NET assembly in memory

1,840 Views
Last Modified: 2012-05-07
I am trying to create an executable wrapper for vb.net. I have the following code:

But it doesn't work. The application I want to execute is a vb.net application. It is an embedded resource. But I get the following error:

TargetParameterCountException was Unhandled
Parameter count mismatch.

On this line:
 ExeAssembly.EntryPoint.Invoke(Nothing, Nothing) 'no parameters

What's the problem?  Thanks!

Private Sub RunInternalExe(ByVal exeName As String)
        'Get the Current Assembly information     
        Dim CurrentAssembly As Reflection.Assembly = Reflection.Assembly.GetExecutingAssembly()
 
        'Resource will store the full name of our embeded dpe.exe resource file     
        Dim Resource As String = String.Empty
 
        'Get all resource names and find the full embeded dpe.exe resource file name     
        Dim ArrResources As String() = CurrentAssembly.GetManifestResourceNames()
        For Each Resource In ArrResources
 
            If Resource.IndexOf(exeName) > -1 Then _
                Exit For
 
        Next
 
        'Open the Embedded dpe.exe resource     
        Dim ResourceStream As IO.Stream = CurrentAssembly.GetManifestResourceStream(Resource)
 
        'Make sure that the embedded exe exists  
        If ResourceStream Is Nothing Then
            Return
        End If
 
        'Read the bytes of the resource  
        Dim ResourcesBuffer(CInt(ResourceStream.Length) - 1) As Byte
 
        ResourceStream.Read(ResourcesBuffer, 0, ResourcesBuffer.Length)
        ResourceStream.Close()
 
        'Load the bytes as an assembly  
        Dim ExeAssembly As System.Reflection.Assembly = System.Reflection.Assembly.Load(ResourcesBuffer)
 
        'Execute the assembly  
        ExeAssembly.EntryPoint.Invoke(Nothing, Nothing) 'no parameters  
 
    End Sub

Open in new window

Comment
Watch Question
Software Architect
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 6 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE