Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Web API by default will ignore controllers that are not public, and LinqPad classes are <em>nested public</em>, we had similar problem in <a href="https://github.com/scriptcs/" rel="nofollow">scriptcs</a></p> <p>You have to add a custom controller resolver, which will bypass that limitation, and allow you to discover controller types from the executing assembly manually.</p> <p>This was actually fixed already (now Web API controllers only need to be <em>Visible</em> not public), but that happened in September and the latest stable version of self host is from August.</p> <p>So, add this:</p> <pre class="lang-cs prettyprint-override"><code>public class ControllerResolver: DefaultHttpControllerTypeResolver { public override ICollection&lt;Type&gt; GetControllerTypes(IAssembliesResolver assembliesResolver) { var types = Assembly.GetExecutingAssembly().GetExportedTypes(); return types.Where(x =&gt; typeof(System.Web.Http.Controllers.IHttpController).IsAssignableFrom(x)).ToList(); } } </code></pre> <p>And then register against your configuration, and you're done:</p> <pre class="lang-cs prettyprint-override"><code>var conf = new HttpSelfHostConfiguration(new Uri(address)); conf.Services.Replace(typeof(IHttpControllerTypeResolver), new ControllerResolver()); </code></pre> <p>Here is a full working example, I just tested against LinqPad. Note that you have to be running LinqPad as admin, otherwise you won't be able to listen at a port.</p> <pre class="lang-cs prettyprint-override"><code>public class TestController: System.Web.Http.ApiController { public string Get() { return "Hello world!"; } } public class ControllerResolver: DefaultHttpControllerTypeResolver { public override ICollection&lt;Type&gt; GetControllerTypes(IAssembliesResolver assembliesResolver) { var types = Assembly.GetExecutingAssembly().GetExportedTypes(); return types.Where(x =&gt; typeof(System.Web.Http.Controllers.IHttpController).IsAssignableFrom(x)).ToList(); } } async Task Main() { var address = "http://localhost:8080"; var conf = new HttpSelfHostConfiguration(new Uri(address)); conf.Services.Replace(typeof(IHttpControllerTypeResolver), new ControllerResolver()); conf.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); var server = new HttpSelfHostServer(conf); await server.OpenAsync(); // keep the query in the 'Running' state Util.KeepRunning(); Util.Cleanup += async delegate { // shut down the server when the query's execution is canceled // (for example, the Cancel button is clicked) await server.CloseAsync(); }; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload