# RunAsync() fails with arguments passed

**URL:** https://forum.alternetsoft.com/t/runasync-fails-with-arguments-passed/519
**Category:** AlterNET Studio Support
**Tags:** scripter
**Created:** [December 18, 2025, 9:14am UTC](https://forum.alternetsoft.com/t/runasync-fails-with-arguments-passed/519 "2025-12-18T09:14:41Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![tsp\_extern\_pa](https://forum.alternetsoft.com/letter_avatar_proxy/v4/letter/t/606060/32.png) [@tsp\_extern\_pa](https://forum.alternetsoft.com/u/tsp_extern_pa)
#### Post date: [December 18, 2025, 9:14am UTC](https://forum.alternetsoft.com/t/runasync-fails-with-arguments-passed/519/1 "2025-12-18T09:14:41Z")

</div>

The following script failed to execute, because ScriptRun.RunAsync() throws an exception, even though the program code is valid → System.Reflection.TargetParameterCountException: ‘Parameter count mismatch.’.

The project is very simple, a console app with basic scripting - but using async Tasks.

Project:

```auto
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net9.0</TargetFramework>
    <RootNamespace>Bug_in_Alternet</RootNamespace>
    <ImplicitUsings>disable</ImplicitUsings>
    <Nullable>disable</Nullable>
    <Platforms>x64</Platforms>
  </PropertyGroup>

	<ItemGroup>
		<PackageReference Include="Alternet.Studio.Scripter" Version="10.0.5" />
	</ItemGroup>

</Project>

```

Program.cs:

```auto
using Alternet.Scripter;
using System;
using System.Threading.Tasks;

class Program
{
    const string AsyncScript = """
            using System;
            using System.Threading.Tasks;

            class AsyncScriptProgram 
            {
                static async Task Main(string[] args)
                {
                    Console.WriteLine($"\t{args.Length} Args:");
                    for (int i = 0; i < args.Length; i++)
                        Console.WriteLine($"\tArg[{i}]: {args[i]}");

                    Console.WriteLine($"\tWait a bit");
                    await Task.Delay(100);
                }
            }
        """;

    public static async Task Main(string[] args)
    {
        Console.WriteLine("Create Script Runtime");

        ScriptRun scriptRun = new ScriptRun()
        {
            AssemblyKind = ScriptAssemblyKind.ConsoleApplication,
            ScriptMode = ScriptMode.Debug,
            ScriptLanguage = ScriptLanguage.CSharp,
            Platform = ScriptPlatform.X64,
        };
        scriptRun.ScriptSource.FromScriptCode(AsyncScript);
        scriptRun.ScriptSource.WithSystemReferences(ScriptTechnologyEnvironment.System, WithSystemReferencesFlags.None);

        Console.WriteLine("Compile Script");
        if (!scriptRun.Compile())
        {
            Console.Error.WriteLine("Failed to compile Script!");
            foreach (ScriptCompilationDiagnostic compileError in scriptRun.ScriptHost.CompilerErrors)
                Console.Error.WriteLine(compileError.ToString());
        }
        else
            Console.WriteLine("Successfully compiled Script");

        string[] scriptArgs = ["Hallo", "Welt", "der", "Programmierer"];

        Console.WriteLine("Run Script");
        await scriptRun.RunAsync(scriptArgs);
        Console.WriteLine("Completed Script");

        Console.WriteLine("Done, press key to exit");
        Console.ReadKey();
    }
}

```

---

<div class="post-metadata">

### Author: ![generalloki](https://forum.alternetsoft.com/user_avatar/forum.alternetsoft.com/generalloki/32/225_2.png) [@generalloki](https://forum.alternetsoft.com/u/generalloki)
#### Post date: [December 18, 2025, 4:57pm UTC](https://forum.alternetsoft.com/t/runasync-fails-with-arguments-passed/519/2 "2025-12-18T16:57:04Z")

</div>

Thank you for the bug report. I was able to reproduce the issue with your sample project. We are currently investigating the cause and working on a fix. I will post an update here—hopefully by tomorrow—once we have a solution or further information.

---

<div class="post-metadata">

### Author: ![generalloki](https://forum.alternetsoft.com/user_avatar/forum.alternetsoft.com/generalloki/32/225_2.png) [@generalloki](https://forum.alternetsoft.com/u/generalloki)
#### Post date: [December 19, 2025, 4:45am UTC](https://forum.alternetsoft.com/t/runasync-fails-with-arguments-passed/519/3 "2025-12-19T04:45:55Z")

</div>

There were a bug in `ScriptMethod.InvokeMainMethod`. With the fix it works fine on your sample project. We will test it in other scenarios and hope to include with the next build which is planned very soon.

 ![image](https://forum.alternetsoft.com/uploads/default/original/1X/ad312365f8b70ff5116ed6650d33e2b680e59a89.png)

---

<div class="post-metadata">

### Author: ![tsp\_extern\_pa](https://forum.alternetsoft.com/letter_avatar_proxy/v4/letter/t/606060/32.png) [@tsp\_extern\_pa](https://forum.alternetsoft.com/u/tsp_extern_pa)
#### Post date: [December 19, 2025, 6:35am UTC](https://forum.alternetsoft.com/t/runasync-fails-with-arguments-passed/519/4 "2025-12-19T06:35:12Z")

</div>

Awesome! Thanks for the fast response.

---

<div class="post-metadata">

### Author: ![generalloki](https://forum.alternetsoft.com/user_avatar/forum.alternetsoft.com/generalloki/32/225_2.png) [@generalloki](https://forum.alternetsoft.com/u/generalloki)
#### Post date: [January 8, 2026, 8:00am UTC](https://forum.alternetsoft.com/t/runasync-fails-with-arguments-passed/519/5 "2026-01-08T08:00:39Z")

</div>

This was fixed in 10.0.6 build which was just released.

---

<div class="post-metadata">

### Author: ![tsp\_extern\_pa](https://forum.alternetsoft.com/letter_avatar_proxy/v4/letter/t/606060/32.png) [@tsp\_extern\_pa](https://forum.alternetsoft.com/u/tsp_extern_pa)
#### Post date: [January 12, 2026, 9:01am UTC](https://forum.alternetsoft.com/t/runasync-fails-with-arguments-passed/519/6 "2026-01-12T09:01:36Z")

</div>

The actual bug with async Main(string args) is now fixed in 10.0.6, but there is another bug which is directly related - ~~which maybe got broken in that fix~~.

The following script does not run, because the arguments string array are always 1 and contains a single element, that is an string array with the actual arguments.

```auto
class ScriptProgram 
{
    public static int Main(string[] args)
    {
        Console.WriteLine($"\t{args.Length} Args:");
        for (int i = 0; i < args.Length; i++)
            Console.WriteLine($"\tArg[{i}]: {args[i]}");

        if (args.Length == 0) {
            Console.Error.WriteLine($"\tNo file arguments passed");
            return -1;
        }

        for (int i = 0; i < args.Length; i++) {
            string filePath = args[i];
            Console.WriteLine($"\tOpen file: {filePath}");
            // ...
        }

        return 0;
    }
}

```

That script is run like this (no async!):

```auto
string[] scriptArgs = ["FileA", "FileB", "FileC"]; // Is just an example

Console.WriteLine($"Run Script with args '{string.Join("|", scriptArgs)}'");
try
{
    object returnValue = scriptRun.Run(scriptArgs);
    Console.WriteLine($"Completed Script with return value: {returnValue}");
}
catch (Exception e)
{
    Console.Error.WriteLine($"Failed to Run Script:\n{e.ToString()}");
}

```

The console output of the script shows clearly what is going wrong:

```auto
        1 Args:
        Arg[0]: System.String[]
        Open file: System.String[]

```

---

<div class="post-metadata">

### Author: ![tsp\_extern\_pa](https://forum.alternetsoft.com/letter_avatar_proxy/v4/letter/t/606060/32.png) [@tsp\_extern\_pa](https://forum.alternetsoft.com/u/tsp_extern_pa)
#### Post date: [January 21, 2026, 8:08am UTC](https://forum.alternetsoft.com/t/runasync-fails-with-arguments-passed/519/7 "2026-01-21T08:08:09Z")

</div>

What is the state of the Run() with arguments single object string array bug? Will this be fixed?

---

<div class="post-metadata">

### Author: ![generalloki](https://forum.alternetsoft.com/user_avatar/forum.alternetsoft.com/generalloki/32/225_2.png) [@generalloki](https://forum.alternetsoft.com/u/generalloki)
#### Post date: [January 21, 2026, 2:58pm UTC](https://forum.alternetsoft.com/t/runasync-fails-with-arguments-passed/519/8 "2026-01-21T14:58:56Z")

</div>

I will study the issue and respond to you shortly.

---

<div class="post-metadata">

### Author: ![generalloki](https://forum.alternetsoft.com/user_avatar/forum.alternetsoft.com/generalloki/32/225_2.png) [@generalloki](https://forum.alternetsoft.com/u/generalloki)
#### Post date: [January 22, 2026, 1:49pm UTC](https://forum.alternetsoft.com/t/runasync-fails-with-arguments-passed/519/9 "2026-01-22T13:49:54Z")

</div>

Thank you for the report. For some reason, we did not receive a notification about the topic update from the forum engine.

I was able to reproduce the issue with `Run(string[])` in version 10.0.6, and it was fixed in the master branch today.  
We will include the fix in the next build.

---

<div class="post-metadata">

### Author: ![generalloki](https://forum.alternetsoft.com/user_avatar/forum.alternetsoft.com/generalloki/32/225_2.png) [@generalloki](https://forum.alternetsoft.com/u/generalloki)
#### Post date: [February 6, 2026, 4:53am UTC](https://forum.alternetsoft.com/t/runasync-fails-with-arguments-passed/519/10 "2026-02-06T04:53:14Z")

</div>

We have just released Alternet.Studio build 10.0.7, which includes a fix for the issue. You will shortly receive a notification about the library update. Please let us know whether everything is working correctly now.
