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.

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.