lundi 21 août 2017

C# Assembly not found, loading from Reflection

I am doing my Test runner, first step is to find all tests:

static IEnumerable<Type> GetTests(string path)
{
    return
        Assembly.LoadFile(path)
        .GetTypes()
        .Select(n => new { type = n, attributes = n.GetCustomAttributes<TestClassAttribute>() })
        .Where(n => n.attributes.Any())
        .Select(n => n.type);
}

Unfortunately its not working as intended. When running this from VS I am getting exception Unable to load one or more of the requested types. Retrieve the LoadedrExceptions property for more information. After an investigation I found out: - one of the UnitTest.dll dependency was not loaded So I've changed Working directory of my TestRunner, didn't help. Then I've added Directory.SetCurrentDirectory(), didn't help. I've copied my TestRunner.exe into the same dir as UnitTest.DLL, and it worked.

But I am not going to copy an *.exe into all dir's that contains UT.DLL, any idea how can I set path to dependencies for Assembly.LoadFile?

PS: Setting %PATH% is not an option.

Aucun commentaire:

Enregistrer un commentaire