0

I have an asp.net website I have been working on in Visual Studio 2019, using .Net Framework 4.5.1. The code builds just fine but won't publish, giving me this error:

Error BC30002: Type 'DataTable' is not defined.

The publish is to a folder on my pc, and is in Release mode. I have 'Delete existing files' set to False, 'Precompile during publishing' set to true, and in the Precompile options I just have 'Do not merge' selected.

DataTable is defined in System.Data, and I am referencing version 4.0.0.0. The code throwing the error is in a class in the App_Code folder, which I know can cause issues - but i've published this code before without an error so I don't see why it wouldn't work.

I tried deleting the .vs folder and restarting Visual Studio, as well as starting VS as an administrator, but I still get the error. Does anyone have any suggestions how I can get the website to publish?

1 Answers1

0

After a bit of trial and error I discovered that I needed to add

Imports System.Data

to each of the classes that was using DataTable. Strangely intellisense actually says this is unneccessary, but obviously it isn't if you want to publish your code.

Thanks to Timothy G. for your suggestion. I read that after I stumbled on my solution, but if i'd seen it earlier it could've saved me time.

  • For web sites application I have now dumped the use of App_Code, and simple create a folder called MyCode. The reason why is that while everything else is compiled at build time, App_Code is still compiled by IIS, and we don't want that. So, I just dumped app_code, and use a folder called my code. For any class, and code in that folder, you do have to right click on the file and choose "compile" as the build action, but other then that, nothing else is required. This comes down to is this a web site, or a web site application. the OTHER big issue is Roslyn not always available for IIS. – Albert D. Kallal Feb 21 '23 at 20:23
  • If you think that solves your issue, you could mark it as the answer. – Jiale Xue - MSFT Feb 27 '23 at 08:28