- Home /
Using TextFieldParser class from Microsoft.VisualBasic.FileIO
Hi, I am trying to use the TextFieldParser class to parse some CSV files in my project.
I am using Unity 2019.3.9f1. Under Edit > Project Settings > Player > Other Settings, I have API Compatibility Level set to .NET 4.x. (Supposedly, this should provide my project access to .NET 4 API, which contains Microsoft.VisualBasic.FileIO.) In the C# script I am attempting to use TextFieldParser in, I have "using Microsoft.VisualBasic.FileIO;". When I open my Unity project, I receive the following error message in the Unity console: "error CS0234: The type or namespace name 'FileIO' does not exist in the namespace 'Microsoft.VisualBasic' (are you missing an assembly reference?)".
The platform I have specified in Build Settings is iOS if that is relevant information also.
I have tried adding an assembly reference through Visual Studio (Community 2019). I open up the .csproj file overseeing the .cs file that I am trying to add TextFieldParser to, right-click it to add a reference, and browse to the Microsoft.VisualBasic.dll file found in my Unity installation's folder (C:\Program Files\Unity\Hub\Editor\2019.3.9f1\Editor\Data\MonoBleedingEdge\lib\mono\4.7.1-api\Microsoft.VisualBasic.dll). This reference gets added (and I am able to create a TextFieldParser object without incident), but upon re-launching my Unity project, it gets removed! And I am left with the same error message in the Unity console.
I would appreciate any help to resolve this mystery.
I believe that if you install a package from the NuGet package manager from within Visual Studio, it's recognised by VS, but not Unity. To do that correctly, you need to find the .dll file for the plugin, create a new folder in your Unity assets folder called 'Plugins', and drag in the .dll file. Then, it should recognise the namespace, I believe. @moblab
Answer by moblab · Apr 09, 2021 at 12:54 PM
Hello, I have solved my problem.
First, I changed my API Compatibility Level to .NET Standard 2.0. Then, I copied and pasted the Microsoft.VisualBasic.dll from here () to my Unity project's Assets folder. Finally, I restarted my Unity editor. And no more console errors!
(I also tried @Llama_w_2Ls suggestion of putting the .dll file into the Assets/Plugins folder. That works too, provided that the API Compatibility Level is set to .NET Standard 2.0.)
Strange that Microsoft.VisualBasic.FileIO is not recognized when the API Compatibility Level is set to .NET 4.x. Perhaps it's my Unity installation? Anyway, I hope this answer helps someone in the future.
Whoopsies, I forgot to add the filepath of the Microsoft.VisualBasic.dll that I had used. Here it is: C:\Program Files\Unity\Hub\Editor\2019.3.9f1\Editor\Data\MonoBleedingEdge\lib\mono\2.0-api\Microsoft.VisualBasic.dll.
Your answer
Follow this Question
Related Questions
How Do I use Mono Debugging in Unity 3.0? 1 Answer
vscode - exclude directories from warnings + code style linter 0 Answers
monodevelop vs visual studio? 1 Answer
Accessing other scripts in C# with Visual Studio. 1 Answer
Visual Studio 2015 debugger can no longer attach to Unity after installing RC3 1 Answer