System.InvalidOperationException: 'The type System.Collections.Generic.List`1 may not be used in this...
I have an asmx which returns data to a client.
In the asmx I have the following method :
[WebMethod]
[XmlInclude(typeof(CustomField))]
public List<CustomField> GetData(InitializeRequest request)
{
return xmlAccessLogic.GetData(request.Map()).Map();
}
The CustomField is a custom-type I am creating. At this moment it looks as follows:
public class CustomField: Object
{
public string Key { get; set; }
public object Value { get; set; }
public CustomField()
{
}
public CustomField(string key, object value)
{
Key = key;
Value = value;
}
}
When I get my data, I return it as a List> which is then mapped to a list of my CustomField-object.
When I do the following I get an error :
List<KeyValuePair<string, Object>> clientcollection = new List<KeyValuePair<string, Object>>();
List<KeyValuePair<string, Object>> companiesCollection = new List<KeyValuePair<string, Object>>();
companiesCollection.Add(new KeyValuePair<string, Object>("Count", 1));
companiesCollection.Add(new KeyValuePair<string, Object>("HitsLeft", _hbXmlAccessRepository.GetNumberOfHitsLeft(request.UserName, request.PassWord)));
clientcollection.Add(new KeyValuePair<string, Object>("Vat", generalDataResult.VatNumber));
companiesCollection.Add(new KeyValuePair<string, Object>("firm", clientcollection));
return companiesCollection;
When I don't add the clientCollection to the companiesCollection everything works fine and my clientapplication receives the data.
When I do add the clientCollection, I get an exception.
The exception I get is the following :
System.InvalidOperationException: 'The type System.Collections.Generic.List
1[[System.Collections.Generic.KeyValuePair
2[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] may not be used in this context.'
What have I forgotten?
I have been looking around and reading, but I didn't find the solution just yet.
(I know my CustomField-object looks like a KeyValuePair, but we have just started and there will be additional fields added to it)
What the client programmer expects, might look as follows:
CompaniesCollection[
Count="1"
HitsLeft="248"
firm[
Vat=423584152
Name= "Some Name"
JurFormID=14
]
firm[
Vat=42358468
Name= "Some Other Name"
JurFormID=14
]
]
c# asmx webmethod keyvaluepair xmlinclude
add a comment |
I have an asmx which returns data to a client.
In the asmx I have the following method :
[WebMethod]
[XmlInclude(typeof(CustomField))]
public List<CustomField> GetData(InitializeRequest request)
{
return xmlAccessLogic.GetData(request.Map()).Map();
}
The CustomField is a custom-type I am creating. At this moment it looks as follows:
public class CustomField: Object
{
public string Key { get; set; }
public object Value { get; set; }
public CustomField()
{
}
public CustomField(string key, object value)
{
Key = key;
Value = value;
}
}
When I get my data, I return it as a List> which is then mapped to a list of my CustomField-object.
When I do the following I get an error :
List<KeyValuePair<string, Object>> clientcollection = new List<KeyValuePair<string, Object>>();
List<KeyValuePair<string, Object>> companiesCollection = new List<KeyValuePair<string, Object>>();
companiesCollection.Add(new KeyValuePair<string, Object>("Count", 1));
companiesCollection.Add(new KeyValuePair<string, Object>("HitsLeft", _hbXmlAccessRepository.GetNumberOfHitsLeft(request.UserName, request.PassWord)));
clientcollection.Add(new KeyValuePair<string, Object>("Vat", generalDataResult.VatNumber));
companiesCollection.Add(new KeyValuePair<string, Object>("firm", clientcollection));
return companiesCollection;
When I don't add the clientCollection to the companiesCollection everything works fine and my clientapplication receives the data.
When I do add the clientCollection, I get an exception.
The exception I get is the following :
System.InvalidOperationException: 'The type System.Collections.Generic.List
1[[System.Collections.Generic.KeyValuePair
2[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] may not be used in this context.'
What have I forgotten?
I have been looking around and reading, but I didn't find the solution just yet.
(I know my CustomField-object looks like a KeyValuePair, but we have just started and there will be additional fields added to it)
What the client programmer expects, might look as follows:
CompaniesCollection[
Count="1"
HitsLeft="248"
firm[
Vat=423584152
Name= "Some Name"
JurFormID=14
]
firm[
Vat=42358468
Name= "Some Other Name"
JurFormID=14
]
]
c# asmx webmethod keyvaluepair xmlinclude
A good Google query is "webmethod the type may not be used in this context". It has too many hits on SO to pick the best dup, but the short of it is that you can't use Object.
– Hans Passant
Nov 15 '18 at 12:28
@HansPassant And how would I have to change my code so I can include my clientCollection into my companiesCollection?
– Bart Schelkens
Nov 15 '18 at 12:30
You can't use Object, that does mean that what you posted is unusable and has to be thrown away. Changing it won't help. Step in the shoes of the client programmer, he needs a concrete object type to work with so he knows what to expect. Declare that type in your code.
– Hans Passant
Nov 15 '18 at 12:43
@HansPassant what the clientprogrammer expexts is an array of values of which some values themselves might be an array containing more values.
– Bart Schelkens
Nov 15 '18 at 12:46
add a comment |
I have an asmx which returns data to a client.
In the asmx I have the following method :
[WebMethod]
[XmlInclude(typeof(CustomField))]
public List<CustomField> GetData(InitializeRequest request)
{
return xmlAccessLogic.GetData(request.Map()).Map();
}
The CustomField is a custom-type I am creating. At this moment it looks as follows:
public class CustomField: Object
{
public string Key { get; set; }
public object Value { get; set; }
public CustomField()
{
}
public CustomField(string key, object value)
{
Key = key;
Value = value;
}
}
When I get my data, I return it as a List> which is then mapped to a list of my CustomField-object.
When I do the following I get an error :
List<KeyValuePair<string, Object>> clientcollection = new List<KeyValuePair<string, Object>>();
List<KeyValuePair<string, Object>> companiesCollection = new List<KeyValuePair<string, Object>>();
companiesCollection.Add(new KeyValuePair<string, Object>("Count", 1));
companiesCollection.Add(new KeyValuePair<string, Object>("HitsLeft", _hbXmlAccessRepository.GetNumberOfHitsLeft(request.UserName, request.PassWord)));
clientcollection.Add(new KeyValuePair<string, Object>("Vat", generalDataResult.VatNumber));
companiesCollection.Add(new KeyValuePair<string, Object>("firm", clientcollection));
return companiesCollection;
When I don't add the clientCollection to the companiesCollection everything works fine and my clientapplication receives the data.
When I do add the clientCollection, I get an exception.
The exception I get is the following :
System.InvalidOperationException: 'The type System.Collections.Generic.List
1[[System.Collections.Generic.KeyValuePair
2[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] may not be used in this context.'
What have I forgotten?
I have been looking around and reading, but I didn't find the solution just yet.
(I know my CustomField-object looks like a KeyValuePair, but we have just started and there will be additional fields added to it)
What the client programmer expects, might look as follows:
CompaniesCollection[
Count="1"
HitsLeft="248"
firm[
Vat=423584152
Name= "Some Name"
JurFormID=14
]
firm[
Vat=42358468
Name= "Some Other Name"
JurFormID=14
]
]
c# asmx webmethod keyvaluepair xmlinclude
I have an asmx which returns data to a client.
In the asmx I have the following method :
[WebMethod]
[XmlInclude(typeof(CustomField))]
public List<CustomField> GetData(InitializeRequest request)
{
return xmlAccessLogic.GetData(request.Map()).Map();
}
The CustomField is a custom-type I am creating. At this moment it looks as follows:
public class CustomField: Object
{
public string Key { get; set; }
public object Value { get; set; }
public CustomField()
{
}
public CustomField(string key, object value)
{
Key = key;
Value = value;
}
}
When I get my data, I return it as a List> which is then mapped to a list of my CustomField-object.
When I do the following I get an error :
List<KeyValuePair<string, Object>> clientcollection = new List<KeyValuePair<string, Object>>();
List<KeyValuePair<string, Object>> companiesCollection = new List<KeyValuePair<string, Object>>();
companiesCollection.Add(new KeyValuePair<string, Object>("Count", 1));
companiesCollection.Add(new KeyValuePair<string, Object>("HitsLeft", _hbXmlAccessRepository.GetNumberOfHitsLeft(request.UserName, request.PassWord)));
clientcollection.Add(new KeyValuePair<string, Object>("Vat", generalDataResult.VatNumber));
companiesCollection.Add(new KeyValuePair<string, Object>("firm", clientcollection));
return companiesCollection;
When I don't add the clientCollection to the companiesCollection everything works fine and my clientapplication receives the data.
When I do add the clientCollection, I get an exception.
The exception I get is the following :
System.InvalidOperationException: 'The type System.Collections.Generic.List
1[[System.Collections.Generic.KeyValuePair
2[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] may not be used in this context.'
What have I forgotten?
I have been looking around and reading, but I didn't find the solution just yet.
(I know my CustomField-object looks like a KeyValuePair, but we have just started and there will be additional fields added to it)
What the client programmer expects, might look as follows:
CompaniesCollection[
Count="1"
HitsLeft="248"
firm[
Vat=423584152
Name= "Some Name"
JurFormID=14
]
firm[
Vat=42358468
Name= "Some Other Name"
JurFormID=14
]
]
c# asmx webmethod keyvaluepair xmlinclude
c# asmx webmethod keyvaluepair xmlinclude
edited Nov 15 '18 at 12:51
Bart Schelkens
asked Nov 15 '18 at 11:07
Bart SchelkensBart Schelkens
4133927
4133927
A good Google query is "webmethod the type may not be used in this context". It has too many hits on SO to pick the best dup, but the short of it is that you can't use Object.
– Hans Passant
Nov 15 '18 at 12:28
@HansPassant And how would I have to change my code so I can include my clientCollection into my companiesCollection?
– Bart Schelkens
Nov 15 '18 at 12:30
You can't use Object, that does mean that what you posted is unusable and has to be thrown away. Changing it won't help. Step in the shoes of the client programmer, he needs a concrete object type to work with so he knows what to expect. Declare that type in your code.
– Hans Passant
Nov 15 '18 at 12:43
@HansPassant what the clientprogrammer expexts is an array of values of which some values themselves might be an array containing more values.
– Bart Schelkens
Nov 15 '18 at 12:46
add a comment |
A good Google query is "webmethod the type may not be used in this context". It has too many hits on SO to pick the best dup, but the short of it is that you can't use Object.
– Hans Passant
Nov 15 '18 at 12:28
@HansPassant And how would I have to change my code so I can include my clientCollection into my companiesCollection?
– Bart Schelkens
Nov 15 '18 at 12:30
You can't use Object, that does mean that what you posted is unusable and has to be thrown away. Changing it won't help. Step in the shoes of the client programmer, he needs a concrete object type to work with so he knows what to expect. Declare that type in your code.
– Hans Passant
Nov 15 '18 at 12:43
@HansPassant what the clientprogrammer expexts is an array of values of which some values themselves might be an array containing more values.
– Bart Schelkens
Nov 15 '18 at 12:46
A good Google query is "webmethod the type may not be used in this context". It has too many hits on SO to pick the best dup, but the short of it is that you can't use Object.
– Hans Passant
Nov 15 '18 at 12:28
A good Google query is "webmethod the type may not be used in this context". It has too many hits on SO to pick the best dup, but the short of it is that you can't use Object.
– Hans Passant
Nov 15 '18 at 12:28
@HansPassant And how would I have to change my code so I can include my clientCollection into my companiesCollection?
– Bart Schelkens
Nov 15 '18 at 12:30
@HansPassant And how would I have to change my code so I can include my clientCollection into my companiesCollection?
– Bart Schelkens
Nov 15 '18 at 12:30
You can't use Object, that does mean that what you posted is unusable and has to be thrown away. Changing it won't help. Step in the shoes of the client programmer, he needs a concrete object type to work with so he knows what to expect. Declare that type in your code.
– Hans Passant
Nov 15 '18 at 12:43
You can't use Object, that does mean that what you posted is unusable and has to be thrown away. Changing it won't help. Step in the shoes of the client programmer, he needs a concrete object type to work with so he knows what to expect. Declare that type in your code.
– Hans Passant
Nov 15 '18 at 12:43
@HansPassant what the clientprogrammer expexts is an array of values of which some values themselves might be an array containing more values.
– Bart Schelkens
Nov 15 '18 at 12:46
@HansPassant what the clientprogrammer expexts is an array of values of which some values themselves might be an array containing more values.
– Bart Schelkens
Nov 15 '18 at 12:46
add a comment |
0
active
oldest
votes
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%2f53318111%2fsystem-invalidoperationexception-the-type-system-collections-generic-list1-ma%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
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%2f53318111%2fsystem-invalidoperationexception-the-type-system-collections-generic-list1-ma%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
A good Google query is "webmethod the type may not be used in this context". It has too many hits on SO to pick the best dup, but the short of it is that you can't use Object.
– Hans Passant
Nov 15 '18 at 12:28
@HansPassant And how would I have to change my code so I can include my clientCollection into my companiesCollection?
– Bart Schelkens
Nov 15 '18 at 12:30
You can't use Object, that does mean that what you posted is unusable and has to be thrown away. Changing it won't help. Step in the shoes of the client programmer, he needs a concrete object type to work with so he knows what to expect. Declare that type in your code.
– Hans Passant
Nov 15 '18 at 12:43
@HansPassant what the clientprogrammer expexts is an array of values of which some values themselves might be an array containing more values.
– Bart Schelkens
Nov 15 '18 at 12:46