jeudi 22 octobre 2015

C# Program gets hung up on asynchronous call inside of dynamically added dll

I have a main program and a helper dll that is added programmatically

Main -

public class MainProgram
{
    public MainProgram()
    {

        byte[] dllByteArray = [dllByteArrayHere];
        byte[] pdbByteArray = [pdbByteArrayHere];

        System.Reflection.Assembly myDllAssembly = System.Reflection.Assembly.Load(dllByteArray , pdbByteArray );

        System.Type MyDLLFormType = myDllAssembly.GetType("HelperNamespace.HelperClass");

        var MyDLLFormInstance = myDllAssembly.CreateInstance(MyDLLFormType.ToString());

    }

}

Helper dll-

namespace HelperNamespace
{
    public class HelperClass
    {

        public HelperClass()
        {

            Console.Write("Start");

            using (var client = new HttpClient())
            {

                var values = new Dictionary<string, string>
                {
                   { "Data", "Data" }
                };

                //Communicate with Data Service
                var content = new FormUrlEncodedContent(values);
                var response = await client.PostAsync( [URL], content);
                var responseString = await response.Content.ReadAsStringAsync();

            }

            Console.Write("End"); 
        } 

    }

}

Currently, when I run MainProgram, the helper dll is successfully added. The problem is that while "Start" is outputed to the console, "End" is never reached.

I believe it is stuck awaiting a response on this line:

var responseString = await response.Content.ReadAsStringAsync();

It is important to note that when the dll is added/referenced using the standard method (By adding as reference), everything runs fine and it does not get "Stuck".

Any idea on what might be going on or how I can go about fixing it? Any input will truly be appreciated.





Aucun commentaire:

Enregistrer un commentaire