Skip to content
This repository has been archived by the owner on Dec 9, 2022. It is now read-only.

Issue running tests on build server with Sonar #64

Closed
donald-slagle opened this issue May 29, 2013 · 5 comments
Closed

Issue running tests on build server with Sonar #64

donald-slagle opened this issue May 29, 2013 · 5 comments

Comments

@donald-slagle
Copy link

I am using Jenkins to pull in my code then build, test, deploy, and run against sonar. The tests run just fine in jenkins but when it gets to the sonar step of running the tests for code coverage data the fluent security tests all fail. The error that I am getting is below:

13:41:07.088 INFO .u.c.CommandExecutor - SetUp : System.TypeInitializationException : The type initializer for 'FluentSecurity.SecurityConfigurator' threw an exception.
13:41:07.088 INFO .u.c.CommandExecutor - ----> System.BadImageFormatException : Could not load file or assembly 'file:///C:\Program Files\Gallio\bin\Gallio.Host.Elevated.x86.exe' or one of its dependencies. An attempt was made to load a program with an incorrect format.

I've tracked it down and it seems to be caused by the SecurityDoctor.ScanForEventListeners method which bubbles down to AssemblyScanner.AssembliesFromApplicationBaseDirectory. It is trying to pull the assemblies from the base directory with AppDomain.CurrentDomain.BaseDirectory but since Gallio is executing the tests from its directory it is instead scanning the Gallio bin folder and not the project folder which causes the error I am getting. Is there a way to override the scanner or have Fluent Security not scan at all when I am running my tests? I am using StructureMap for my IOC container so all my registration is done there.

Fluent Security has been great and does exactly what I need. I just need to get my coverage report to know what other tests I need to write.

@donald-slagle
Copy link
Author

I attempted to fix this issue by modifying the Sonar plugin for .Net Gallio to allow passing the adb(Absolute Base Directory) parameter in. The changes to the plugin worked but didn't fix the issue that I am having with the tests. I found out I can run the tests successfully with Gallio alone but when I use OpenCover to execute Gallio to run my tests for code coverage is when it fails. I did manage to get past the original error by adding a hack into my test startup:

AppDomain.CurrentDomain.SetData("APPBASE", Environment.CurrentDirectory);

But now I am getting an error that says:

Method FluentSecurity.ConfigurationExpression.For: type argument 'Controller' violates the constraint of type parameter 'TController'

I know that this issue is usually cause by mismatched mvc versions but I am not sure where this is happening because I have put this in my App.config file which solved this same issue I was having when running from Nunit or Jenkins.

<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
  </dependentAssembly>
</assemblyBinding>
</runtime>

I don't know where the conflict is happening or even how to debug to find this issue. I know that Fluent Security is pointing at MVC3 and I am using MVC4 but my tests work fine other wise unless I run with OpenCover and Gallio.

@donald-slagle
Copy link
Author

I was running my tests manually through command line with OpenCover and Gallio but after finally running it with Jenkins + Sonar it seems to work. I am pretty sure the hack I added made it work. I am fine with the hack because it is a 1 liner and only in my unit tests so I can live with it, but this could be some useful information for future changes.

@kristofferahl
Copy link
Owner

Sorry for not responding faster. Glad you found a fix that worked for your scenario.

The issue related to the assembly version is documented in the wiki but the issue you were having with the base directory is something new and possibly something that needs to be improved. The fix you provided (AppDomain.CurrentDomain.SetData("APPBASE", Environment.CurrentDirectory)) is OK but if you have any ideas on a more permanent fix, please let me know.

Thanks for posting and supporting the project by doing so!

@robertmircea
Copy link

Yet another problem with the "assembly scanner". From what it seems, it tries to load oci.dll which is a native dll (not an assembly)

The type initializer for 'FluentSecurity.SecurityConfigurator' threw an exception.
at FluentSecurity.SecurityConfigurator.Configure(Action`1 configurationExpression)
at Xyz.MvcApplication.Application_Start() in Global.asax.cs:line 117

Could not load file or assembly 'file:///C:\inetpub\wwwroot\xyz\bin\oci.dll' or one of its dependencies. The module was expected to contain an assembly manifest.
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)

Any suggestions on how to solve this?

@MarcoGaribaldi
Copy link

Here another problem with the assembly scanner. The following code

SecurityConfigurator.Configure(configuration => { configuration.GetAuthenticationStatusFrom(SecurityHelper.UserIsAuthenticated); configuration.GetRolesFrom(SecurityHelper.UserRoles); configuration.ApplyProfile(); configuration.ApplyProfile();
configuration.Scan(scan =>
{
    scan.AssembliesFromApplicationBaseDirectory();
    scan.LookForProfiles();
});

});

generates the following error:

Could not load file or assembly 'file:///C:\Users\MyName\Source\Workspaces\MyApplication\Dev\ErcApplication.WebMVC\bin\optipng.exe' or one of its dependencies. The module was expected to contain an assembly manifest.

I am not sure what optipng.exe is. It may have to do with the ImageResizer addon, but I am just guessing. Is there a way to skip a dll that causes problems?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants