Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Can't launch nunit unit tests with rider due to netstandard.dll not loading

Discussion in 'Testing & Automation' started by rbitard, Jun 5, 2022.

  1. rbitard

    rbitard

    Joined:
    Jan 11, 2022
    Posts:
    197
    Hello, I have this weird error since I upgraded to unity 2021.3 (.2f1) from 2020.3.
    I have an assembly definition for my tests where I load needed AD and nunitframework.dll
    upload_2022-6-5_23-47-34.png

    But when I execute my tests I have a System.BadImageFormatException when I look in detail I have
    Impossible to load file or assembly 'netstandard, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies (Exception HRESULT : 0x80131058).

    Do you know what causes this ? I look csproj and found the netstandard reference that correctly points to a dll on my drive.
    Thanks in advance if you can point me in the correct direction to solve this.
     
  2. rbitard

    rbitard

    Joined:
    Jan 11, 2022
    Posts:
    197
    it's definitely something I do wrong because in Edit mode the test pass but in standalone it doesn't.
    upload_2022-6-5_23-55-26.png
     
  3. rbitard

    rbitard

    Joined:
    Jan 11, 2022
    Posts:
    197
    if I switch the API compatibility Level* from .net Standard 2.1 to .Net framework in my project settings the tests works but I can't build my application anymore :(
     
  4. RGV

    RGV

    Joined:
    Jan 25, 2016
    Posts:
    48
    I think there is a deeper problem regarding Unity+Rider+UnitTesting.
    These broke back in late 2020. Standalone NUnit launcher is not properly working since.
    I've try everything I have found here and there but still cannot make it work back. TDD with Unity Editor Mode is such a cumbersome waiting cycle. :(
     
    AshMcConnell and rbitard like this.
  5. AshMcConnell

    AshMcConnell

    Joined:
    Aug 10, 2011
    Posts:
    11
    @RGV Did you ever find a fix for this? I'm finding the Unity Editor Mode a pain too
     
  6. AshMcConnell

    AshMcConnell

    Joined:
    Aug 10, 2011
    Posts:
    11
    @RGV managed to get it working by changing the API compatibility level in Project Settings -> Player -> Configuration to .NET Framework.
    upload_2022-11-7_20-34-28.png

    Also added the nunit.framework.dll to the Assembly References in my Tests asmdef

    upload_2022-11-7_20-34-46.png

    Hope this helps!

    *EDIT* arg, I didn't read the thread properly. This will help for unit testing, but it won't build.
     
  7. RGV

    RGV

    Joined:
    Jan 25, 2016
    Posts:
    48
    Didn't work to me because of what you highlighted in the edit. NUnit standalone requires a build, which fails. It says “invalid option 9.0 for /langversion...”. Whatever I try, a new error arises then a new one until I get back to this very first error.
    It's really cumbersome, this regression.
     
    AshMcConnell likes this.
  8. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,533
    But generally it would work switching to .NET Framework for tests, and switching to .NetStandard for builds? Because we should be able to script that switch when making a build using a rather simple build override script.

    I wonder if you have the same issue in Rider, where I cannot select .NetStandard as the target framework for any new project (not just Unity Class Library):
    upload_2023-4-29_13-48-44.png
     
    RGV likes this.