2017-07-09 5 views
0

私はC#を初めて使用しており、SQL ServerでCRUD操作を実行するためのWeb APIを開発中です。Web API構成ファイルのエラーc#

Web設定ファイルでエラーが表示されます。

私はモデルクラスを作成しています

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=\&quot;Web\&quot; /optionInfer+" /> 
</compilers> 

私は次のことを受け付けておりますプロジェクトを実行しようとするとエラーが発生します。

Error

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

を解決する方法。

あなたはパッケージマネージャ使用して、それをインストールすることができます。

enter image description here

をして、次のコマンドを入力します。将来ので、それをあなたのグローバルアセンブリキャッシュにインストールするには、おそらく良いアイデアです

PM> Install-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform 

をアプリケーションで同じ問題が発生することはありません。

gacutil -i "C:\*PATH TO YOUR APP CODE*\bin\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll" 
0

(Nugetで使用される)あなたのPackagesフォルダを持っているDLLのバージョンは、参照フォルダまたはGACは

Version=1.0.3.0 
ではありません