How to add System.Data.dll in Unity? [duplicate] - unity3d

I'm using Visual Studio for my Unity project. (Unity is using mono framework, NOT .net). I'm using a database so I have to use System.Data.dll in the project which i'm keeping in Assets/Plugins folder:
As you can see Visual Studio has problems seeing System.Data library. So I'm hardcoding:
And some more red lines:
Surprisingly, I have no errors in Unity and the code is actually working:
I also have this annoying yellow icon in VS:
Can you help me in forcing Visual Studio to see System.Data library please?

The System.Data.dll, System.MySql.dll and System.Drawing.dll should all placed in the Assets folder not in the Assets/Plugin folder. Making these changes get ride of the error.
EDIT:
Adding System.Data.dll to the Assets folder should work but is failing silently. Digging deeper into this, I got this error:
The primary reference "System.Data" could not be resolved because it
has a higher version "2.0.5.0" than exists in the current target
framework. The version found in the current target framework is
"2.0.0.0".
So, the System.Data.dll version is different from your target framework and that is the problem. You need another version of System.Data.dll that is the-same version of your target framework(2.0.0.0).
You can get a compatible version(2.0.0.0) from:
C:\Program Files (x86)\Reference
Assemblies\Microsoft\Framework\.NETFramework\v3.5\Profile\Unity Subset
v3.5

Related

Maui build and publication issues

I have a MAUI project that references 3 .dll's that are built with netstandard2.1. I am working on a Mac with Ventura MacOS and Visual Studio 2022 17.4.2. I am having a problem building the .ipa for the iOS platform. I can compile all of the elements of the project but when I run the command
"dotnet publish -f:net6.0-ios -c:Release /p:ArchiveOnBuild=true -r:ios-arm64 --no-self-contained"
I get 3 errors all related to the .dll project files not referencing .net6.0-ios.
/usr/local/share/dotnet/sdk/6.0.404/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(267,5):
error NETSDK1005: Assets file
'/Users/davidrutter/Projects/RadixIQDealerPortal/aspnet-core/src/RadixDealerPortal.HttpApi.Client/obj/project.assets.json'
doesn't have a target for 'net6.0-ios'.
I've tried several things and searched all over trying to find a solution but without success. If anyone has an idea how to resolve this I would be truly appreciative.
You want to use the framework net6.0, net6.0-ios should not make a difference here as you are using --no-self-contained.
Leaving the options for net6.0-ios out should work too, as you already have the runtime defined.
TLDR;
remove -f:net6.0-ios

Visual Studio Code on Apple M1 chip and .NET Core 3.1

Trying to set up my dev env on my mac machine with M1. Downloaded VSCode and all required SDKs.
I am able to run any project >=6.x (because MSFT has native SDK for ARM64), but struggling in running projects that target .NET Core 3.1 for instance.
Here is what I get as an error when I try to build\run:
Architecture: arm64
Framework: 'Microsoft.AspNetCore.App', version '3.1.0' (arm64)
.NET location: /usr/local/share/dotnet/
The following frameworks were found:
6.0.7 at [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Learn about framework resolution:
https://aka.ms/dotnet/app-launch-failed
To install missing framework, download:
https://aka.ms/dotnet-core-applaunch?framework=Microsoft.AspNetCore.App&framework_version=3.1.0&arch=arm64&rid=osx.12-arm64
I have tried to run VSCode using rosseta to emulate Intel without any luck. Looks like omnisharp extension needs to be updated, but not sure what exactly to change.
Appreciate any help!
P.S. Everything works in Visual Studio, but not in vscode.
UPDATE
Adding path (/usr/local/share/dotnet/x64) to x64 in /etc/path makes the
trick, but I don't like this kind of trick, let me know guys if you have an any better solution...
Adding an answser here as well as a comment, as formatting in comments doesn't work...
I needed to edit the file
/etc/paths
to add the line:
/usr/local/share/dotnet/x64
Note that you may not see the /etc folder in Finder on the mac because it's hidden.
To see hidden files/folders in Finder, press Shift-Cmd-1
The above key combination toggles hidden folder/file visibility

Unity + ClearScript - Importing DLL

I'm trying to use ClearScript in Unity, but fail because Unity does not see the DLL.
To be sure, I cloned the project and had the DLLs built. I did this using the instructions from ClearScript.
The goal is to use the DLL on HoloLens, which in turn means I have UWP as the platform and ARM64 as the architecture.
But I also want to have valid references during the implementation in Unity and not have constantly grayed out code because of the scripting symbols (such as UNITY_WSA).
So what did I do?
Screenshot - I took the dlls out of the output-net4.5-folder and set the api compatibility level in unity to .NET 4.x. The red ones are the dlls that I need and the blue ones only if I realy need to use V8, like already mentioned by the instruction from ClearScript.
All the dlls, except "..win-x64|86.dll", are managed dlls and should work out of the box in unity. So this are the import settings for the managed dlls and the settings for the unmanaged|native dlls.
So what did I miss or what did I do wrong? I used in the past for example another javascript interpreter, called Jint, where I also just took the managed dll out of the .net-4.5-build folder, imported it under Assets/Plugins/Jint and used it in my code just by adding the using in my classes.
I'm not sure if I should actually be happy or sad. Unity does what it feels like doing. The whole time (2 days) it didn't want to load the DLL for me. Just now I opened Unity for the 30th time and suddenly Unity recognized the DLL and listed it under references in the vs-unity-project.
So I doubted whether Unity, after making changes in Unity, actually reassembles the VS project.What did I do to confirm the guess and what do you need to do to solve the problem? I added a new DLL, this of course was not seen by unity and not referenced in the vs-unity-project. Then I deleted the solution file and the C# project file from the Unity project and restarted Unity. And when I reopened the VS Unity project (by opening a c# script), all the DLLs including the new DLL were suddenly referenced and the usings worked!

How to fix "The type or namespace name could not be found"?

Visual studio wont recognize certain packages (Entities, and TMPro, to name a few) and it gives the error: The type or namespace name could not be found; but everything compiles fine. I know there are already many questions and answers related to this problem, but so far none of them have worked for me.
So the way I downloaded these packages was by using the Unity Package Manager, so this makes things even more confusing because I installed other packages the same way, and they are recognized no problem.
So far I have tried:
Checking the target framework of the packages and the project (all are .NET Framework 4.6)
Deleting the Library folder
Checking my Unity version (2019.2.0a11)
Some extra notes:
I've had this issue for a long time now (with TMPro to be specific; for about a year) ever since downloading it from the Package Manager in one of the 2018.X versions
In other Unity projects, which are using various versions, give the same result. This leads me to believe it is something to do with my visual studio.
The Entities package shows up on the side, see picture below
I uninstalled Visual Studio 2017 installed Visual Studio 2019 and it fixed my problem. I suspect re-installing like others suggested may have worked too.

FxCop indirect reference to System.Core version 2.0.5.0

I've got a project that uses Autofac, and the WebAPI integration
We run FxCop over our solution, and on opening autofac, I get the following:
The following indirectly-referenced assembly could not be found. This
assembly is not required for analysis, however, without it, analysis
results could be incomplete. This assemble was referenced by
Autofac.dll
System.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes
This causes the following error on our CI server:
FxCop return code (516): PROJECT_LOAD_ERROR ASSEMBLY_REFERENCES_ERROR
Is there a way to tell FxCop to ignore this?
Had the same issue with AutoMapper 3.1.0 on our project. The real problem is an old version of FxCop. The last official release was FxCop 10.0, but new versions of FxCop have been bundled with Visual Studio since 2012.
I just replaced the FxCop 10.0 with the version that can be found in:
C:\Program Files (x86)\Microsoft Visual Studio 11.0\Team Tools\Static Analysis Tools\FxCop
or
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Team Tools\Static Analysis Tools\FxCop
and the problem was solved.
This is a common FxCop thing when running with Portable Class Libraries. It's not Autofac; you just happen to see it because Autofac is the only PCL you're using. In my experience, this error doesn't seem to happen if you're building on a Windows 8 machine, but on Windows 7 or Server 2008R2 I see this a lot.
It's not a bug, and no, you won't find 2.0.5.0 on your machine. That version is actually for Silverlight and runtime .NET "stuff" handles redirection to the right assembly version. Unfortunately, FxCop is less cooperative.
I see the same thing in my build and solved it using the suggestions from questions like this: How to fix FxCop error code 512?
You must add a reference to the assembly's directory in the FxCop project file. For instance:
<Targets>
<AssemblyReferenceDirectories>
<Directory>C:/Windows/Microsoft.NET/assembly/GAC_MSIL/Microsoft.Web.Infrastructure/v4.0_1.0.0.0__31bf3856ad364e35/</Directory>
<Directory>C:/Windows/Microsoft.NET/assembly/GAC_MSIL/System.Web.Mvc/v4.0_3.0.0.0__31bf3856ad364e35/</Directory>
</AssemblyReferenceDirectories>
Workaround for this issue is to copy the missing System.Core.dll to the project output directory. I made this as a postbuild event to copy System.Core.dll from a shared folder to project\bin directory.
You can get the copy of System.Core.dll from the Silverlight SDK 2 installation.
Now fxcop runs successfully without any issues. Note that I was using Fxcop integrator for Visual Studio 2010.