Typed dataset not recognized when moved to another

2020-07-24 05:04发布

问题:

I moved a typed dataset from one project to an ASP Web Application project. I put the typed dataset into one of the existing directories as it was in the App_Code directory of the previous site but don't see the option to create that asp.net folder in this project.

Now, when I try to instantiate the typed dataset, the compiler says 'The type or namespace name '' could not be found (are you missing a using directive or an assembly reference?)'.

Thoughts?

回答1:

You may need to re-gen the DataSet. When you move the .xsd, you've only moved the xml layout of the DataSet.

Delete any generated code file, open the xsd, move something, and then save it. The save operation calls the generator. Or you can right-click on the .xsd file and call the generator directly.



回答2:

Make sure the compiler knows it's a dataset and not just an Xml file. Select the DataSet.xsd in Solution Explorer, then in the Project window ensure that "Custom Tool" is set to MSDataSetGenerator.

After that, instead of guessing, open up the dll file in Reflector and look for your DataSet class. Make sure it's in the namespace you think it is.



回答3:

I moved my web site to a Web Application Project and experienced the same issues. I took the approach mentioned in the first answer and was able to get the project to compile eventually. I would like to add a little more detail to the first answer.

To be explicit: I first deleted all of the files associated with the xsd file except for the xsd file itself (the xss, xsc, cs, ...). I then right-clicked on the xsd file, selecting "View Designer" and then "View Code", and then "Run Custom Tool". All of the files were re-gened and the references compiled.



回答4:

In Visual Studio 2015, what I did was

  1. Before I right-click the added dataset to Include in project, I deleted the .xss and .xsc files and left the rest.

  2. I then right-click the .xsd file and included in the project and problem solved.

Hope I solved someone's problem.



回答5:

You have included the "using namespace" statement in the new code?