Parameter count mismatch in C# 12-29-2012, 01:02 AM
#1
Hi, dear HackCommunity-members.
I have a bit of a problem when trying to create something in C#. I don't know what the problem is, and I've been sitting here multiple hours trying to solve it. I've searched for different solutions, tried them - nothing worked. Some other forums said something about "Invoke", as in the bottom of my code?.
Here, I want to read bytes (former from a *.exe assembly) from a text document, or a byte[]-variable. Now, here's the code that reads those bytes.
But when trying to run the application through reading the text document (Windows Form, WPF) it shows me; parameter count mismatch. But when I decide to point the file location to an executable instead, the application starts up and runs just fine.
- EDIT -
I'm sorry, I made a mistake. The error I am getting when trying to load bytes to run assembly is "Ett undantagsfel har inträffat i målet för en aktivering" in Swedish, which basically means "An exception occurred in the case of an activation.", with the code above.
What's wrong? Any clue?
Thank you.
I have a bit of a problem when trying to create something in C#. I don't know what the problem is, and I've been sitting here multiple hours trying to solve it. I've searched for different solutions, tried them - nothing worked. Some other forums said something about "Invoke", as in the bottom of my code?.
Here, I want to read bytes (former from a *.exe assembly) from a text document, or a byte[]-variable. Now, here's the code that reads those bytes.
Code:
// read the bytes from the application exe file
FileStream fs = new FileStream("RunThis.txt", FileMode.Open);
BinaryReader br = new BinaryReader(fs);
byte[] bin = br.ReadBytes(Convert.ToInt32(fs.Length));
fs.Close();
br.Close();
// load the bytes into Assembly
Assembly a = Assembly.Load(bin);
// search for the Entry Point
MethodInfo method = a.EntryPoint;
if (method != null)
{
// create an istance of the Startup form Main method
object o = a.CreateInstance(method.Name);
// invoke the application starting point
method.Invoke(o, null);
}But when trying to run the application through reading the text document (Windows Form, WPF) it shows me; parameter count mismatch. But when I decide to point the file location to an executable instead, the application starts up and runs just fine.
- EDIT -
I'm sorry, I made a mistake. The error I am getting when trying to load bytes to run assembly is "Ett undantagsfel har inträffat i målet för en aktivering" in Swedish, which basically means "An exception occurred in the case of an activation.", with the code above.
What's wrong? Any clue?
Thank you.
(This post was last modified: 12-29-2012, 01:24 AM by Blunt.)
![[+]](https://sinister.ly/images/modern/collapse_collapsed.png)