Owin/Katana System.EntryPointNotFoundException 装配在别处
Owin/Katana System.EntryPointNotFoundException Assembly located elsewhere
不知何故我找不到遇到同样问题的人。
我们有一个基于插件的项目,在主文件夹中我们有 Plugin Starter、Bootstrapper 和一些依赖项。
插件位于 "Plugins" 文件夹中,里面还有一些其他文件夹。
我的Startup.cs文件如下:
public class Startup
{
public void Configuration(IAppBuilder appBuilder)
{
appBuilder.Use(async (env, next) =>
{
new object().Info(string.Concat("Http method: ", env.Request.Method, ", path: ", env.Request.Path));
await next();
new object().Info(string.Concat("Response code: ", env.Response.StatusCode));
});
RunWebApiConfiguration(appBuilder);
}
private static void RunWebApiConfiguration(IAppBuilder appBuilder)
{
var httpConfiguration = new HttpConfiguration();
httpConfiguration.Routes.MapHttpRoute(
name: "WebApi"
, routeTemplate: "{controller}/{id}"
, defaults: new { id = RouteParameter.Optional }
);
appBuilder.UseWebApi(httpConfiguration);
}
}
调用如下:
WebApp.Start<Startup>("http://localhost/MyRestApi");
如果我将程序集加载到同一个文件夹,没问题,但如果我将它加载到 "belongs" 的位置,我就无法让 Owin 找到它。
有人曾经 运行 了解过这个或有任何想法吗?我可能会想到 App.config 中的配置行之类的东西,但我认为这不是解决方案。
更新 1:
当我将 Rest Service 程序集复制到主目录时,系统再次运行,但随后它被加载了两次,这是一个大问题。
当我发送休息请求时,我收到以下消息:
{"Message":"An error has occurred.","ExceptionMessage":"Multiple types were found that match the controller named 'ExternalOrder'. This can happen if the route that services this request ('{controller}/{id}') found multiple controllers defined with the same name but differing namespaces, which is not supported.\r\n\r\nThe request for 'ExternalOrder' has found the following matching controllers:\r\nInternalOrderValidationPlugin.Controllers.ExternalOrderController\r\nInternalOrderValidationPlugin.Controllers.ExternalOrderController","ExceptionType":"System.InvalidOperationException","StackTrace":" at System.Web.Http.Dispatcher.DefaultHttpControllerSelector.SelectController(HttpRequestMessage request)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"}
好的,在网上转了一圈,找到了解决办法,就是Dependency Injection.
在这个post“How to use DI container when OwinStartup”中你可以找到很多可能性,但我实现并解决了我的问题的是这个博客post:
https://damienbod.wordpress.com/2013/10/01/self-host-webapi-with-owin-and-unity/
我希望这可以帮助其他人。
不知何故我找不到遇到同样问题的人。
我们有一个基于插件的项目,在主文件夹中我们有 Plugin Starter、Bootstrapper 和一些依赖项。
插件位于 "Plugins" 文件夹中,里面还有一些其他文件夹。
我的Startup.cs文件如下:
public class Startup
{
public void Configuration(IAppBuilder appBuilder)
{
appBuilder.Use(async (env, next) =>
{
new object().Info(string.Concat("Http method: ", env.Request.Method, ", path: ", env.Request.Path));
await next();
new object().Info(string.Concat("Response code: ", env.Response.StatusCode));
});
RunWebApiConfiguration(appBuilder);
}
private static void RunWebApiConfiguration(IAppBuilder appBuilder)
{
var httpConfiguration = new HttpConfiguration();
httpConfiguration.Routes.MapHttpRoute(
name: "WebApi"
, routeTemplate: "{controller}/{id}"
, defaults: new { id = RouteParameter.Optional }
);
appBuilder.UseWebApi(httpConfiguration);
}
}
调用如下:
WebApp.Start<Startup>("http://localhost/MyRestApi");
如果我将程序集加载到同一个文件夹,没问题,但如果我将它加载到 "belongs" 的位置,我就无法让 Owin 找到它。
有人曾经 运行 了解过这个或有任何想法吗?我可能会想到 App.config 中的配置行之类的东西,但我认为这不是解决方案。
更新 1:
当我将 Rest Service 程序集复制到主目录时,系统再次运行,但随后它被加载了两次,这是一个大问题。
当我发送休息请求时,我收到以下消息:
{"Message":"An error has occurred.","ExceptionMessage":"Multiple types were found that match the controller named 'ExternalOrder'. This can happen if the route that services this request ('{controller}/{id}') found multiple controllers defined with the same name but differing namespaces, which is not supported.\r\n\r\nThe request for 'ExternalOrder' has found the following matching controllers:\r\nInternalOrderValidationPlugin.Controllers.ExternalOrderController\r\nInternalOrderValidationPlugin.Controllers.ExternalOrderController","ExceptionType":"System.InvalidOperationException","StackTrace":" at System.Web.Http.Dispatcher.DefaultHttpControllerSelector.SelectController(HttpRequestMessage request)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"}
好的,在网上转了一圈,找到了解决办法,就是Dependency Injection.
在这个post“How to use DI container when OwinStartup”中你可以找到很多可能性,但我实现并解决了我的问题的是这个博客post:
https://damienbod.wordpress.com/2013/10/01/self-host-webapi-with-owin-and-unity/
我希望这可以帮助其他人。