Coded UI Test now gets error about Newtonsoft.json not being found

白昼怎懂夜的黑 提交于 2019-12-06 06:48:27

The error

The error message is

Could not load file or assembly 'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies.

One thing to know here is that this error has two options:

  1. It cannot find Newtonsoft.Json
  2. It cannot find a dependency

The analysis

The typical way to analyze this sort of problem is using Process Monitor [Microsoft SysInternals].

If you want to do it fully manually, follow these steps:

  1. Run Process Monitor
  2. Add a filter for the executable which has the problem
  3. Reproduce the issue
  4. Stop recording events once the problem has been reproduced
  5. The hard task: From the bottom, look for errors Name not found, Path not found or Access denied. You have to find a DLL that has a problem and is not followed by Success later (which may happen if the DLL is found late in the search paths).

I have automated this process and provide Process Monitor Log Analyzer for download. Disclaimer: I'm the author of this free tool.

With that tool, the steps are:

  1. Run Process Monitor
  2. Add a filter for the executable which has the problem
  3. Reproduce the issue
  4. Stop recording events once the problem has been reproduced
  5. Save Process Monitor log as XML
  6. Open the XML in Process Monitor Log Analyzer
  7. Go though the items from top to bottom

Your questions

The question then is, why did this start after changing the user that the Coded UI system runs tests under?

Maybe the "old" user had sufficient access rights and the "new" user doesn't. This should not be the reason for an admin user (though still possible).

Maybe the "old" user had different folders in the PATH and the "new" user doesn't.

The interesting thing is that Newtonsoft.Json (aka Json.Net) isn't used in the project at all or any referenced libraries.

I wonder how you checked that. Note that you cannot simply use Dependency Walker for .NET. You need something .NET specific, e.g. dotPeek [JetBrains], but dotPeek does not show all dependencies at once, you'd need to go through all references manually. However, this will not find missing native DLLs. Therefore, the most reliable way for me is Process Monitor as described before.

What could cause that error message and be machine/test code independent?

Same as before: user specific configurations.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!