Class 从WebAPI调用引用的dll可以在本地工作,但不能在服务器上工作

Class 从WebAPI调用引用的dll可以在本地工作,但不能在服务器上工作,class,reference,asp.net-web-api2,Class,Reference,Asp.net Web Api2,我有一个启用Cors的WebAPI 我的webAPI引用了我在其中进行大量处理的类库 WebAPI和类库之间的调用以及类库内部的一些调用 正在抛出此错误 {"Message":"An error has occurred.","ExceptionMessage":"Object reference not set to an instance of an object.", "ExceptionType":"System.NullReferenceException","StackTrace":

我有一个启用Cors的WebAPI

我的webAPI引用了我在其中进行大量处理的类库

WebAPI和类库之间的调用以及类库内部的一些调用

正在抛出此错误

{"Message":"An error has occurred.","ExceptionMessage":"Object reference not set to an instance of an object.",
"ExceptionType":"System.NullReferenceException","StackTrace":"   
at RCIS.MappingServices.WebAPI.Utilities.SQL.SQLInsertObjects(Int32 TypeMapId, Int32 GrowerId, Int32 CropYear, String NAME, String SHAPE, String CREATED_BY, String CREATED_DATETIME, String MODIFIED_BY, String MODIFIED_DATETIME, String IsDELETED)\r\n   
at RCIS.MappingServices.WebAPI.Controllers.PostObjectsController.GET(String TypeMapId, String GrowerId, String CropYear, String NAME, String SHAPE)\r\n   
at lambda_method(Closure , Object , Object[] )\r\n   
at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)\r\n   
at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)\r\n   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, 
IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   
at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   
at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   
at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"}
{“Message”:“发生了错误”,“ExceptionMessage”:“对象引用未设置为对象的实例。”,
“ExceptionType”:“System.NullReferenceException”,“StackTrace”:
位于RCIS.MappingServices.WebAPI.Utilities.SQL.SQLInsertObjects(Int32 TypeMapId、Int32 GrowerId、Int32 CropYear、字符串名称、字符串形状、字符串创建人、字符串创建人、字符串修改人、字符串修改日期时间、字符串删除)\r\n
位于RCIS.MappingServices.WebAPI.Controllers.PostObjectsController.GET(字符串类型MAPID、字符串GrowerId、字符串CropYear、字符串名称、字符串形状)\r\n
在lambda_方法(闭包、对象、对象[])处\r\n
在System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.c\u DisplayClass10.b\u 9(对象实例,对象[]方法参数)\r\n
在System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(对象实例,对象[]参数)\r\n在System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext,
IDictionary`2个参数,CancellationToken CancellationToken)\r\n---来自引发异常的上一个位置的堆栈结束跟踪---\r\n
在System.Runtime.CompilerServices.TaskWaiter.ThrowForNonSuccess(任务任务)时\r\n
在System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务任务)中\r\n
位于System.Web.Http.Controllers.ApiControllerActionInvoker.d\u 0.MoveNext()\r\n---引发异常的上一个位置的堆栈结束跟踪---\r\n
在System.Runtime.CompilerServices.TaskWaiter.ThrowForNonSuccess(任务任务)时\r\n
在System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务任务)中\r\n
在System.Web.Http.Controllers.ActionFilterResult.d\u 2.MoveNext()\r\n--引发异常的上一个位置的堆栈结束跟踪---\r\n
在System.Runtime.CompilerServices.TaskWaiter.ThrowForNonSuccess(任务任务)时\r\n
在System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务任务)中\r\n
在System.Web.Http.Dispatcher.HttpControllerDispatcher.d_u1.MoveNext()“}
这似乎只有在从服务器调用类库时才会发生(即,我在Chrome中输入一个URL调用WebAPI方法并返回此错误)

如果我在WebAPI和类库中使用所有基元类型,我会收到一条成功消息

如果你有任何问题,请告诉我。
在此方面的任何帮助都将不胜感激,我已经尝试解决这个问题两天了

确保只传递字符串值。

创建一个ErrorHelper:

public class ErrorHelper : IHttpActionResult
{
    private HttpRequestMessage Request { get; }
    private HttpStatusCode statusCode;
    private string message;

    public ErrorHelper(HttpRequestMessage request, HttpStatusCode statusCode, string message)
    {
        this.Request = request;
        this.statusCode = statusCode;
        this.message = message;
    }

    public Task<HttpResponseMessage> ExecuteAsync(CancellationToken cancellationToken)
    {
        return Task.FromResult(Request.CreateErrorResponse(statusCode, message));
    }
}

这将为您提供异常详细信息。您可能没有在服务器上安装组件,例如数据库驱动程序或类似的组件。

您找到解决此问题的方法了吗?我也有类似的问题。
public IHttpActionResult Get(int id)
{
    try
    {
        var person = _repository.GetPersonId(id);
        if (person == null)
        {
            return NotFound();
        }
        return Ok(person);
    }
    catch (Exception ex)
    {
        return new ErrorHelper(Request, HttpStatusCode.InternalServerError, ex.ToString());
    }
}