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

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

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.

it’s definitely something I do wrong because in Edit mode the test pass but in standalone it doesn’t.

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 :frowning:

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. :frowning:

2 Likes

@RGV Did you ever find a fix for this? I’m finding the Unity Editor Mode a pain too

@RGV managed to get it working by changing the API compatibility level in Project Settings → Player → Configuration to .NET Framework.

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

Hope this helps!

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

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.

1 Like

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):
8981335--1235680--upload_2023-4-29_13-48-44.png

1 Like