- Home /
How to fix losing System.Data.dll in Project?
I am trying to add a database connection to my server application, and need to have a reference to System.Data.dll for that. Everything is fine when I add the reference manually.
However, everytime Unity rebuilds the project and Visual Studio 2013 prompts me to reload the project, the System.Data.dll-Reference is there, but with an exclamation mark, meaning it could not be loaded. Looking at the properties of the corrupt reference, the path is empty.
The System.Data.dll is already in the Assets/Plugins/-Folder.
How can I fix this?
Answer by Lohrion · Jul 03, 2015 at 12:43 PM
Thank you @incorrect, your second comment actually brought me on the right track. The last post in that thread refers to this page, where this problem is solved (but if I interpret it correctly, they will not fix this as it is not a bug). If you want, you can just repost this as an answer and I will delete mine and accept yours :)
Basically, you need to add the following code in your Assets/Plugins/Editor folder. You can also modify it to work with other DLLs.
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using SyntaxTree.VisualStudio.Unity.Bridge;
using UnityEditor;
namespace Assets.Plugins.Editor
{
[InitializeOnLoad]
public class ProjectFileHook
{
// necessary for XLinq to save the xml project file in utf8
class Utf8StringWriter : StringWriter
{
public override Encoding Encoding
{
get { return Encoding.UTF8; }
}
}
static void ProcessNodesWithIncludeAttribute(XDocument document, string localName, string includeValue, Action<XElement> action)
{
var nodes = document
.Descendants()
.Where(p => p.Name.LocalName == localName);
foreach (var node in nodes)
{
var xa = node.Attribute("Include");
if (xa != null && !string.IsNullOrEmpty(xa.Value) && string.Equals(xa.Value, includeValue))
{
action(node);
}
}
}
// Remove System.Data from project (not from file system so Unity can compile properly)
static void RemoveFileFromProject(XDocument document, string fileName)
{
ProcessNodesWithIncludeAttribute(document, "None", fileName, element => element.Remove());
}
// Adjust references, by using the default framework assembly instead of local file (remove the HintPath)
static void RemoveHintPathFromReference(XDocument document, string assemblyName)
{
ProcessNodesWithIncludeAttribute(document, "Reference", assemblyName, element => element.Nodes().Remove());
}
static ProjectFileHook()
{
ProjectFilesGenerator.ProjectFileGeneration += (string name, string content) =>
{
var document = XDocument.Parse(content);
RemoveFileFromProject(document, @"Assets\System.Data.dll");
RemoveHintPathFromReference(document, "System.Data");
var str = new Utf8StringWriter();
document.Save(str);
return str.ToString();
};
}
}
}
Didn't work for me.. am I missing something..?? I updated the string path to be the correct path...
Answer by walidabazo · Oct 01, 2017 at 07:02 PM
You can show this videos to connect unity 3d and sqlite and solved all dll error compile for different windows 32bit and 64bit