realvizu / NsDepCop

NsDepCop is a static code analysis tool that helps to enforce namespace dependency rules in C# projects. No more unplanned or unnoticed dependencies in your system.
GNU General Public License v2.0
200 stars 32 forks source link

Unable to communicate with NsDepCop service. All retries failed on CI Build #48

Closed seblucas closed 5 years ago

seblucas commented 5 years ago

Hi,

First thanks for this tool, it's exactly what we needed to make sure our code is properly decoupled.

Next, unfortunately, I've never managed to make it run with our CI build. I'm using Azure Devops using my own build machine which a Win10 with latest VS2017 (same as my laptop). I always have this error message :

  Utilisation de la compilation partagée avec le compilateur du répertoire : C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Roslyn
NsDepCop_Analyze:
  [NsDepCop] Analysing project in folder: C:\agent\_work\10\s\src\Quadra.Affixe2.Application.Bodac.Private
##[error]Exception during NsDepCopTask execution: System.Exception: Unable to communicate with NsDepCop service. All retries failed. ---> System.Runtime.Remoting.RemotingException: Échec de la connexion à un port IPC : Le fichier spécifié est introuvable.

Server stack trace: 
   à System.Runtime.Remoting.Channels.Ipc.IpcPort.Connect(String portName, Boolean secure, TokenImpersonationLevel impersonationLevel, Int32 timeout)
   à System.Runtime.Remoting.Channels.Ipc.ConnectionCache.GetConnection(String portName, Boolean secure, TokenImpersonationLevel level, Int32 timeout)
   à System.Runtime.Remoting.Channels.Ipc.IpcClientTransportSink.ProcessMessage(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream, ITransportHeaders& responseHeaders, Stream& responseStream)
   à System.Runtime.Remoting.Channels.BinaryClientFormatterSink.SyncProcessMessage(IMessage msg)

Exception rethrown at [0]: 
   à System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   à System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   à Codartis.NsDepCop.Core.Interface.Analysis.Remote.IRemoteDependencyAnalyzer.AnalyzeProject(IAnalyzerConfig config, String[] sourcePaths, String[] referencedAssemblyPaths)
   à Codartis.NsDepCop.Core.Implementation.Analysis.Remote.RemoteDependencyAnalyzerClient.InvokeRemoteAnalyzer(IEnumerable`1 sourceFilePaths, IEnumerable`1 referencedAssemblyPaths)
   à Codartis.NsDepCop.Core.Util.RetryHelper.Retry[TResult](Func`1 func, Int32 maxRetryCount, BeforeRetryCallback beforeRetryAction)
   --- Fin de la trace de la pile d'exception interne ---
   à Codartis.NsDepCop.Core.Implementation.Analysis.Remote.RemoteDependencyAnalyzerClient.OnAllRetriesFailed(Exception exception)
   à Codartis.NsDepCop.Core.Implementation.Analysis.Remote.RemoteDependencyAnalyzerClient.GetIllegalTypeDependencies(IEnumerable`1 sourceFilePaths, IEnumerable`1 referencedAssemblyPaths)
   à Codartis.NsDepCop.Core.Implementation.Analysis.DependencyAnalyzerBase.<PerformAnalysis>d__9.MoveNext()
   à Codartis.NsDepCop.Core.Implementation.Analysis.DependencyAnalyzerBase.<AnalyzeCore>d__8.MoveNext()
   à Codartis.NsDepCop.MsBuildTask.NsDepCopTask.Execute()

I've read all other issues about this config (using 1.9.0), so it should have plenty of time to connect :

<NsDepCopConfig IsEnabled="true" CodeIssueKind="Error" ChildCanDependOnParentImplicitly="true" AnalyzerServiceCallRetryTimeSpans="100,1000,10000,30000">
    <Allowed From="*" To="*" />
    <Disallowed From="Quadra.Affixe2.Application.Bodac.*" To="Quadra.Affixe2.Core.Commun.*" />
    <Disallowed From="Quadra.Affixe2.Application.Bodac.*" To="Quadra.Affixe2.Application.Commun.Private.*" />
</NsDepCopConfig>

It's working perfectly on all developers laptops, the only problem is the CI builds.

Due to the way Azure devops is build, the MSBuild process should run as a system user (NETWORK_SERVICE IIRC), can it cause this problem ?

Thanks in advance.

Sébastien

realvizu commented 5 years ago

Hi,

When NsDepCop.ServiceHost starts listening it configures security so that everyone can connect. Here's the relevant code: https://github.com/realvizu/NsDepCop/blob/c16b81def8ffc8e9c47b34a90244b5095ec9ecec/source/NsDepCop.ServiceHost/Program.cs#L61-L79 Se either this code is broken (maybe it doesn't work well on a localized OS -- I noticed that your Windows speaks French) or the problem is something else.

First we should narrow down the problem a bit.

seblucas commented 5 years ago

Sorry for the delay, I'll test that this afternoon and keep you posted.

seblucas commented 5 years ago

Se either this code is broken (maybe it doesn't work well on a localized OS -- I noticed that your Windows speaks French) or the problem is something else.

My laptop is also in french and everything is working fine.

seblucas commented 5 years ago

I spend all yesterday afternoon looking for an explaination and haven't found a clue. I guess that's a problem on my end. I'll close this. thanks for the help