Search code examples
asp.netvisual-studio-2019.net-4.5publish

Error BC30002 being thrown on publish but not build


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?


Solution

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