4

I am using visual studio 2012 and .Net framework 4.5. I have included 'Microsoft.VisualBasic' in my project reference.

I am getting the following error while executing the project.

Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0234: The type or namespace name 'FileIO' does not exist in the namespace 'Microsoft.VisualBasic' (are you missing an assembly reference?)

Source Error:

      int lineNumber = 0;
      int flag = 1;
     using (Microsoft.VisualBasic.FileIO.TextFieldParser parser = new Microsoft.VisualBasic.FileIO.TextFieldParser(file))
     {
        parser.CommentTokens = new string[] { "#" };

I had tried adding the reference again and again but it doesn't seems to be working.

I even tried the answers from following question in Stack Overflow but nothing helped microsoft.visualbasic.fileio does not exist

here is my reference and properties of Microsoft visual basic

Please help me

Community
  • 1
  • 1
Myth
  • 446
  • 7
  • 18
  • Possible dup of: http://stackoverflow.com/questions/15419475/the-type-or-namespace-textfieldparser-could-not-be-found – dotNET Sep 24 '14 at 04:29
  • Did you add the reference to Microsoft.VisualBasic.dll? From which framework folder have you given the reference? Since you are using Framework 4.5 the folder is usually C:\Windows\Microsoft.NET\Framework64\v4.0.30319 – Sam Sep 24 '14 at 04:30
  • Can you post a screenshot of your Solution Explorer with the References node expanded? Also, select the VB reference and show the Properties window too. – jmcilhinney Sep 24 '14 at 04:30
  • @sam the path of reference is C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\Microsoft.VisualBasic.dll – Myth Sep 24 '14 at 04:32
  • Make sure the reference you added is from the *same* .NET Framework version as the one specified in your project Properties. Also, this should be a .NET reference, not a COM or File reference. – SF Lee Sep 24 '14 at 04:36
  • I have added the reference tab and Properties in my question please see that – Myth Sep 24 '14 at 04:38
  • @dotNET I had gone through that question too and i made sure that i had checked the box for Microsoft.VisualBasic but that too didn't worked – Myth Sep 24 '14 at 04:40
  • @SFLee It is a .net reference and not a COM or file reference – Myth Sep 24 '14 at 04:43
  • That seems to be correct. Did you try clean build or closing the Visual Studio and start opening again? That seems silly but sometimes that works :) – Sam Sep 24 '14 at 04:44
  • I am facing this problem yesterday onward, I have restarted visual studio and took a clean build many times but nothing helped – Myth Sep 24 '14 at 04:49
  • I'm out of ideas... Maybe you can compress the whole solution (minus the sensitive code of course) into a zip file and post it somewhere so that we can look at it? – SF Lee Sep 24 '14 at 04:53
  • Ok, try this. Create a fresh project and add this reference and then just initialize an object with Microsoft.VisualBasic.FileIO.TextFieldParser class. Then try to compile. See what happens. – Sam Sep 24 '14 at 04:54
  • If the reference is wrong the compiler will not warn about FileIO it will just say Microsoft.VisualBasic cannot be found. I'm sure you are referencing an older version of this DLL. Try using Reflector and see whether Microsoft.VisualBasic.dll that you are using has FileIO class – Sam Sep 24 '14 at 05:00
  • Let us know how you go with this – Sam Sep 24 '14 at 05:42
  • @sam I got it solved now still don't know why it was not working when adding reference to the C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\Microsoft.VisualBasic.dll – Myth Sep 24 '14 at 08:14

3 Answers3

3

Similar to Mark Richman, it still did not give me access to the FileIO. What I did, is click on Tools->NuGet PackageManager->Manage NuGet Packages For Solution. Searched for Microsoft.VisualBasic. Clicked Install, and it gave some terms and conditions that I accepted. After Installing this way, I was able to get the FileIO option.

Miles
  • 113
  • 7
2

I got this problem solved now

I have copied Microsoft.VisualBasic.dll file to the bin folder of my project and now it seems to be working fine. (OR) You can change the Properties of the reference as follows

right click the Microsoft.VisualBasic reference in solution explorer and change **Copy Local** property value as '**True**'

-> Right click the Microsoft.VisualBasic reference in solution explorer and change Copy Local property value as 'True' . This will do the trick

Myth
  • 446
  • 7
  • 18
1

I ran into this error while writing unit tests and thought I had added the reference to my project as described above (and in this answer). However, I was adding the reference to my unit test project rather than my main project. Just in case anyone is as foolish as I was: add your reference to the correct project, clean your project/solution, then profit.

Community
  • 1
  • 1
tessafyi
  • 2,273
  • 2
  • 19
  • 28