Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullReferenceException when getting TestDirectory from TestContext #2110

Closed
florian-gandon opened this issue Apr 5, 2017 · 2 comments
Closed

Comments

@florian-gandon
Copy link

Hello !

In the context of an attribute implementing ITestAction applied at assembly level, I'm receiving NullReferenceException when calling TestContext.CurrentContext.TestDirectory in AfterTest method.

I've provided a project as a sample.
ClassLibrary22.zip

As work around, I'm doing:
AssemblyHelper.GetDirectoryName(Assembly.GetCallingAssembly())

Is there another way to get the test directory at this moment ?

Regards,
Florian

@CharliePoole
Copy link
Member

This line of code in TestContext.cs is at fault:

                    return AssemblyHelper.GetDirectoryName(test.TypeInfo.Assembly);

Use of TypeInfo implies that the test is implemented by a method or class. That's true for everything except the top-level assembly. We can either add special code to detect that it's a test assembly and cast in order to get the Assembly or - even simpler - arrange to fall through to the following code that uses GetCallingAssembly.

@florian-gandon
Copy link
Author

Thanks for the quick answer and the fix.

@ChrisMaddock ChrisMaddock added this to the 3.7 milestone Apr 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants