2017-12-13 41 views
1

내 코드 :는 낸시 자체 호스팅에 간단한 GET 요청을 수행 할 수 없습니다 : RuntimeBinderException 및 ViewNotFoundException

public class MyWebService : IDisposable 
{ 
    private readonly NancyHost _host; 

    public MyWebService(int port = 7017) 
    { 
     var uri = new Uri(string.Format("http://localhost:{0}", port)); 
     _host = new NancyHost(uri); 
     _host.Start(); 
    } 

    public void Dispose() 
    { 
     if (_host != null) 
     { 
      _host.Stop(); 
      _host.Dispose(); 
     } 
    } 
} 

internal class MyWebModule : NancyModule 
{ 
    public MyWebModule() 
    { 
     Get["/"] = _ => "Received GET request"; 
    } 
} 

HTTP 요청 다음 실행 : Insomnia REST client을 사용 GET http://localhost:7017/를 내가지고있어 다음과 같은 비밀 예외 :

Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'Cannot convert type 'Nancy.ErrorHandling.DefaultStatusCodeHandler.DefaultStatusCodeHandlerResult' to 'Nancy.Response'' 
at CallSite.Target(Closure , CallSite , Object) 

출처 : Anonymously Hosted DynamicMethods Assembly

이어서

Nancy.ViewEngines.ViewNotFoundException 
    at Nancy.ViewEngines.DefaultViewFactory.GetRenderedView(String viewName, Object model, ViewLocationContext viewLocationContext) 

예외적 인 추가 정보없이

그런 다음 REST 클라이언트는 404 오류를 표시합니다.

무엇을 잘못 정의 했습니까? 다음 예제를 따라했습니다 : building-a-simple-http-server-with-nancy

답변

1

디버거에서 코드를 실행하는 경우 - 예외가 실제로 처리되지 않았는지 확인하십시오. 코드에서 예외가 발생하고 예외가 처리 된 경우에도 디버거가 중단 될 수 있습니다 (일부 catch 차단). 결국 404 회 답장을 받았지만 충돌이 발생하지 않았기 때문에 이러한 예외는 "정상적인"nancy 흐름의 일부이므로 처리됩니다.

404와 마찬가지로 모듈은 내부적이며 Nancy는 발견하지 않습니다. 대신 공개하기 :

public class MyWebModule : NancyModule 
{ 
    public MyWebModule() 
    { 
     Get["/"] = _ => "Received GET request"; 
    } 
}