我是C#的新手,我正在开发一个web api来在SQL Server上执行CRUD操作。
我在网络配置文件中收到错误。
我创建了模型类:
public class Test_Automation_Data
{
private String strTest_Automation_Group;
private String strTest_Automation_Application;
private String strTest_Automation_Count;
public string Test_Automation_Group { get => strTest_Automation_Group; set => strTest_Automation_Group = value; }
public string Test_Automation_Application { get => strTest_Automation_Application; set => strTest_Automation_Application = value; }
public string Test_Automation_Count { get => strTest_Automation_Count; set => strTest_Automation_Count = value; }
}
public class TestAutomationDataModel
{
private SqlConnection GetSQLConnection()
{
SqlConnection objConnection = null;
try
{
String ConnectionString = "Data Source=**********;Initial Catalog=***********;User ID=************;Password=*********";
objConnection = new SqlConnection(ConnectionString);
}
catch (Exception ex)
{
throw ex;
}
return objConnection;
}
public List<Test_Automation_Data> GetTestData()
{
List<Test_Automation_Data> Data = new List<Test_Automation_Data>();
try
{
SqlConnection obj_Connection = GetSQLConnection();
obj_Connection.Open();
string SQL_Query = "SELECT * FROM Test_Automation_Inventory";
if (obj_Connection.State == System.Data.ConnectionState.Open)
{
SqlCommand objCommand = new SqlCommand(SQL_Query, obj_Connection);
SqlDataReader DataReader = objCommand.ExecuteReader();
if (DataReader.HasRows)
{
while (DataReader.Read())
{
Test_Automation_Data obj_TestData = new Test_Automation_Data();
obj_TestData.Test_Automation_Group = DataReader.GetValue(0).ToString();
obj_TestData.Test_Automation_Application = DataReader.GetValue(1).ToString();
obj_TestData.Test_Automation_Count = DataReader.GetValue(2).ToString();
Data.Add(obj_TestData);
}
DataReader.Close();
obj_Connection.Close();
}
}
}
catch (Exception ex)
{
throw ex;
}
return Data;
}
public int DeleteTest(String Test_Group, String Test_Application)
{
int RowCount = 0;
try
{
SqlConnection obj_Connection = GetSQLConnection();
obj_Connection.Open();
string SQL_Query = "DELETE FROM Test_Automation_Inventory WHERE Test_Inventory_Group = '" + Test_Group + "' and Test_Inventory_Application = '" + Test_Application + "'";
if (obj_Connection.State == System.Data.ConnectionState.Open)
{
SqlCommand objCommand = new SqlCommand(SQL_Query, obj_Connection);
RowCount = int.Parse(objCommand.ExecuteNonQuery().ToString());
}
obj_Connection.Close();
}
catch (Exception ex)
{
throw ex;
}
return RowCount;
}
public int CreateTest(String Test_Group, String Test_Application)
{
int RowCount = 0;
try
{
SqlConnection obj_Connection = GetSQLConnection();
obj_Connection.Open();
if (obj_Connection.State == System.Data.ConnectionState.Open)
{
SqlCommand objCommand = new SqlCommand();
objCommand.CommandType = System.Data.CommandType.Text;
objCommand.CommandText = "INSERT INTO Test_Automation_Inventory Values (@Test_Group,@Test_Application,@Test_Count)";
objCommand.Connection = obj_Connection;
objCommand.Parameters.AddWithValue("@Test_Group", Test_Group);
objCommand.Parameters.AddWithValue("@Test_Application", Test_Application);
objCommand.Parameters.AddWithValue("@Test_Count", 0);
RowCount = objCommand.ExecuteNonQuery();
}
obj_Connection.Close();
}
catch (Exception ex)
{
throw ex;
}
return RowCount;
}
}
这是我的控制器类:
public class TestController : ApiController
{
// GET: api/TestAutomationInventory
public List<Test_Automation_Data> Get()
{
TestAutomationDataModel obj = new TestAutomationDataModel();
return obj.GetTestData();
}
}
这是我的Web配置文件:
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" />
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+" />
</compilers>
我在尝试运行项目时收到以下错误:
Line 39: <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" />
如何解决问题
答案 0 :(得分:0)
您可能正在使用一个依赖于此程序集的程序包,假定您已经安装了它。
您可以使用包管理器安装它:
然后输入以下命令:
PM> Install-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform
安装全局程序集缓存可能是个好主意,因此未来的应用程序不会遇到同样的问题。
gacutil -i "C:\*PATH TO YOUR APP CODE*\bin\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll"
答案 1 :(得分:0)
您的Packages文件夹(由Nuget使用),参考文件夹或GAC中的DLL版本不是
Version=1.0.3.0