locked
Unable to find assembly RRS feed

  • Question

  • Hello,

    I have problem with unit testing in Visual Studio 2017 15.5.5 Profesional. I got message An exception occurred while invoking executor 'executor://mstestadapter/v2': Unable to find assembly 'log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a'.

    Problem is that I don't have log4net assembly referenced. 

    When I reference log4net and click Run test there is this exception and test doesn't run. Why there is exception about assembly log4net when I comment all lines where log4net is it and remove referenced to it? Is there any cache?

    Monday, February 19, 2018 11:40 AM

Answers

  • I found problem.

    I encapsulate log4net in my class. In ctor I need some data from database (Log batch id - it is not important). So I have:

    public Logger()

    {

    log = log4net.LogManager.GetLogger(typeof(Logger)); log4net.LogicalThreadContext.Properties["LogRunId"] = 0; //get max+1 log from database

    }

    When I change LogicalThreadContext to ThreadContext unit test is worked fine.

    Example is here: https://1drv.ms/u/s!AtGI8jaUqSfuiNhRtwmmxkr-YhoWPA

    • Proposed as answer by Judy ZhuY Thursday, February 22, 2018 1:28 AM
    • Marked as answer by Petr B Thursday, February 22, 2018 5:44 AM
    Wednesday, February 21, 2018 9:50 PM

All replies

  • Hi Petr B,

    Welcome to the MSDN forum.

    What unit test project did you test, Unit Test Project (.NET Core) or Unit Test Project (.NET Framework)?

    Please have a try with the following to troubleshoot this issue, and test again:

      • Please right click the test project, choose Properties, change the Target framework to ".NET Framework 4.6.1" under Application node. Then, rebuild the project and run it.

      • Please try to install the log4net use NuGet (right click the test project, and choose Manage NuGet Packages…, find the log4net under Browse node and install it).

      • Please open the ".csproj" file in notepad, check the reference from .csproj, does it point to the right dll file (is the path to log4net.dll correct)?

      • Remove "%temp%\VisualStudioTestExplorerExtensions"

    If above methods could not help you, please share the test project to me? That will be helpful to repro the issue in my side and find the solution. Thanks for your understanding.

    About sharing via OneDrive, please refer to:

    https://onedrive.live.com/


    Regards,

    Judyzh


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    • Edited by Judy ZhuY Tuesday, February 20, 2018 3:01 AM
    Tuesday, February 20, 2018 3:01 AM
  • Thanks for reply. I tried remove all code where log4net is used and finally I removed log4net reference from project. Error was still there. Then I tried remove "%temp%\VisualStudioTestExplorerExtensions". It worked fine without error. But there was not log4net reference. 

    When I added log4net reference back, error went back. There is not directory which I removed. I installed log4net from nuget by package manager. I will investigated it. I will share this project with you when I cannot find any solution but give me some time please, I'm very busy :) 

    I use unit test project (.NET Framework).


    • Edited by Petr B Tuesday, February 20, 2018 9:21 AM spelling
    • Proposed as answer by Judy ZhuY Wednesday, February 21, 2018 1:51 AM
    Tuesday, February 20, 2018 9:18 AM
  • Hi Petr B,

    >> Then I tried remove "%temp%\VisualStudioTestExplorerExtensions". It worked fine without error.

    If my reply could help you, could you please mark it as an answer?

    And, if you find any other solutions, welcome to share the solutions here, this will help other community members who encounter the same issue with you.

    Thanks for your understanding and looking forward your reply.

    Regards,

    Judyzh


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, February 21, 2018 1:51 AM
  • I found problem.

    I encapsulate log4net in my class. In ctor I need some data from database (Log batch id - it is not important). So I have:

    public Logger()

    {

    log = log4net.LogManager.GetLogger(typeof(Logger)); log4net.LogicalThreadContext.Properties["LogRunId"] = 0; //get max+1 log from database

    }

    When I change LogicalThreadContext to ThreadContext unit test is worked fine.

    Example is here: https://1drv.ms/u/s!AtGI8jaUqSfuiNhRtwmmxkr-YhoWPA

    • Proposed as answer by Judy ZhuY Thursday, February 22, 2018 1:28 AM
    • Marked as answer by Petr B Thursday, February 22, 2018 5:44 AM
    Wednesday, February 21, 2018 9:50 PM
  • Hi Petr B,

    Glad you have resolved your issue, please mark your reply as an answer, this will help other community members who encounter the same issue with you.

    Thanks for your understanding.

    Regards,

    Judyzh


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, February 22, 2018 1:28 AM