- BusinessEntity (Layer)
DTO
BeMonitorRequest.cs - ...другие классы...
[*]Интернет (уровень)
- Контроллеры
MonitorController.cs - ...другие контроллеры...
У меня возникла проблема с созданием установочных файлов с помощью параметра «Опубликовать» в VS2015. Я генерирую файлы в определенной папке, а затем копирую и вставляю их в производственную среду.
Когда я запускаю проект из VS2015, у меня не возникает никаких проблем, но после вставки созданные файлы развертывания в рабочую среду, я получаю ошибку 500.
Эта ошибка возникает при попытке получить конечную точку с именем «api/monitor/getMonitorCasesByFilter». В контроллере веб-уровня он определяется следующим образом:
Код: Выделить всё
[RoutePrefix("api/monitor")]
public class MonitorController : BaseController
{
private readonly ISelector iSelector;
private readonly IMonitorCase iMonitorCase;
private readonly ITimeConverter iTimeConverter;
public MonitorController(IMonitorCase iMonitorCase, ISelector iSelector, ITimeConverter iTimeConverter)
{
this.iMonitorCase = iMonitorCase;
this.iSelector = iSelector;
this.iTimeConverter = iTimeConverter;
}
[HttpGet]
[Route("getMonitorCasesByFilter")]
public IHttpActionResult CasesByFilter([FromUri] BeMonitorRequest request)
{
request.ProjectId = this.GetProject();
request.UserName = this.GetUserName();
List CasesByFilter = this.iMonitorCase.GetMonitorCasesMainByFilter(request);
return Ok(CasesByFilter);
}
}
Код: Выделить всё
using MyProject.BusinessEntity.DTO;
namespace MyProject.BusinessEntity.DTO
{
public class BeMonitorRequest
{
public int ProjectId { get; set; }
public string ProjectDB { get; set; }
public string From { get; set; }
public string To { get; set; }
public string RadNumber { get; set; }
public string UserName { get; set; }
public string FullName { get; set; }
public int ProcessId { get; set; }
public string ProcessName { get; set; }
public int TaskId { get; set; }
public string NotificationType { get; set; }
public int StepTypeId { get; set; }
public int WiClosed { get; set; }
public int WinClosed { get; set; }
}
}
Код: Выделить всё
using MyProject.Bl;
using MyProject.Bl.Interfaces;
using MyProject.Dal;
using MyProject.Dal.Interfaces;
using MyProject.Utils;
using MyProject.Utils.Interfaces;
using MyProject.Utils.Proxies;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using Unity;
namespace MyProject.Web.Dependency
{
internal static class DependencyConfig
{
internal static IUnityContainer Configure()
{
IUnityContainer container = new UnityContainer();
var host = ConfigurationManager.AppSettings["Host"];
var connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
container.RegisterType();
container.RegisterInstance(new ConfigProxyService(host));
container.RegisterType();
container.RegisterInstance(new DalConnection(connectionString, true));
//...
container.RegisterType();
container.RegisterType();
//...
return container;
}
}
}
Код: Выделить всё
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http.Dependencies;
using Unity;
namespace MyProject.Web.Dependency
{
public class WebApiUnityResolver : IDependencyResolver
{
protected IUnityContainer container;
public WebApiUnityResolver(IUnityContainer container)
{
if (container == null)
{
throw new NotImplementedException("container");
}
this.container = container;
}
public IDependencyScope BeginScope()
{
var child = container.CreateChildContainer();
return new WebApiUnityResolver(child);
}
public void Dispose()
{
container.Dispose();
}
public object GetService(Type serviceType)
{
try
{
return container.Resolve(serviceType);
}
catch (ResolutionFailedException e)
{
return null;
}
}
public IEnumerable GetServices(Type serviceType)
{
try
{
return container.ResolveAll(serviceType);
}
catch (ResolutionFailedException)
{
return new List();
}
}
}
}
На локальном хосте (работает)

В рабочей среде (не работает)

Код: Выделить всё
{
"message" : "An error has occurred.",
"exceptionMessage": "An error occurred when trying to create a controller of type 'MonitorController'. Make sure that the controller has a parameterless public constructor.",
"exceptionType" : "System.InvalidOperationException",
"stackTrace" : "
at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)"
at System.Web.Http.Dispatcher.HttpControllerDispatcher.d__15.MoveNext()",
"innerException": {
"message" : "An error has occurred.",
"exceptionMessage": "Type 'MyProject.Web.Controllers.MonitorController' does not have a default constructor",
"exceptionType" : "System.ArgumentException",
"stackTrace" : "
at System.Linq.Expressions.Expression.New(Type type)
at System.Web.Http.Internal.TypeActivator.Create[TBase](Type instanceType)
at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.GetInstanceOrActivator(HttpRequestMessage request, Type controllerType, Func`1& activator)
at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)"
}
}
- Операционная система моего компьютера:
Windows 10 Enterprise
Версия 22H2
Сборка ОС 19045.4412 - Операционная система сервера:
Windows Server 2022 Datacenter
Версия 21H2Сборка ОС 20348.1906 - Серверный IIS:
Версия 10.0.20348.1
VS2015
Версия 14.0.25431.01, обновление 3 - Целевая структура проекта
.Net Framework 4.5.2
- Очистка и восстановление проекта за проектом
- Очистка и восстановление всего решения
Подробнее здесь: https://stackoverflow.com/questions/786 ... net-framew