5

I've seen the above question asked many times on many sites, but I haven't seen an answer that fixed the problem.

The scenario is this... I am on .NET Framework 4.0, building a C# web application in VisualStudio 2012 Express with the Razor view engine.

I'm trying to use Microsoft.VisualBasic.FileIO.TextFieldParser in my code. From what I've read it is appropriate to do so by adding a project reference to Microsoft.VisualBasic, which I've done, and coding @using Microsoft.VisualBasic; in my view. However when I code...

Microsoft.VisualBasic.FileIO.TextFieldParser parser = new Microsoft.VisualBasic.FileIO.TextFieldParser(new StringReader(xxxxxxxx));

...in the view and rebuild the solution it returns errors: The type or namespace name 'FileIO' does not exist in the namespace 'Microsoft.VisualBasic' (are you missing an assembly reference?)

I know the reference is in the correct project because when I add and remove it I see it come and go from the references folder. I know the code I'm trying to reference exists because I can see it in Object Browser. I've even tried adding the reference using Object Browser instead of through the menus and although it gets added, the results are the same.

The solution it's in is a bit complicated so I tried just creating a test stand alone C# project and I get the same results. I also tried creating a test stand alone Visual Basic project, and sure enough, it works there as advertised. I'm by no means an expert on Visual Studio so I'm guessing that it's just something I'm missing in the configuration, but I'm at a loss to figure it out.

I've spent days on this, so any help anyone could offer would be greatly appreciated.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
user2203007
  • 51
  • 1
  • 2
  • Did you add `Imports Microsoft.VisualBasic` to the code file? – Tim Mar 23 '13 at 19:30
  • Can you post a screenshot of your references for this specific project? e.g. http://i.stack.imgur.com/bePc5.png – eandersson Mar 23 '13 at 19:38
  • First time posting here so I'm not too familiar with how to respond but I'll give it a shot! First to Tim - yes I did. Sorry but I showed @using in my original post which referred to a .cshtml page (which I also tried). Since the page I'm trying to get working is .aspx your comment was actually right on the money. – user2203007 Mar 23 '13 at 20:13
  • To eandersson - as I said I'm not a VS expert and I don't see a way to list references as you have in your attached capture. I've captured an image of my references folder if that helps... just not sure how to post it. – user2203007 Mar 23 '13 at 20:21
  • 1
    Do you see Microsoft.VisualBasic.dll under References folder in your project? – volody Mar 23 '13 at 20:26
  • The reference shows as Microsoft.VisualBasic. Looking at the properties shows that it is Microsoft.VisualBasic.dll. So I would say yes. – user2203007 Mar 23 '13 at 20:36
  • I'm trying to post an image link using the syntax examples shown, but keep getting a message saying that the content is not allowed. Not sure what to do to get the image posted. – user2203007 Mar 23 '13 at 21:05
  • Okay, looks like new users cannot post pictures. Reasonable. So the reference capture is at... freeimagehosting-dot-net/rwtqq. Replace -dot- with a real dot to see the references. – user2203007 Mar 23 '13 at 21:35
  • Can you click on the reference in the solution explorer and see if it gives you a path to where the DLL is? Maybe it's a location of the DLL issue (I rather doubt it, but it never hurts to rule out the simple stuff). – Tim Mar 23 '13 at 21:44
  • Now sure what I'm looking for here, but the path is C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\Microsoft.VisualBasic.dll and there is an actual file there. This is the same file referenced in the Visual Basic project that works. – user2203007 Mar 23 '13 at 21:55

1 Answers1

6
  1. Right-click on your project and select Add Reference...

  2. In the Reference Manager, expand Assemblies and select Framework. Then check the box for Microsoft.VisualBasic and click OK.

reference  picture

Credit goes to: https://stackoverflow.com/a/17146200/2530360

I just had the same problem and your question title was more verbose so I figured it should have the answer inside.

Community
  • 1
  • 1
Evan Morrison
  • 652
  • 6
  • 18