Daily Usage Issues

System.TypeInitializationException

Started by ivoloshin on 10,578 views

I am using VS 2012 with NCrunch. I'm running NUNit tests using Resharper, VS and NCrunch. The problem I have is in an older log4net library that throws System.TypeInitializationException when creating a logger.

I added the following to App.config fix this:

<runtime>
<NetFx40_LegacySecurityPolicy enabled="true" />
</runtime>


This has made it so that the application runs without the error, and the unit tests pass in Resharper test runner as well as MS Test runner. I still have this error in NCrunch, however.

I tried making the following modification to files:

nCrunch.build.4.0.config
nCrunch.TaskRunner40.x64.exe.config
nCrunch.TaskRunner40.x86.exe.config

<runtime>
<NetFx40_LegacySecurityPolicy enabled="true" />
<legacyUnhandledExceptionPolicy enabled="0" />
</runtime>

This did not help.

Thanks,
Ilya

Edited

Hi Ilya,

Depending upon its configuration, NCrunch will usually run your tests inside a hosted environment that doesn't consider the .config files. However, you can easily change this.

Under your global NCrunch configuration, you'll find an option called 'Use hosted task runner'. Set this to FALSE, and your modifications to the nCrunch.TaskRunner*.config files should start working.


Cheers,

Remco
Thanks for the reply!

This did not seem to help my problem, however.

I'll try to set up a sample project to demonstrate the problem.

Thanks,
Ilya

Edited

Make sure you reset the engine after applying this setting. If it takes effect, you should see the NCrunch task runners as showing up under the names 'nCrunch.TaskRunner40.x86.exe', etc.

I'll message you with an email address if you'd like to send a sample project. NCrunch has seen limited testing around CAS and there are a number of known issues at the moment, so it would probably be good to solve this one at the same time!


Cheers,

Remco
Remco,

I was not able to reproduce the exception in a standalone example and the full solution is too large to send anyway. I did, however, find a way to make our library work correctly by adding the following to AssemblyInfo.cs:

[assembly: SecurityRules(SecurityRuleSet.Level1)]

Not an ideal solution, but it'll work for us for now.

Thanks!
Ilya
Thanks, I'll have a play with it and see what I can find.

Post a reply

Log in to reply.