Install `System.ComponentModel.DataAnnotations.dll` to a MacOS Unity project - c#

I need System.ComponentModel.DataAnnotations.dll as a dependency for openapi-generate, but I can't seem to get a valid dll.
I've tried using
NuGet for Unity (silently fails to install, other packages do work)
Installing with VisualStudio (indicates that it's installed, but doesn't resolve the reference errors)
Directly copying the dll from Mono.framework (says that .dll doesn't contain valid CIL)
I'm using Unity 2021.3.6f1 what are my options here as far as diagnosing, understanding and fixing dependency problems like this?

Related

Type CallerMemberNameAttribute exists in both System.Runtime 2.6.10 and mscorlib

I have a Class Library running on .Net 4.7. Attempting to upgrade this project to and SDK style i take the following steps in a terminal window (Im using Visual Studio 2022) and keep the target to 4.7
dotnet tool install --global Project2015To2017.Migrate2019.Tool
dotnet migrate-2019 wizard proj.csproj
(Received an error about the runtime not being installed on my machine so clicked the link and installed.)
I get some messages but no real errors as such e.g.
A better way to reference 'System.ComponentModel.Composition' assembly is using respective 'System.ComponentModel.Composition' NuGet package. It will simplify porting to other runtimes and enable possible .NET SDK tooling improvements.
and
Consider migrating to 'portable' debug type, cross-platform alternative to legacy Windows PDBs.
Number of these types of messages appear.
I load up the solution in VS 2022 and try to rebuild but some NuGet package errors occur so i restore all packages using the Nuget restore command.
Im now faced with the error
The type 'CallerMemberNameAttribute' exists in both System.Runtime VErsion 2.6.10.0 and mscorlib Version 4.0.0.0
This occurs on the line
public void DoSomething([CallerMemberName] string nm = "")
{}
Ive tried to reference this explicitly i.e. System.Runtime.CompilerServices.CallerMemberName but that didnt work and not entirely sure what i could attempt to resolve this?

Importing NSubstitute into Unity project

I'm trying to use NSubstitute in my Unity project (Unity version 2019.2.2f1). No matter how to import it, my IDE, both Visual Studio and JetBrains Rider, would give an error when I try using NSubstitute saying NSubstitute is undefined.
I have tried many options and versions of NSubstitute packages (4.2.1 and 2.0.3). I also import the dll file from net35 folder of the package into a Plugins folder in my Unity project. I also tried to install the same version of NSubstitute using Nuget in the IDE.
I added NSubstitute 4.2.1 (.NET Standard 2.0) in a Unity project, but I needed to include 3 more dependencies for it to work:
system.threading.tasks.extensions.4.5.3
system.runtime.compilerservices.unsafe.4.6.0
castle.core.4.4.0
Update 2020
If you read this in 2020 or later, check the answer from Rodrigo Eleuterio how to make this work with the latest version of NSubstitute.
/end update
I was able to make the 2.0.3 version work with Unity. The newer versions have additional dependencies which I could not make work in Unity, so it seems for now we're stuck with 2.0.3. So here is how I did it:
Download 2.0.3 from the NuGet Website.
Unzip the file and move the lib/net35/NSubstitute.dll into the Plugins folder of your project.
In your test assembly definition, don't forget to reference it, otherwise it will not be found.
When you now reopen the project in Rider it should be found. Sometimes Unity acts up a little and doesn't seem to find the DLL. In this case re-importing the project can help.

Why nuget tries to look for `dll` file on Linux

I am working on Debian Stable Linux and installing packages using nuget. However, sometimes I get error message where nuget is not able to find a dll file. For example:
$ nuget install Accord.Math
Attempting to resolve dependency 'Accord (≥ 3.8.0)'.
Installing 'Accord.Math 3.8.0'.
Could not find a part of the path "/tmp/nuget/sh5gjtik.wke/lib/netstandard2.0/Accord.Math.dll".
Since dll is a windows file, I am not able to understand why nuget is looking for them on Linux.
Also, how can this problem be solved?

Failed to run reference rewriter with command error with unity error when adding a DLL to the assets folder

I have encountered this error when I am adding the DAI.dll to the assets folder.
this error happens when I try to build.
UnityException: Failed to run reference rewriter with command --target="Temp\StagingArea\DAI.dll" --additionalreferences="Temp\StagingArea","C:\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.17134.0\Facade","C:\Program Files (x86)\Windows Kits\10\References\10.0.17134.0\Windows.AI.MachineLearning.Preview.MachineLearningPreviewContract\1.0.0.0","C:\Program Files (x86)\Windows Kits\10\References\10.0.17134.0\Windows.ApplicationModel.Calls.CallsVoipContract\3.0.0.0","C:\Program Files (x86)\Windows Kits\10\References\10.0.17134.0\Windows.ApplicationModel.SocialInfo.SocialInfoContract\2.0.0.0","C:\Program Files (x86)\Windows Kits\10\References.....(followed by alot more of this)....
I am using visual Studio 2017 version 15.7.3 and Unity version 2017.2.0b7
I have added the DLL to the assets folder in unity.
These are my player and build settings.
You need to change the settings in unity (Settings example in the photo below):
Find your dll file in your project inside Unity.
Click on it once to highlight it.
You will see the dll options in the Isnpector
Usually for HoloLens, you only select "WSAPlayer"
Click Apply to save settings.
Rebuild
Warnings
Sometime the dll that you trying to include is referencing something else is not included and that's why it will not work, but the error will be different than what you got.
Sometimes you may need to import an older version of the DLL. For example, I tried to import Newtonsoft.Json 11.0.2, but 11.0.2 was referencing a newer core framework than the solution that unity generate. There is a way to update it, but I didn't want to deal with it every time, so I found out that the highest version that I can use is 9.0.1 (I had to skip 11.0.2, 11.0.1, 10.0.3, 10.0.2, 10.0.1).
Also, keep in mind that you should include netstandard dll.
I usually have UWP test project in hand to try to test my dll with it. If it works there, then it is a good first step that it may work after importing it to Unity assuming it does not have dependencies.
Last result workaround
You can comment the code that references your dll
build the project from unity without the dll
in the generated UWP solution, you can add dll normally and even use nuget to install your desired dll
Uucomment your code.
Build your solution then deploy to your device or create a package to deploy it to device or store.
This works nicely as a work around.
One issue with this is that you will need to import dll or install nuget every time solution generated if it was deleted. It gets annoying and if you are working with a team, it can get confusing when they get the project and think that it does not work. Meaning you need to do more work to communicate and deploy.
Second issue, Unity is moving away from .NET backend to IL2CPP (I don't think you can do this in the CPP generated project). Meaning this is a short term workaround.
Consider upgrading to Unity 2018.2
Using .NET 4.X instead of .NET 3.4 Equivalent made my life easier with references and issues related to references and using more modern C# code.
You can install it and still keep the 2017 version if you install Unity Hub. This will minimize the risk of considering the update.

The namespace RDotNet could not be found

I'm trying to use R with C#. I'm using Unity and MonoDevelop on the C# side and I've R version 3.2.1. I've tried my best to follow instructions here: http://jmp75.github.io/rdotnet/getting_started/
But I'm stuck. Here's what I've done
download nuget.exe, put it in a folder already in PATH.
open CMD.exe
run nuget install R.NET.Community
If I try to reinstall R.NET.Community with the same command above, I got the message that it is already installed (which is good I guess).
My question : what now? I tried to run the RDotNet namespace, but it's not recognized. Obviously I need to set up something else, but I do not know where and what. Any lead would be appreciated!
I wouldn't expect just running the nuget install to add a reference into your project - the nuget installer is basically just downloading the package for you.
You could manually add a reference in your project to the relevant assembly file (.dll) that has been downloaded. However, it would be better to use a package manager within MonoDevelop. If you're using MonoDevelop 3.x or 4.5, you should use the NuGet MonoDevelop add-in and use that to manage the NuGet packages for your project. MonoDevelop 5.x has a NuGet package manager built in, apparently.

Categories

Resources