c# - NDepend TypeInitializationExceptions when Testing with NUnit -


so i'm trying set project using ndepend api metrics on code (which works nicely), however, when attempt run testing framework (nunit) on it, i'm getting typeinitializationexceptions thrown.

here code reproduce errors i'm getting:

  • create class library project, , reference ndepend api dll @ $ndependinstallpath$\lib\ndependapi, setting copy local false. create class follows:

    public class ndependprojectloader {   public void loadanndependproject()   {     var provider = new ndependservicesprovider();   } } 
  • create second class library project in solution test class. reference nunit , project created references ndependapi

    [testfixture] public class ndependprojectloader_tests {   [test]   public void i_can_load_an_depend_project()   {     new ndependprojectloader().loadanndependproject();   } } 
  • build, , run test using test runner of choice (i've tried resharper's test runner , nunit gui).

  • you typeinitializationexception on line var provider = new ndependservicesprovider();

  • looking inside typeinitializationexception shows root exception's message is:

"{"could not load file or assembly 'ndepend.platform.dotnet' or 1 of dependencies. system cannot find file specified.":"ndepend.platform.dotnet"}".

"the program executable assembly must generated $ndependinstallpath$\"

  • in case code started test runner executable not in ndepend install path.

  • calling ndependprojectloader.loadanndependproject() console application .exe generated in $ndependinstallpath$\lib\ (note .exe seems need generated in \lib\ subfolder not in $ndependinstallpath$\ stated in getting started guide) not produce exception, further points being cause.

so, question is, how 1 work ndepend api other console application? example, here want test runner. obvious candidate iis application. missing obvious?

indeed problem comes assembly resolution. must tell clr find ndepend assemblies (i.e in dir $ndependinstallpath$\lib) have 2 choices this. suppose $ndependinstallpath$ "c:\ndepend" example:

  • either edit assemblyresolverhelper resolve assemblies in "c:\ndepend\lib"

  • either create app.config file exe, add <probing> element refers "c:\ndepend\lib". when clr won't resolve assembly, it'll @ dir in such element


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -