async POST method C# '': not all code paths return a value
As I'm listening to lots of POST requests I'm trying to do it asynchronous with Promise like methodology.
The issue is that it it requires a return value outside of the "getDataLead" task(this case to uncomment the return "good2
" part).
Any ideas how can I make it so the POST method waits and returns the response from the asynced "matchLogic" function?
[HttpPost]
public async Task<string> Post([FromForm]string id)
{
String filterType = "id";
string filterValues = id;
int batchSize = 50;//max 300, default 300
String fields = { "email", "country", "city", "address", "postalCode", "phone", "company", "billingCountry", "billingCity", "billingPostalCode", "billingStreet", "mainPhone", "website" };//array of field names to retrieve
String nextPageToken = "";//paging token
Task<string> tr = await getDataLead(filterType, filterValues, batchSize, fields, nextPageToken).ContinueWith((t1) =>
{
if (t1.Exception == null)
{
getLeadsByFilterTypeRootObject data = JsonConvert.DeserializeObject<getLeadsByFilterTypeRootObject>(t1.Result);
if (data.success == true)
{
if (data.result.Count < 2)
{
return matchLogic(data.result[0]);
}
else
{
return Task.FromResult("not good");
}
}
else
{
return Task.FromResult("not good");
}
}
else
{
return Task.FromResult("not good");
}
});
// return "good2";
}
Thank you
c# asynchronous post promise continuewith
add a comment |
As I'm listening to lots of POST requests I'm trying to do it asynchronous with Promise like methodology.
The issue is that it it requires a return value outside of the "getDataLead" task(this case to uncomment the return "good2
" part).
Any ideas how can I make it so the POST method waits and returns the response from the asynced "matchLogic" function?
[HttpPost]
public async Task<string> Post([FromForm]string id)
{
String filterType = "id";
string filterValues = id;
int batchSize = 50;//max 300, default 300
String fields = { "email", "country", "city", "address", "postalCode", "phone", "company", "billingCountry", "billingCity", "billingPostalCode", "billingStreet", "mainPhone", "website" };//array of field names to retrieve
String nextPageToken = "";//paging token
Task<string> tr = await getDataLead(filterType, filterValues, batchSize, fields, nextPageToken).ContinueWith((t1) =>
{
if (t1.Exception == null)
{
getLeadsByFilterTypeRootObject data = JsonConvert.DeserializeObject<getLeadsByFilterTypeRootObject>(t1.Result);
if (data.success == true)
{
if (data.result.Count < 2)
{
return matchLogic(data.result[0]);
}
else
{
return Task.FromResult("not good");
}
}
else
{
return Task.FromResult("not good");
}
}
else
{
return Task.FromResult("not good");
}
});
// return "good2";
}
Thank you
c# asynchronous post promise continuewith
1
Make it non-async, then just return the value.
– Neil
Nov 22 '18 at 15:08
1
Make a variable, make your code asssign value to the variable and just return that variable, simple as that, you might need to give it a default value.
– mahlatse
Nov 22 '18 at 15:10
I've made the 3 methods to non-async and the POST still wants that return value outside the task response
– Mihai Dobrescu
Nov 22 '18 at 15:14
Change the prototype to be `public string Post([FromForm]string id)'
– Neil
Nov 22 '18 at 17:09
add a comment |
As I'm listening to lots of POST requests I'm trying to do it asynchronous with Promise like methodology.
The issue is that it it requires a return value outside of the "getDataLead" task(this case to uncomment the return "good2
" part).
Any ideas how can I make it so the POST method waits and returns the response from the asynced "matchLogic" function?
[HttpPost]
public async Task<string> Post([FromForm]string id)
{
String filterType = "id";
string filterValues = id;
int batchSize = 50;//max 300, default 300
String fields = { "email", "country", "city", "address", "postalCode", "phone", "company", "billingCountry", "billingCity", "billingPostalCode", "billingStreet", "mainPhone", "website" };//array of field names to retrieve
String nextPageToken = "";//paging token
Task<string> tr = await getDataLead(filterType, filterValues, batchSize, fields, nextPageToken).ContinueWith((t1) =>
{
if (t1.Exception == null)
{
getLeadsByFilterTypeRootObject data = JsonConvert.DeserializeObject<getLeadsByFilterTypeRootObject>(t1.Result);
if (data.success == true)
{
if (data.result.Count < 2)
{
return matchLogic(data.result[0]);
}
else
{
return Task.FromResult("not good");
}
}
else
{
return Task.FromResult("not good");
}
}
else
{
return Task.FromResult("not good");
}
});
// return "good2";
}
Thank you
c# asynchronous post promise continuewith
As I'm listening to lots of POST requests I'm trying to do it asynchronous with Promise like methodology.
The issue is that it it requires a return value outside of the "getDataLead" task(this case to uncomment the return "good2
" part).
Any ideas how can I make it so the POST method waits and returns the response from the asynced "matchLogic" function?
[HttpPost]
public async Task<string> Post([FromForm]string id)
{
String filterType = "id";
string filterValues = id;
int batchSize = 50;//max 300, default 300
String fields = { "email", "country", "city", "address", "postalCode", "phone", "company", "billingCountry", "billingCity", "billingPostalCode", "billingStreet", "mainPhone", "website" };//array of field names to retrieve
String nextPageToken = "";//paging token
Task<string> tr = await getDataLead(filterType, filterValues, batchSize, fields, nextPageToken).ContinueWith((t1) =>
{
if (t1.Exception == null)
{
getLeadsByFilterTypeRootObject data = JsonConvert.DeserializeObject<getLeadsByFilterTypeRootObject>(t1.Result);
if (data.success == true)
{
if (data.result.Count < 2)
{
return matchLogic(data.result[0]);
}
else
{
return Task.FromResult("not good");
}
}
else
{
return Task.FromResult("not good");
}
}
else
{
return Task.FromResult("not good");
}
});
// return "good2";
}
Thank you
c# asynchronous post promise continuewith
c# asynchronous post promise continuewith
asked Nov 22 '18 at 15:06
Mihai DobrescuMihai Dobrescu
31
31
1
Make it non-async, then just return the value.
– Neil
Nov 22 '18 at 15:08
1
Make a variable, make your code asssign value to the variable and just return that variable, simple as that, you might need to give it a default value.
– mahlatse
Nov 22 '18 at 15:10
I've made the 3 methods to non-async and the POST still wants that return value outside the task response
– Mihai Dobrescu
Nov 22 '18 at 15:14
Change the prototype to be `public string Post([FromForm]string id)'
– Neil
Nov 22 '18 at 17:09
add a comment |
1
Make it non-async, then just return the value.
– Neil
Nov 22 '18 at 15:08
1
Make a variable, make your code asssign value to the variable and just return that variable, simple as that, you might need to give it a default value.
– mahlatse
Nov 22 '18 at 15:10
I've made the 3 methods to non-async and the POST still wants that return value outside the task response
– Mihai Dobrescu
Nov 22 '18 at 15:14
Change the prototype to be `public string Post([FromForm]string id)'
– Neil
Nov 22 '18 at 17:09
1
1
Make it non-async, then just return the value.
– Neil
Nov 22 '18 at 15:08
Make it non-async, then just return the value.
– Neil
Nov 22 '18 at 15:08
1
1
Make a variable, make your code asssign value to the variable and just return that variable, simple as that, you might need to give it a default value.
– mahlatse
Nov 22 '18 at 15:10
Make a variable, make your code asssign value to the variable and just return that variable, simple as that, you might need to give it a default value.
– mahlatse
Nov 22 '18 at 15:10
I've made the 3 methods to non-async and the POST still wants that return value outside the task response
– Mihai Dobrescu
Nov 22 '18 at 15:14
I've made the 3 methods to non-async and the POST still wants that return value outside the task response
– Mihai Dobrescu
Nov 22 '18 at 15:14
Change the prototype to be `public string Post([FromForm]string id)'
– Neil
Nov 22 '18 at 17:09
Change the prototype to be `public string Post([FromForm]string id)'
– Neil
Nov 22 '18 at 17:09
add a comment |
1 Answer
1
active
oldest
votes
[HttpPost]
public async Task<string> Post([FromForm]string id)
{
String filterType = "id";
string filterValues = id;
Task<string> result = string.Empty;
int batchSize = 50;//max 300, default 300
String fields = { "email", "country", "city", "address", "postalCode", "phone", "company", "billingCountry", "billingCity", "billingPostalCode", "billingStreet", "mainPhone", "website" };//array of field names to retrieve
String nextPageToken = "";//paging token
Task<string> tr = await getDataLead(filterType, filterValues, batchSize, fields, nextPageToken).ContinueWith((t1) =>
{
if (t1.Exception == null)
{
getLeadsByFilterTypeRootObject data = JsonConvert.DeserializeObject<getLeadsByFilterTypeRootObject>(t1.Result);
if (data.success == true)
{
if (data.result.Count < 2)
{
result = matchLogic(data.result[0]);
}
else
{
result = Task.FromResult("not good");
}
}
else
{
result = Task.FromResult("not good");
}
}
else
{
result = Task.FromResult("not good");
}
});
return result;
}
That should force your application to get the value from the async stuff.
works with result as Task<string>, thank you
– Mihai Dobrescu
Nov 22 '18 at 15:23
Will update my answer, thanks for the heads up, I didn't check that typo
– mahlatse
Nov 22 '18 at 15:25
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53433759%2fasync-post-method-c-sharp-not-all-code-paths-return-a-value%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
[HttpPost]
public async Task<string> Post([FromForm]string id)
{
String filterType = "id";
string filterValues = id;
Task<string> result = string.Empty;
int batchSize = 50;//max 300, default 300
String fields = { "email", "country", "city", "address", "postalCode", "phone", "company", "billingCountry", "billingCity", "billingPostalCode", "billingStreet", "mainPhone", "website" };//array of field names to retrieve
String nextPageToken = "";//paging token
Task<string> tr = await getDataLead(filterType, filterValues, batchSize, fields, nextPageToken).ContinueWith((t1) =>
{
if (t1.Exception == null)
{
getLeadsByFilterTypeRootObject data = JsonConvert.DeserializeObject<getLeadsByFilterTypeRootObject>(t1.Result);
if (data.success == true)
{
if (data.result.Count < 2)
{
result = matchLogic(data.result[0]);
}
else
{
result = Task.FromResult("not good");
}
}
else
{
result = Task.FromResult("not good");
}
}
else
{
result = Task.FromResult("not good");
}
});
return result;
}
That should force your application to get the value from the async stuff.
works with result as Task<string>, thank you
– Mihai Dobrescu
Nov 22 '18 at 15:23
Will update my answer, thanks for the heads up, I didn't check that typo
– mahlatse
Nov 22 '18 at 15:25
add a comment |
[HttpPost]
public async Task<string> Post([FromForm]string id)
{
String filterType = "id";
string filterValues = id;
Task<string> result = string.Empty;
int batchSize = 50;//max 300, default 300
String fields = { "email", "country", "city", "address", "postalCode", "phone", "company", "billingCountry", "billingCity", "billingPostalCode", "billingStreet", "mainPhone", "website" };//array of field names to retrieve
String nextPageToken = "";//paging token
Task<string> tr = await getDataLead(filterType, filterValues, batchSize, fields, nextPageToken).ContinueWith((t1) =>
{
if (t1.Exception == null)
{
getLeadsByFilterTypeRootObject data = JsonConvert.DeserializeObject<getLeadsByFilterTypeRootObject>(t1.Result);
if (data.success == true)
{
if (data.result.Count < 2)
{
result = matchLogic(data.result[0]);
}
else
{
result = Task.FromResult("not good");
}
}
else
{
result = Task.FromResult("not good");
}
}
else
{
result = Task.FromResult("not good");
}
});
return result;
}
That should force your application to get the value from the async stuff.
works with result as Task<string>, thank you
– Mihai Dobrescu
Nov 22 '18 at 15:23
Will update my answer, thanks for the heads up, I didn't check that typo
– mahlatse
Nov 22 '18 at 15:25
add a comment |
[HttpPost]
public async Task<string> Post([FromForm]string id)
{
String filterType = "id";
string filterValues = id;
Task<string> result = string.Empty;
int batchSize = 50;//max 300, default 300
String fields = { "email", "country", "city", "address", "postalCode", "phone", "company", "billingCountry", "billingCity", "billingPostalCode", "billingStreet", "mainPhone", "website" };//array of field names to retrieve
String nextPageToken = "";//paging token
Task<string> tr = await getDataLead(filterType, filterValues, batchSize, fields, nextPageToken).ContinueWith((t1) =>
{
if (t1.Exception == null)
{
getLeadsByFilterTypeRootObject data = JsonConvert.DeserializeObject<getLeadsByFilterTypeRootObject>(t1.Result);
if (data.success == true)
{
if (data.result.Count < 2)
{
result = matchLogic(data.result[0]);
}
else
{
result = Task.FromResult("not good");
}
}
else
{
result = Task.FromResult("not good");
}
}
else
{
result = Task.FromResult("not good");
}
});
return result;
}
That should force your application to get the value from the async stuff.
[HttpPost]
public async Task<string> Post([FromForm]string id)
{
String filterType = "id";
string filterValues = id;
Task<string> result = string.Empty;
int batchSize = 50;//max 300, default 300
String fields = { "email", "country", "city", "address", "postalCode", "phone", "company", "billingCountry", "billingCity", "billingPostalCode", "billingStreet", "mainPhone", "website" };//array of field names to retrieve
String nextPageToken = "";//paging token
Task<string> tr = await getDataLead(filterType, filterValues, batchSize, fields, nextPageToken).ContinueWith((t1) =>
{
if (t1.Exception == null)
{
getLeadsByFilterTypeRootObject data = JsonConvert.DeserializeObject<getLeadsByFilterTypeRootObject>(t1.Result);
if (data.success == true)
{
if (data.result.Count < 2)
{
result = matchLogic(data.result[0]);
}
else
{
result = Task.FromResult("not good");
}
}
else
{
result = Task.FromResult("not good");
}
}
else
{
result = Task.FromResult("not good");
}
});
return result;
}
That should force your application to get the value from the async stuff.
edited Nov 22 '18 at 15:26
answered Nov 22 '18 at 15:13
mahlatsemahlatse
921517
921517
works with result as Task<string>, thank you
– Mihai Dobrescu
Nov 22 '18 at 15:23
Will update my answer, thanks for the heads up, I didn't check that typo
– mahlatse
Nov 22 '18 at 15:25
add a comment |
works with result as Task<string>, thank you
– Mihai Dobrescu
Nov 22 '18 at 15:23
Will update my answer, thanks for the heads up, I didn't check that typo
– mahlatse
Nov 22 '18 at 15:25
works with result as Task<string>, thank you
– Mihai Dobrescu
Nov 22 '18 at 15:23
works with result as Task<string>, thank you
– Mihai Dobrescu
Nov 22 '18 at 15:23
Will update my answer, thanks for the heads up, I didn't check that typo
– mahlatse
Nov 22 '18 at 15:25
Will update my answer, thanks for the heads up, I didn't check that typo
– mahlatse
Nov 22 '18 at 15:25
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53433759%2fasync-post-method-c-sharp-not-all-code-paths-return-a-value%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Make it non-async, then just return the value.
– Neil
Nov 22 '18 at 15:08
1
Make a variable, make your code asssign value to the variable and just return that variable, simple as that, you might need to give it a default value.
– mahlatse
Nov 22 '18 at 15:10
I've made the 3 methods to non-async and the POST still wants that return value outside the task response
– Mihai Dobrescu
Nov 22 '18 at 15:14
Change the prototype to be `public string Post([FromForm]string id)'
– Neil
Nov 22 '18 at 17:09