Forum Discussion

Pharos_Systems_'s avatar
Pharos_Systems_
Occasional Contributor
12 years ago

Error while trying to send a multipart request

Hello All,

I have been trying to send a multipart request using soapUI, but see the following error:
System.NullReferenceException: Object reference not set to an instance of an object. at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Http.ApiController.<InvokeActionWithExceptionFilters>d__1.MoveNext().

I chose MediaType: multipart/form-data and added an attachment.
Here is the raw request:
POST http://hostname/ImportService/Imports/Upload/Users HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: multipart/form-data; boundary="----=_Part_35_1122409331.1382987797294"
MIME-Version: 1.0
Content-Length: 47819
Host: hostname
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)


------=_Part_35_1122409331.1382987797294
Content-Type: multipart/form-data
Content-Transfer-Encoding: 8bit

Content-Disposition: form-data; name="Request"

{
"CustomerGuid":"00000000-0000-0000-0000-000000000",
"ColumnMappings":[
{"FileColumnName":"Name","FileColumnNumber":0,"DtoPropertyName":"Name"},
{"FileColumnName":"Domain","FileColumnNumber":1,"DtoPropertyName":"Domain"},
{"FileColumnName":"FullName","FileColumnNumber":2,"DtoPropertyName":"FullName"},
{"FileColumnName":"Email","FileColumnNumber":3,"DtoPropertyName":"Email"},
{"FileColumnName":"Position","FileColumnNumber":4,"DtoPropertyName":"Position"},
{"FileColumnName":"PhoneNumber","FileColumnNumber":5,"DtoPropertyName":"PhoneNumber"},
{"FileColumnName":"Manager","FileColumnNumber":6,"DtoPropertyName":"Manager"},
{"FileColumnName":"Department","FileColumnNumber":7,"DtoPropertyName":"Department"},
{"FileColumnName":"Region","FileColumnNumber":8,"DtoPropertyName":"Region"},
{"FileColumnName":"Site","FileColumnNumber":9,"DtoPropertyName":"Site"},
{"FileColumnName":"Building","FileColumnNumber":10,"DtoPropertyName":"Building"},
{"FileColumnName":"Floor","FileColumnNumber":11,"DtoPropertyName":"Floor"},
{"FileColumnName":"Area","FileColumnNumber":12,"DtoPropertyName":"Area"}]
}
------=_Part_35_1122409331.1382987797294
Content-Type: application/octet-stream; name="PNZ&PUS 378 USERS.csv"
Content-Transfer-Encoding: binary
Content-Disposition: form-data; name="PNZ&PUS 378 USERS.csv"; filename="PNZ&PUS 378 USERS.csv"

Name,Domain,FullName,Email,Position,PhoneNumber,Manager,Department,Country,State,City,Building,Floor
"Pharosmaster","pnz","PharosMaster","Pharosmaster@pharos.co.nz","","","","Users - Utility","","","","",""
"krbtgt","pnz","krbtgt","","","","","Users - Utility","","","","",""
"Guest","pnz","Guest","","","","","Users - Utility","","","","",""

Thanks in advance

17 Replies

  • Pharos_Systems_'s avatar
    Pharos_Systems_
    Occasional Contributor
    Thanks All for your replies.

    We are using MVC 4 and here is the comparion of the whole request:
    If I use the following request in fiddler(this was generated in SOAPUI) I see the same error in both tools("Object reference not set to an instance of an object.",)

    POST http://hostname/ImportService/Imports/Upload/Users HTTP/1.1
    Accept-Encoding: gzip,deflate
    Content-Type: multipart/form-data; boundary="----=_Part_41_472186237.1383242955647"
    MIME-Version: 1.0
    Content-Length: 1302
    Host: hostname
    Connection: Keep-Alive
    User-Agent: Apache-HttpClient/4.1.1 (java 1.5)

    ------=_Part_41_472186237.1383242955647
    Content-Type: multipart/form-data
    Content-Transfer-Encoding: 8bit

    Content-Disposition: form-data; name="Request"

    {"CustomerGuid":"00000000-0000-0000-0000-000000000000","ColumnMappings":
    [
    {"FileColumnName":"Name","FileColumnNumber":0,"DtoPropertyName":"Name"},
    {"FileColumnName":"Domain","FileColumnNumber":1,"DtoPropertyName":"Domain"},
    {"FileColumnName":"FullName","FileColumnNumber":2,"DtoPropertyName":"FullName"},
    {"FileColumnName":"Email","FileColumnNumber":3,"DtoPropertyName":"Email"},
    {"FileColumnName":"Position","FileColumnNumber":4,"DtoPropertyName":"Position"},
    {"FileColumnName":"PhoneNumber","FileColumnNumber":5,"DtoPropertyName":"PhoneNumber"},
    {"FileColumnName":"Manager","FileColumnNumber":6,"DtoPropertyName":"Manager"},
    {"FileColumnName":"Department","FileColumnNumber":7,"DtoPropertyName":"Department"},
    {"FileColumnName":"Region","FileColumnNumber":8,"DtoPropertyName":"Region"},
    {"FileColumnName":"Site","FileColumnNumber":9,"DtoPropertyName":"Site"},
    {"FileColumnName":"Building","FileColumnNumber":10,"DtoPropertyName":"Building"},
    {"FileColumnName":"Floor","FileColumnNumber":11,"DtoPropertyName":"Floor"},
    {"FileColumnName":"Area","FileColumnNumber":12,"DtoPropertyName":"Area"}
    ]}
    ------=_Part_41_472186237.1383242955647
    Content-Type: application/octet-stream; name=test.csv
    Content-Transfer-Encoding: binary
    Content-Disposition: form-data; name="test.csv"; filename="test.csv"

    Name,Domain,FullName,Email,Position,PhoneNumber,Manager,Department,Region,Site,Building,Floor,Area
    Pharosmaster,pnz,PharosMaster,Pharosmaster@pharos.co.nz,,,,Users - Utility,,,,,
    Bastiaan,pnz,Bastiaan Bosman,bbosman@pharos.co.nz,IT Manager,532-0735,Paul Reddy,IT,New Zealand,,,,
    ------=_Part_41_472186237.1383242955647--



    but I can get the request to work in Fiddler by doing this :
    Accept-Encoding: gzip,deflate
    Content-Type: multipart/form-data; boundary=abcd
    MIME-Version: 1.0
    Content-Length: 1569
    Host: hostname
    Connection: Keep-Alive
    User-Agent: Apache-HttpClient/4.1.1 (java 1.5)

    --abcd
    Content-Disposition: form-data; name="Request"

    {"CustomerGuid":"5480f181-a008-e211-bb60-000c293df992","ColumnMappings":[{"FileColumnName":"Name","FileColumnNumber":0,"DtoPropertyName":"Name"},{"FileColumnName":"Domain","FileColumnNumber":1,"DtoPropertyName":"Domain"},{"FileColumnName":"FullName","FileColumnNumber":2,"DtoPropertyName":"FullName"},{"FileColumnName":"Email","FileColumnNumber":3,"DtoPropertyName":"Email"},{"FileColumnName":"Position","FileColumnNumber":4,"DtoPropertyName":"Position"},{"FileColumnName":"PhoneNumber","FileColumnNumber":5,"DtoPropertyName":"PhoneNumber"},{"FileColumnName":"Manager","FileColumnNumber":6,"DtoPropertyName":"Manager"},{"FileColumnName":"Department","FileColumnNumber":7,"DtoPropertyName":"Department"},{"FileColumnName":"Region","FileColumnNumber":8,"DtoPropertyName":"Region"},{"FileColumnName":"Site","FileColumnNumber":9,"DtoPropertyName":"Site"},{"FileColumnName":"Building","FileColumnNumber":10,"DtoPropertyName":"Building"},{"FileColumnName":"Floor","FileColumnNumber":11,"DtoPropertyName":"Floor"},{"FileColumnName":"Area","FileColumnNumber":12,"DtoPropertyName":"Area"}]}
    --abcd
    Content-Disposition: form-data; name="Content"; filename="PNZ&PUS 378 USERS.csv"
    Content-Type: application/vnd.ms-excel

    Name,Domain,FullName,Email,Position,PhoneNumber,Manager,Department,Region,Site,Building,Floor,Area
    Pharosmaster,pnz,PharosMaster,Pharosmaster@pharos.nz,,,,Users - Utility,,,,,
    --abcd--

    I am not sure if this is happening, but I think that soapUI is stripping off the last line in the request.
    Please let me know if you need more information to debug the problem.

    Thanks again.
  • To the best of my knowledge, the SoapUI-generated request you posted is a correct multipart request – nothing seems to be stripped from it. I also believe that this part of SoapUI is well proven, so I'd be surprised if our tool proved to be the culprit in this case. :-)

    Unfortunately Arian got the versions of MVC mixed up in an earlier response. As a matter of fact, it is early versions of MVC 4 (not MVC 3) that have had problems processing certain multipart requests. Can you check what version of the framework you're using?

    Meanwhile, we will try to reproduce your issue on another platform (i.e. not MVC 4).

    Kind regards,
    Manne
  • Hello again,

    I've now verified that the multipart REST requests generated by SoapUI work fine with a REST service built on the Grails framework. In other words the requests are correct.

    If upgrading to the latest version of MVC doesn't work, maybe there's some kind of compatibility problem because SoapUI and MVC interpret the specs in different ways. Could you try to intercept the requests sent by Postman and Fiddler and post them here in the forum?

    Kind regards,
    Manne
  • Hi!

    We've tried to verify this, and found that there is indeed no newline in the end of the Raw request editor, but it is present in the http log tab in the bottom of the main SoapUI window and thus sent to the server.
    Could you please provide us with the full contents of the http log when you tried to send a request from SoapUI and it fails on the server.

    --
    Regards

    Erik
    SmartBear Sweden
  • Hi,

    What I see from your http log is that at the end of the request SoapUI is appending unix line ending "\n" and apparently it seems mvc 4 parser has a bug (http://aspnetwebstack.codeplex.com/discussions/354215) that it crashes if it does not receive windows line ending "\r\n" at the end of the request.

    Regardless of that, I have tried to send some request with multi-part form data and SoapUI seems to always send the windows line ending "\r\n". So, I was wondering it is possible to share some kind of sample project with sample attachment too so that we can reproduce the problem at our end. As long as we can see from http log that, it is not sending "\r\n" at the end of the request in that case we can further investigate this to figure out any solution or work around.

    Regards,
    Shadid
    SmartBear Sweden