realvizu/NsDepCop

Unable to communicate with NsDepCop service

Closed this issue · 14 comments

TC-M commented

I am installing NsDepCop for the first time. NuGet package v1.8.0 installed without issue and created config.nsdepcop. Also, the extensions NsDepCop VS2017 and NsDepCop Config XML Schema Support installed without issue. However, every time I build my project, I get the "Unable to communicate with NsDepCop service" exception. I have read the Troubleshooting page and #29, in which a similar issue was reported. I know that you've diagnosed the cause of this exception as a timing issue -- the client doesn't wait long enough for the server to spin up. However, I've increased the wait times drastically and continue to get the error every time.

AnalyzerServiceCallRetryTimeSpans="1000,10000,100000"

Do you have any suggestions about how I might further debug this issue?

-TC

Is there a full exception string (with full exception message and call stack) in the build output? If so please post it.

TC-M commented
Severity	Code	Description	Project	File	Line	Suppression State
Error		Exception during NsDepCopTask execution: System.Exception: Unable to communicate with NsDepCop service. All retries failed. ---> System.Runtime.Remoting.RemotingException: Failed to connect to an IPC Port: The system cannot find the file specified.
 

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

Exception rethrown at [0]: 
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at Codartis.NsDepCop.Core.Interface.Analysis.Remote.IRemoteDependencyAnalyzer.AnalyzeProject(IAnalyzerConfig config, String[] sourcePaths, String[] referencedAssemblyPaths)
   at Codartis.NsDepCop.Core.Implementation.Analysis.Remote.RemoteDependencyAnalyzerClient.InvokeRemoteAnalyzer(IEnumerable`1 sourceFilePaths, IEnumerable`1 referencedAssemblyPaths)
   at Codartis.NsDepCop.Core.Implementation.Analysis.Remote.RemoteDependencyAnalyzerClient.<>c__DisplayClass6_0.<GetIllegalTypeDependencies>b__0()
   at Codartis.NsDepCop.Core.Util.RetryHelper.Retry[TResult](Func`1 func, Int32 maxRetryCount, BeforeRetryCallback beforeRetryAction)
   --- End of inner exception stack trace ---
   at Codartis.NsDepCop.Core.Implementation.Analysis.Remote.RemoteDependencyAnalyzerClient.OnAllRetriesFailed(Exception exception)
   at OneOf.OneOf`2.Match[TResult](Func`2 f0, Func`2 f1)
   at Codartis.NsDepCop.Core.Implementation.Analysis.Remote.RemoteDependencyAnalyzerClient.GetIllegalTypeDependencies(IEnumerable`1 sourceFilePaths, IEnumerable`1 referencedAssemblyPaths)
   at Codartis.NsDepCop.Core.Implementation.Analysis.Remote.RemoteDependencyAnalyzerClient.<>c__DisplayClass3_0.<AnalyzeProject>b__0()
   at Codartis.NsDepCop.Core.Implementation.Analysis.DependencyAnalyzerBase.<PerformAnalysis>d__9.MoveNext()
   at Codartis.NsDepCop.Core.Implementation.Analysis.DependencyAnalyzerBase.<AnalyzeCore>d__8.MoveNext()
   at Codartis.NsDepCop.MsBuildTask.NsDepCopTask.Execute()	AIM_LP_Engine_CS			

Well, unfortunately not much info in this exception.
All we know is the client part of NsDepCop running inside the msbuild.exe process cannot communicate with NsDepCop.ServiceHost.exe via remoting (named pipe).

Let's try this:

  1. Find the location of the downloaded NsDepCop nuget package.
  • If your project uses the packages.config package manager format then it's in: <solution folder>\packages\NsDepCop.1.8.0
  • Otherwise it's in: <your user folder>\.nuget\packages\NsDepCop.1.8.0
  1. Make sure you can find the NsDepCop.ServiceHost.exe and a bunch of dlls in the tools subfolder.
  2. Start a cmd.exe window and find its process ID in Task Manager.
  3. In the cmd.exe window change the current directory to the tools folder where NsDepCop.ServiceHost.exe is located and start it: NsDepCop.ServiceHost.exe <the process ID of the cmd.exe process>
  4. If it throws an exception then please post it.
  5. Download the pipelist tool that lists open named pipes (https://docs.microsoft.com/en-us/sysinternals/downloads/pipelist)
  6. Run pipelist from a cmd.exe window. In the tool's output you should see an entry starting with NsDepCop indicating that it's listening on a pipe.
  7. If you see in pipelist that NsDepCop service is actually listening then try to build your project and tell me what happens.
TC-M commented

I followed all the steps.

  • NsDepCop.ServiceHost.exe and many DLLs are in <solution folder>\packages\NsDepCop.1.8.0\tools.
  • NsDepCop.ServiceHost.exe runs from the command window without throwing an exception.
  • pipelist64.exe confirms that NsDepCop-1.8.0.204 is listening.
  • When I build the project, I get an exception different from before. The error message says "Unable to find assembly 'NsDepCop.Core...'", but I don't know why that is the case; NsDepCop.Core.dll is in <solution folder>\packages\NsDepCop.1.8.0\tools, and the version numbers match.
Severity	Code	Description	Project	File	Line	Suppression State
Error		Exception during NsDepCopTask execution: System.Exception: Unable to communicate with NsDepCop service. All retries failed. ---> System.Runtime.Serialization.SerializationException: Unable to find assembly 'NsDepCop.Core, Version=1.8.0.204, Culture=neutral, PublicKeyToken=null'.

Server stack trace: 
   at System.Runtime.Serialization.Formatters.Binary.BinaryAssemblyInfo.GetAssembly()
   at System.Runtime.Serialization.Formatters.Binary.ObjectReader.GetType(BinaryAssemblyInfo assemblyInfo, String name)
   at System.Runtime.Serialization.Formatters.Binary.BinaryConverter.TypeFromInfo(BinaryTypeEnum binaryTypeEnum, Object typeInformation, ObjectReader objectReader, BinaryAssemblyInfo assemblyInfo, InternalPrimitiveTypeE& primitiveTypeEnum, String& typeString, Type& type, Boolean& isVariant)
   at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.ReadArray(BinaryHeaderEnum binaryHeaderEnum)
   at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()
   at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
   at System.Runtime.Remoting.Channels.CoreChannel.DeserializeBinaryResponseMessage(Stream inputStream, IMethodCallMessage reqMsg, Boolean bStrictBinding)
   at System.Runtime.Remoting.Channels.BinaryClientFormatterSink.SyncProcessMessage(IMessage msg)

Exception rethrown at [0]: 
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at Codartis.NsDepCop.Core.Interface.Analysis.Remote.IRemoteDependencyAnalyzer.AnalyzeProject(IAnalyzerConfig config, String[] sourcePaths, String[] referencedAssemblyPaths)
   at Codartis.NsDepCop.Core.Implementation.Analysis.Remote.RemoteDependencyAnalyzerClient.InvokeRemoteAnalyzer(IEnumerable`1 sourceFilePaths, IEnumerable`1 referencedAssemblyPaths)
   at Codartis.NsDepCop.Core.Implementation.Analysis.Remote.RemoteDependencyAnalyzerClient.<>c__DisplayClass6_0.<GetIllegalTypeDependencies>b__0()
   at Codartis.NsDepCop.Core.Util.RetryHelper.Retry[TResult](Func`1 func, Int32 maxRetryCount, BeforeRetryCallback beforeRetryAction)
   --- End of inner exception stack trace ---
   at Codartis.NsDepCop.Core.Implementation.Analysis.Remote.RemoteDependencyAnalyzerClient.OnAllRetriesFailed(Exception exception)
   at OneOf.OneOf`2.Match[TResult](Func`2 f0, Func`2 f1)
   at Codartis.NsDepCop.Core.Implementation.Analysis.Remote.RemoteDependencyAnalyzerClient.GetIllegalTypeDependencies(IEnumerable`1 sourceFilePaths, IEnumerable`1 referencedAssemblyPaths)
   at Codartis.NsDepCop.Core.Implementation.Analysis.Remote.RemoteDependencyAnalyzerClient.<>c__DisplayClass3_0.<AnalyzeProject>b__0()
   at Codartis.NsDepCop.Core.Implementation.Analysis.DependencyAnalyzerBase.<PerformAnalysis>d__9.MoveNext()
   at Codartis.NsDepCop.Core.Implementation.Analysis.DependencyAnalyzerBase.<AnalyzeCore>d__8.MoveNext()
   at Codartis.NsDepCop.MsBuildTask.NsDepCopTask.Execute()	AIM_LP_Engine_CS			

I have no clue what is happening.
Can you post an example project here on github so I can try to run it on my machine and get a repro?

TC-M commented

I have new findings to report.

I tried to create a sample project to send you as a demonstration of the error, but I was not able to reproduce the error in a new project -- NsDepCop worked perfectly. That suggests there is something unusual about my work project which causes the error. However, I can't figure out what that is.

Here is something else interesting: If NsDepCop starts successfully, it continues working for all projects, but if it starts with a failure, it continues to fail for all projects. Suppose I open two Visual Studio windows, one with my work solution and one with my sample solution. If the first project I build is in the sample solution, NsDepCop will succeed and continue to work when I build projects in my work solution. If the first project I build is in my work solution, then NsDepCop will fail and continue to fail when I build projects in my sample solution.

I'll let you know if I learn anything else.

Please try one more thing.
Set MsBuild's log verbosity to Detailed in Visual Studio / Tools / Options / Projects and Solutions / Build and Run / MSBuild project build output verbosity.
Then you can find NsDepCop's trace messages in the Output window by searching for the string: [NsDepCop]
Try to generate a log for the failing and for the succeeding cases too. Maybe we can figure out something from any differences we may find in them.

TC-M commented

It looks like the problem is related to spaces in the solution folder path. Here is part of the detailed error log:

2>  [NsDepCop] Trying to activate analyzer service (attempt #1).
2>  [NsDepCop] Starting C:\Users\TC\Documents\AIM%20Code\trunk\packages\NsDepCop.1.8.0\tools\NsDepCop.ServiceHost.exe with parameter 11320
2>  [NsDepCop]   Working folder is C:\Users\TC\Documents\AIM%20Code\trunk\packages\NsDepCop.1.8.0\tools
2>  [NsDepCop] AnalyzerServiceActivator.CreateServer failed: System.ComponentModel.Win32Exception (0x80004005): The directory name is invalid

When I changed the folder name from "AIM Code" to "AIM_Code", the errors ceased.

Wow, thanks a lot for taking the time to figure it out!
I'll fix it as soon as I'll have some time.

Fixed in v1.8.1: https://www.nuget.org/packages/NsDepCop/1.8.1
Please let me know whether that fixed the issue!

TC-M commented

You're right, there was another similar bug in the assembly resolution folder name handling.
Fixed in: https://www.nuget.org/packages/NsDepCop/1.8.2-beta1

Now I'm a bit more cautious and publish the fix as beta version and will publish a release when you confirm that it actually fixed the issue. Please let me know!

I had the same issue with a space in the solution path and I can confirm that the beta indeed fixes it.

Thanks for the feedback.
The fix is released: https://www.nuget.org/packages/NsDepCop/1.8.2