Skip to content

Null Reference in TypeMatchFilter Middleware with non-JADNC Controller #405

Closed
@joshhubers

Description

@joshhubers

Description

I'm getting a

    System.NullReferenceException: Object reference not set to an instance of an object.
    at JsonApiDotNetCore.Middleware.TypeMatchFilter.OnActionExecuting(ActionExecutingContext context) in 
C:\projects\jsonapidotnetcore\src\JsonApiDotNetCore\Middleware\TypeMatchFilter.cs:line 34

Using a standard dotnet Core Controller when returning a Json(result) of type string.
My code is as follows:

namespace Foo.Controllers
{
    [Authorize]
  public class UploadController : Controller
  {
    IPhotoService _photoService;

    public UploadController(IPhotoService photoService)
    {
      _photoService = photoService;
    }

    [Route("api/v1/attachments/upload")]
    [HttpPost]
    public async Task<IActionResult> PostFileAsync(IFormFile file)
    {
      if(file == null || file.Length == 0)
        return Content("No content in file or file not uploaded");

      string path = await _photoService.UploadPhotoAsync(file);
      
      return Json(path);
    }
  }
}

Looking at the code I'm gonna guess it's something to do with the IsJsonApiRequest not filtering replies properly?

Environment

  • JsonApiDotNetCore Version: 2.5.2
  • Other Relevant Package Versions:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions