Failed to generate code error when compiling a ASP.NET website on a new computer

半世苍凉 提交于 2021-01-28 07:00:24

问题


I moved my ASP.NET 4.5 website to a new computer by copying the whole folder of the website. When I try to build the website on the new computer in Visual Studio 2012 (same version that I have on the first computer) I get a few warnning and Errors.

Error:

Failed to generate code. Exception of type 'System.Data.Design.InternalException' was thrown.   C:\Users\admin\Desktop\website_sample\App_Code\DataSet.xsd  

There are 21 warnnings, all saying "Unable to update auto-refresh reference" for different dll files.

when I try to run my default.aspx page (worked great on the first computer), I get the following error for the App_Code/DataSet.xsd file:

Failed to generate code. Exception of type 'System.Data.Design.InternalException' was thrown.

And also the source error:

Line 1:  <?xml version="1.0" encoding="utf-8"?>
Line 2:  <xs:schema id="DataSet" targetNamespace="http://tempuri.org/DataSet.xsd" xmlns:mstns="http://tempuri.org/DataSet.xsd" xmlns="http://tempuri.org/DataSet.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:msprop="urn:schemas-microsoft-com:xml-msprop" attributeFormDefault="qualified" elementFormDefault="qualified">
Line 3:    <xs:annotation>

I am using MySQL .NET Connector, but I already intalled it on the new computer to make sure that this doesn't lead to the error.

I need to know how to solve the error and warnning. I am most concerned about the error first because it prevents me from running a few tasks that I need to run today. Thanks in advance.

My assumption is that I used a different version of the .NET MySQL connector, but I'm not dure.


回答1:


If you initially created the datasets by dragging and dropping from the Database or Server Explorer inside of Visual Studio, and the database reference at some point is no longer valid (moved/deleted the database), it will cause this exception.

It's due to the fact that Visual Studio stores the connection string within the XSD. If that connection string is no longer valid, it can't dynamically generate the needed adapters. To fix this, change the ConnectionStringObject attribute on the Connection node inside the XSD file (not at design level, but at the text editor level.) Set it to a valid connection string pointing to the database your dataset corresponds to, and you're good to go.




回答2:


If you don't care about the connection any more, you can instead delete the Connection element, leaving an empty Connections node.

...
<DataSource DefaultConnectionIndex="0" FunctionsComponentName="QueriesTableAdapter" Modifier="AutoLayout, AnsiClass, Class, Public" SchemaSerializationMode="IncludeSchema" xmlns="urn:schemas-microsoft-com:xml-msdatasource">
    <Connections />
    <Tables />
    <Sources />
</DataSource>
...


来源:https://stackoverflow.com/questions/17914840/failed-to-generate-code-error-when-compiling-a-asp-net-website-on-a-new-computer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!