Build/Test Issues

Reflection Exception when running tests.

Started by Luciferius on 7,212 views

Hello,

I tried to use NCrunch because I love Infinittest for eclipse. After I got every project to compile I tried to run my tests.
The task runner process status is Completed. The status of the underlying tests are Running but they dont do anything.
If I select the task runner process in the Processing Queue I get the follwoing stacktrace:

[13:23:42.6842-TestExecutionTask-8] ERROR (Internal): System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.RuntimeModule.GetTypes()
at System.Reflection.Assembly.GetTypes()
at nCrunch.Reflection.Clr.ClrAssembly.get_Types()
at nCrunch.Reflection.ReflectedAssembly.GetFlattenedTypes()
at nCrunch.Reflection.ReflectedAssembly.#=qs2_oOiBUxtZn_gNpwZ8iPjLn5lAzQnCfWjDv6p9neNo=()
at nCrunch.Reflection.ReflectedAssembly.GetTypeByFullName(String typeFullName)
at nCrunch.TestExecution.ReflectionExtensions.GetTypeFromTestId(ReflectedAssembly assembly, TestId testId)
at nCrunch.TestExecution.ReflectionExtensions.GetMemberFromTestId(ReflectedAssembly assembly, TestId testId)
at #=qWONS4dr5w7Ki0$RiwFRZLyaxminPjbGL5IYxHL89jJ7ZI41J5YVgb9ONwhKoDpOJNYXcpEWszCBvYCWvsb_UBg==.#=qZTcArX2yt6MJZ31mPCphz7KLnAMfHnFMuK9c2DIi0nY=(TestId[] #=qKXVbb_5NuAC1Z3nCC5Bkip8HgucklnT_bkFE71LalTg=, ReflectedAssembly #=qGg3$aFHongBPz3n12k$pfg==)
at #=qWONS4dr5w7Ki0$RiwFRZLyaxminPjbGL5IYxHL89jJ7ZI41J5YVgb9ONwhKoDpOJNYXcpEWszCBvYCWvsb_UBg==..ctor(MSTestNames #=qC7coe4UERCd_o8_lPmGFLQ==, String #=qkiMhFI3aZJmZVGx03g5KGXlvMfvyYrzn4MS1eaYrpMM=, String #=qQ0uEy9kDhxK99QDj5aCfye4jCAUnUnjGGbaWGSzK2W4=, ReflectedAssembly #=qjvhYLIqIO$BHkxdxeAB39Q==, TestId[] #=qNN5tg_ov5x01svRfOvqQwZgNXMbo$cw94gR6a0ZR2Dc=)
at nCrunch.TestExecution.Frameworks.MSTest.MSTestFramework.RunTests(TestOutput output, TestExecutionMapSet testMapSet, TestExecutionParameters parameters)
at nCrunch.TestExecution.TestRunnerThread.#=q7v3LnBjYuJV_NJz$Mxoi$Q==()


Has anyone an idea what this could meanß

Regards, Luciferius
Hi, thanks for posting and for taking the time to try out NCrunch!

There is something unusual with one of the fixture types in your test project that is causing runtime reflection to fail to resolve the type. Are you able to narrow down which class is causing the problem? I'd really like to see a bit more about how the class is declared so we can identify what is unique about it. The task in the processing queue that failed should also contain the list of tests that it was trying to execute, so you may be able to figure out which fixture is causing the problem by deductively trying to run the tests in the task individually (using the 'run tests' option in the Tests Window or by right-clicking on the test declaration).
Thanks for the response. I found the problem, but not the solution.

Our assemblies are local delay signed with a public key and on the build server they get correctly signed. Following problem: if I deactivate the signing in NCrunch with "Prevent from signing" the unit tests work, but only after another problematic change.
The unit tests are in a different assembly than the code. Because of that these two assemblies are friendly with "InternalsVisibleTo". There I have to put the public key so that the unit tests can be run after the assemblies are signed. Unfortunate this does not wok for unsigned. There I have to delete the public key. But than the unit tests are not working on the build server. So I can only make them work on Ncrunch OR the build server.
On this point I need a solution for the problem.

Regards, Luciferius.
Nice work on identifying the cause of the problem. This is an easy one to solve - you simply need to introduce some conditional logic so that you use a different [InternalsVisibleTo] attribute when working with NCrunch, as opposed to the build server. You can make use of the #if NCRUNCH directive to achieve this. For example:

#if NCRUNCH
[assembly: InternalsVisibleTo ("TestProject.Tests")]
#else
[assembly: InternalsVisibleTo ("TestProject.Tests, PublicKey=mypublickey")]
#endif
Great thanks, that does the trick for me.

Regards, Luciferius
This post has been deleted.

Post a reply

Log in to reply.