2017-06-16 67 views
0

我使用Visual Studio 2017年15.2(26430.12)
我創建的WebAPI 2空項目
然後添加一個控制器,如下所示:空的WebAPI 2項目拋出的StackOverflow異常在VS2017 15.2(26430.12)

public class DefaultController : ApiController 
{ 
    // GET: api/Default 
    public IEnumerable<string> Get() 
    { 
     return new string[] { "value1", "value2" }; 
    } 

    // GET: api/Default/5 
    public string Get(int id) 
    { 
     return "value"; 
    } 

    // POST: api/Default 
    public void Post([FromBody]string value) 
    { 
    } 

    // PUT: api/Default/5 
    public void Put(int id, [FromBody]string value) 
    { 
    } 

    // DELETE: api/Default/5 
    public void Delete(int id) 
    { 
    } 
} 

沒有任何其他更改,我啓動該項目,當我導航到http://localhost:51989/api/Default/發生異常時!沒有任何細節
它有什麼問題?從Windows事件查看器 WebApi 2 Empty project stackoverflow

詳情:

Faulting application name: iisexpress.exe, version: 10.0.14358.1000, time stamp: 0x574fc56b 
Faulting module name: iiscore.dll, version: 10.0.14358.1000, time stamp: 0x574fc56c 
Exception code: 0xc00000fd 
Fault offset: 0x00018992 
Faulting process id: 0x794 
Faulting application start time: 0x01d2e6c78b37e814 
Faulting application path: C:\Program Files (x86)\IIS Express\iisexpress.exe 
Faulting module path: C:\Program Files (x86)\IIS Express\iiscore.dll 
Report Id: 088d1dfb-6a5d-4fcb-bfab-e85185d1c6a5 
Faulting package full name: 
Faulting package-relative application ID: 

編輯:
項目的Web.config

<?xml version="1.0" encoding="utf-8"?> 
<!-- 
    For more information on how to configure your ASP.NET application, please visit 
    https://go.microsoft.com/fwlink/?LinkId=301879 
    --> 
<configuration> 
    <appSettings></appSettings> 
    <system.web> 
    <compilation debug="true" targetFramework="4.5"/> 
    <httpRuntime targetFramework="4.5"/> 
    </system.web> 
    <system.webServer> 
    <handlers> 
     <remove name="ExtensionlessUrlHandler-Integrated-4.0"/> 
     <remove name="OPTIONSVerbHandler"/> 
     <remove name="TRACEVerbHandler"/> 
     <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" 
     preCondition="integratedMode,runtimeVersionv4.0"/> 
    </handlers> 
    </system.webServer> 
    <runtime> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35"/> 
     <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/> 
     <bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0"/> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35"/> 
     <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/> 
     </dependentAssembly> 
    </assemblyBinding> 
    </runtime> 
    <system.codedom> 
    <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> 
    </system.codedom> 
</configuration> 
+0

我看不出代碼在問題中可能會給你這個例外。這個項目中還有其他的東西。 – Amy

+0

其實我什麼都沒做,只是新建項目>空WebApi 2 - >添加DefaultController>開始 –

+1

向我們展示你的web.Config – Amy

回答

2

對於它的價值,使用相同的VS版本爲你,在Windows 10上,我能夠創建測試應用並播放它,而不會遇到此問題。我也使用相同版本的IIS Express。我認爲腳手架代碼沒有什麼問題。如果存在,你能否嘗試刪除解決方案根目錄中的(隱藏).vs目錄,看看是否可以解決問題?由於解決方案的.vs目錄與您自己的Documents \ IISExpress目錄之間的applicationhost.config不同,我已經看到過古怪的情況。還有一個類似的線程提供了一個類似的問題,這裏提供了額外的調試建議:IIS Express crashes when starting a site from visual studio

+0

謝謝,我刪除了'.vs'目錄,我的問題解決了。 –

+0

歡迎您!對於它的價值,我可以說很少,爲什麼這會起作用,或者是什麼條件導致這些事情進入這樣一個奇怪的狀態,只是我知道它經常與許多IIS表達錯誤一起工作。通常情況下,這對我來說成了問題,當時開發人員神祕地將.vs文件夾檢入源代碼控制。 – Trioj