Using System.Data.SQLite in Unity with EF6: "Module 'System.Data, Version=4..." should be referenced

I’m trying to add System.Data.SQLite with EF6 support to my Unity project (targeting .NET 4.x Equivalent). However, when trying to build the connection string, I get the following error:
The type ‘System.Data.Common.DbConnectionStringBuilder’ has been forwarded to an assembly that is not referenced. Consider adding a reference to assembly ‘System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’

When opening the class in Visual Studio, I get the following error on the SQLiteConnectionStringBuilder:
“Module 'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089” should be referenced

I can add the reference through Visual Studio, but when I return to Unity, the reference gets removed on Unity’s recompile (by design, Unity doesn’t know Visual Studio added a reference in the generated .csproj and it gets overwritten.)

I have tried adding a mcs.rsp file with -r:System.Data.dll and the error in Unity goes away, but when I open Visual Studio to edit the class, I get the same error and the project’s references don’t show System.Data.dll.

I’m assuming since the error went away in Unity that the mcs.rsp file is doing its job, but why isn’t it reflecting that in Visual Studio? Is there anything else I need to do?

1 Like

We ended up going with SQLite-NET instead, trying to avoid the problem. However, the same issue came up when trying to reference models in our OpenAPI .dll with System.ComponentModel.DataAnnotations. I have been able to mitigate the issue in Visual Studio by including System.ComponentModel.DataAnnotations.dll in our Unity project, but Unity then complains “Loading script assembly “Assets/Plugins/WebAPI.Client/System.ComponentModel.DataAnnotations.dll” failed!”. But it still builds normally and runs in PlayMode, so I’m not sure what’s going on there.