43

I am on .NET Framework 4.0, building a C# web application in VisualStudio 2012. I have Microsoft.VisualBasic added as a reference to the project. I am having trouble with the following line of code:

using Microsoft.VisualBasic.FileIO;

Building the solution returns the error: The type or namespace name 'FileIO' does not exist in the namespace 'Microsoft.VisualBasic' (are you missing an assembly reference?)

I have removed and re-added the reference to the assembly Microsoft.VisualBasic, but still get the error. Microsoft.VisualBasic is in the GAC, as well as Microsoft.VisualBasic.Compatibility, Microsoft.VisualBasic.Compatibility, Microsoft.VisualBasic.PowerPacks.Vs, and Microsoft.VisualBasic.Vsa.

Please let me know how to get VS2012 to recognize the FileIO namespace.

Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108
Rob Cole
  • 721
  • 1
  • 6
  • 16
  • 1
    Are you sure you added it to the correct project? I just created a test web app and couldn't reproduce the error. – nick_w Oct 10 '12 at 23:53
  • @KenWhite, it is a valid namespace: http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.fileio.aspx – Gromer Oct 10 '12 at 23:56
  • @Gromer: I found it. That's why I deleted my comment. :-) Thanks, though. I always like learning something I didn't know. (I still don't understand the need for it in a C# app, however; I never have, which is probably why I didn't know it was there.) – Ken White Oct 11 '12 at 00:07
  • 4
    The Add Reference dialog was redesigned in VS2012. Make sure you don't just select the assembly, you have to make sure to click the checkbox in front of it. – Hans Passant Oct 11 '12 at 00:30
  • Yes, I had added the reference to another project. Thanks for your help. – Rob Cole Oct 11 '12 at 02:45

3 Answers3

74
  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.

Chris Schiffhauer
  • 17,102
  • 15
  • 79
  • 88
1

I had similar issue, fixed by change TargetFramework (in .csproj) from netstandard2.0 to netcoreapp3.0.

0

Application references are not available to uncompiled files in your application (aspx, ashx). There are two solutions to this issue as follows:

1) Move your code to a compiled part of the application (cs/vb file)

or

2) Add the reference to the web config

My reference was in an ashx file. I simply copied the code from the ashx file to the clipboard, deleted the file from the project, added a new Generic Handler (right click in Visual Studio > Add > Generic Handler), entered the same name as before, and pasted the code from the clipboard into the cs file editor that Visual Studio opened. I now have a cs file that will compile with the project and use the project reference. The file name is the same, so there is no need to update anything else -- just rebuild and deploy.

llessurt
  • 555
  • 3
  • 14