nunit - Unit testing with Roslyn.Services.Workspace results in a SecurityException while working at x86 target -


i'm working on set of constants project, , i'd use verify of them in source code level. achieve this, i'm loading entire solution using following snippet appdomain isfullytrusted == true , ishomogenous == true, i.e. remoting enabled x86 platform target:

// load workspace, i.e. solution visual studio var workspace = roslyn.services.workspace.loadsolution(solutionfile); 

test runners ncrunch , nunit x86 platform roslyn

but while using either 1.45 or 2.6.2 nunit-console-x86.exe platform configuration x86 test runners, i'm getting following system.security.securityexception:

system.security.securityexception : type system.runtime.remoting.objref , types derived (such system.runtime.remoting.objref) not permitted deserialized @ security level.  server stack trace:     @ system.runtime.serialization.formatterservices.checktypesecurity(type t, typefilterlevel securitylevel)    @ system.runtime.serialization.formatters.binary.objectreader.checksecurity(parserecord pr)    @ system.runtime.serialization.formatters.binary.objectreader.parseobject(parserecord pr)    @ system.runtime.serialization.formatters.binary.objectreader.parse(parserecord pr)    @ system.runtime.serialization.formatters.binary.__binaryparser.readobjectwithmaptyped(binaryobjectwithmaptyped record)    @ system.runtime.serialization.formatters.binary.__binaryparser.readobjectwithmaptyped(binaryheaderenum binaryheaderenum)    @ system.runtime.serialization.formatters.binary.__binaryparser.run()    @ system.runtime.serialization.formatters.binary.objectreader.deserialize(headerhandler handler, __binaryparser serparser, boolean fcheck, boolean iscrossappdomain, imethodcallmessage methodcallmessage)    @ system.runtime.serialization.formatters.binary.binaryformatter.deserialize(stream serializationstream, headerhandler handler, boolean fcheck, boolean iscrossappdomain, imethodcallmessage methodcallmessage)    @ system.runtime.remoting.channels.corechannel.deserializebinaryrequestmessage(string objecturi, stream inputstream, boolean bstrictbinding, typefilterlevel securitylevel)    @ system.runtime.remoting.channels.binaryserverformattersink.processmessage(iserverchannelsinkstack sinkstack, imessage requestmsg, itransportheaders requestheaders, stream requeststream, imessage& responsemsg, itransportheaders& responseheaders, stream& responsestream)  exception rethrown @ [0]:     @ system.runtime.remoting.proxies.realproxy.handlereturnmessage(imessage reqmsg, imessage retmsg)    @ system.runtime.remoting.proxies.realproxy.privateinvoke(messagedata& msgdata, int32 type)    @ roslyn.utilities.remoteservices.initialize(int32 clientprocessid)    @ roslyn.utilities.remoteservices.startremoteservicesprocess()    @ roslyn.utilities.remoteservices.get_instance()    @ roslyn.utilities.remoteservices.createinstance[t]()    @ roslyn.services.host.temporarystorageservicefactory.createservice(iworkspaceserviceprovider workspaceservices)    @ roslyn.services.host.workspaceserviceproviderfactory.<>c__displayclass6.<onimportssatisfied>b__1(iworkspaceserviceprovider wsp)    @ roslyn.services.host.workspaceserviceprovider.constructservice(type type)    @ system.collections.concurrent.concurrentdictionary`2.getoradd(tkey key, func`2 valuefactory)    @ roslyn.services.host.workspaceserviceprovider.getservice[tworkspaceservice]()    @ roslyn.services.solutionservices..ctor(iworkspaceserviceprovider workspaceservices)    @ roslyn.services.solution..ctor(solutionid id, string filepath, versionstamp version, versionstamp latestprojectversion, iworkspaceserviceprovider workspaceservices)    @ roslyn.services.host.solutionfactoryservicefactory.solutionfactoryservice.createsolution(solutionid id)    @ roslyn.services.host.trackingworkspace.createnewsolution(isolutionfactoryservice solutionfactory, solutionid id)    @ roslyn.services.host.trackingworkspace..ctor(iworkspaceserviceprovider workspaceserviceprovider, boolean enablebackgroundcompilation, boolean enableinprogresssolutions)    @ roslyn.services.host.hostworkspace..ctor(iworkspaceserviceprovider workspaceserviceprovider, boolean enablebackgroundcompilation, boolean enableinprogresssolutions, boolean enablefiletracking)    @ roslyn.services.host.loadedworkspace..ctor(iworkspaceserviceprovider workspaceserviceprovider, idictionary`2 globalproperties, boolean enablebackgroundcompilation, boolean enablefiletracking)    @ roslyn.services.host.loadedworkspace.loadsolution(string solutionfilename, string configuration, string platform, boolean enablefiletracking)    @ roslyn.services.workspace.loadsolution(string solutionfilename, string configuration, string platform, boolean enablefiletracking) 

there a discussion on ncrunch forum, but have tried following options without success:

  • add [assembly: allowpartiallytrustedcallers] assemblyinfo.cs
  • add [assembly: securityrules(securityruleset.level1)] assemblyinfo.cs
  • add <netfx40_legacysecuritypolicy enabled="true" /> app.config
  • run vs2012 administrator
  • decorate both unittests , implementation [securitysafecritical]
  • update: create new appdomain , provide
    • permissionstate.unrestricted, securitypermissionflag.allflags , dataprotectionpermissionflags.allflags
    • add host evidence: securityzone.mycomputer, system.security.policy.hash , system.security.policy.strongname
    • add assemblies (both mine , roslyn ctp) fulltrustassemblies while creating of appdomain

update #2

this exception happens while i'm running test under x86 configuration, after had switched x64 platform configuration, seems work fine

question

are there other attributes or configuration changes app.config or appdomain enable deserialization in .net framework remoting system.runtime.remoting.objref while running under x86 configuration?

temporary solution

switch x64 build configuration unittest project(s)

source code

additional information

also notice...

  1. a lot of instances of roslyn.services.dll hang in background, after tests had been completed.
  2. lack of host evidences ncrunch: system.security.policy.hash , system.security.policy.strongname test runner assembly name
  3. msil (should x64 inside) , 2.6.2 nunit-console.exe test runner working fine, looks roslyn configuration/remoting/security configuration issue.

it looks executing tests in partial trust, whereas resharper running them in full trust.

roslyn has not been tested in partial trust scenarios. there accesses apis require full trust.

i haven't used ncrunch, maybe there way configure run tests in full trust?


Comments