I have written a web service and constructor that adds objects to my list. I am getting an error that makes no sense to me because I am passing in the 3 parameters I should be passing in.
The error is:
There is no argument given that corresponds to the required formal
parameter 'myArticleID' of
'MainPage.GetTileDetails.GetTileDetails(string, string, int)'
Here is my code:
Web Service:
[OperationContract]
List<ViewDetails> ViewDetails();
[DataContract]
public class ViewDetails
{
[DataMember]
public string TitleView { get; set; }
[DataMember]
public string BodyView { get; set; }
[DataMember]
public int ArticleID { get; set; }
public ViewDetails() { }
public ViewDetails(string myTitleView, string myBodyView, int myArticleID)
{
this.TitleView = myTitleView;
this.BodyView = myBodyView;
this.ArticleID = myArticleID;
}
}
Project where i am using web service
public async void ViewData()
{
ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();
List<GetTileDetails> tileList = new List<GetTileDetails>();
var res = await client.ViewDetailsAsync();
for (int i = 0; i < res.Count; i++)
{
tileList.Add(new GetTileDetails(res[i].TitleView, res[i].BodyView.Substring(0, 170) + " ..."), res[i].ArticleID);
}
tileGridView.ItemsSource = tileList;
}
public class GetTileDetails
{
public string TitleView { get; set; }
public string BodyView { get; set; }
public int ArticleID { get; set; }
public GetTileDetails() { }
public GetTileDetails(string myTitleView, string myBodyView, int myArticleID)
{
this.TitleView = myTitleView;
this.BodyView = myBodyView;
this.ArticleID = myArticleID;
}
}
Can anyone tell me why I am getting that error? I am passing in (string, string, int)....
Replace this line:
tileList.Add(new GetTileDetails(res[i].TitleView, res[i].BodyView.Substring(0, 170) + " ..."), res[i].ArticleID);
with this one:
tileList.Add(new GetTileDetails(res[i].TitleView, res[i].BodyView.Substring(0, 170) + " ...", res[i].ArticleID));
Note you have a misplaced ) right after " ...").
Related
I have the following class
public class ResProductSetupData
{
public List<ProductSetup> data { get; set; }
}
public class ProductSetup
{
public List<Fundtype> FundType { get; set; }
}
public class Fundtype
{
public string FundType { get; set; }
public bool IsGIO { get; set; }
public string ReportCode { get; set; }
public List<Fundlist> FundList { get; set; }
}
public class Fundlist
{
public string FundCode { get; set; }
public string FundDesc { get; set; }
public decimal MinAllocation { get; set; }
public string VPMSField { get; set; }
public string FundSpec { get; set; }
}
Now I want to initialize this object inside another file so that I can fill its values. Fundtype is a list and FundList is another list inside FundType.
ProductSetup prodSetup = new ProductSetup();
Fundtype fundType = new Fundtype();
Fundlist fundlist = new Fundlist();
So Inside a foreach loop I instantiated these objects
prodSetup.FundType = new List<Fundtype>();
foreach (var fund in fundTypeData)
{
fundType.FundType = fund.FundType;
fundType.IsGIO = fund.IsGIO;
fundType.ReportCode = "";
prodSetup.FundType.Add(fundType);
var listOfFund = GetProductFund(prodSetup.ProdCode, fund.FundType);
int i = 0;
foreach (var listFundData in listOfFund)
{
var fundDetails = GetFundDetails(listFundData.FundCode);
fundlist.FundCode = listFundData.FundCode;
fundlist.VPMSField = listFundData.VPMSField;
fundlist.FundDesc = fundDetails[0].FundDesc;
fundlist.MinAllocation = fundDetails[0].MinAllocation;
fundlist.FundSpec = fundDetails[0].FundSpec;
prodSetup.FundType[i].FundList.Add(fundlist);
i++;
}
}
When I add data into the Fundlist list, an error will show System.NullReferenceException: 'Object reference not set to an instance of an object.'. I know I have to instantiate first, but I dont know how. Any help would be appreciated.
Update, I have instantiated the FundList array as below
int i = 0;
foreach (var listFundData in listOfFund)
{
prodSetup.FundType[i].FundList = new List<Fundlist>();
var fundDetails = GetFundDetails(listFundData.FundCode);
fundlist.FundCode = listFundData.FundCode;
fundlist.VPMSField = listFundData.VPMSField;
fundlist.FundDesc = fundDetails[0].FundDesc;
fundlist.MinAllocation = fundDetails[0].MinAllocation;
fundlist.FundSpec = fundDetails[0].FundSpec;
prodSetup.FundType[i].FundList.Add(fundlist);
i++;
}
The first index [0] is fine. But when it loops to the second index to instantiate the second index [1], it throws another error Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: index
I'm trying to realize the listBox with List where i getting some variable.
And when i wonna to add a new "Object" to static List i getting a NullReferenceException
This is my code where i adding a new List
if (EventArgsIn.Message.Chat.Id == MainChatId)
{
if (EventArgsIn.Message.ReplyToMessage != null)
{
var _tempMessage = new listBoxMessage()
{
From = EventArgsIn.Message.From.Username,
FromId = EventArgsIn.Message.From.Id,
MessageId = EventArgsIn.Message.MessageId,
MessageText = EventArgsIn.Message.Text,
MessageIdReply = 0
};
tempMessageMain.Add(_tempMessage);
} else
{
var _tempMessage = new listBoxMessage() {
From = EventArgsIn.Message.From.Username,
FromId = EventArgsIn.Message.From.Id,
MessageId = EventArgsIn.Message.MessageId,
MessageText = EventArgsIn.Message.Text,
MessageIdReply = 0
};
tempMessageMain.Add(_tempMessage);
}
}
And here is my static List
public static List<listBoxMessage> tempMessageMain;
A-a-and my class where i doing Template
public class listBoxMessage
{
public listBoxMessage()
{
}
public string From { get; set; }
public int FromId { get; set; }
public int MessageId { get; set; }
public string MessageText { get; set; }
public int MessageIdReply { get; set; }
}
}
This is test code*
You declared a listbox with next line:
public static List<listBoxMessage> tempMessageMain;
The value of tempMessageMain is still null.
Now you have to create a new instance of tempMessageMain:
public static List<listBoxMessage> tempMessageMain = new List<listBoxMessage>();
I'm a little bit stuck in Linq.
So first - I show you first the entities. I have a List let's name it "PersonalList" with another List of ListMembers.
public class PersonalList
{
public PersonalList();
public List<ListMember> ListMembers { get; set; }
public long ListNumber {get; set; }
public string Description {get; set;}
}
Here is the ListMember Class:
public class ListMember
{
public ListMember();
public string MemberName{ get; set; }
public long ListId {get; set; }
public string MemberType {get; set; }
public string Position {get; set; }
}
So now im my AppClass I have a List of the PersonalLists.
And I want to create a Dictionary, which has the PersonalList.ListNumber as Key and the Value should be the MemberName AND the MemberType.
What I have tried in first step is:
var personalLists = _allPersonalLists.Select(x => new {x.ListNumber, x.ListMembers).ToArray();
This solves the Problem with ListNumbers as Key. Now I want to have the ListMembers to be filtered so I have tried:
var personalLists = _allPersonalLists.Select(x => new {x.ListNumber, x.ListMembers.Select(y => new {y.MemberName, y.MemberType})}).ToArray();
But here - I get a compile error with following error message:
Error CS0746: Invalid anonymous type member declarator. Anonymous type
members must be declared with a member assignment, simple name or
member access.
So how can I achieve my goal? Any suggestions?
I tried to simulate your scenario and following solution will work for you.
public class PersonalList
{
public List<ListMember> ListMembers { get; set; }
public long ListNumber { get; set; }
public string Description { get; set; }
}
public class ListMember
{
public string MemberName { get; set; }
public long ListId { get; set; }
public string MemberType { get; set; }
public string Position { get; set; }
}
static void Main(string[] args)
{
List<PersonalList> _allPersonalLists = new List<PersonalList>();
for (int i = 1; i <= 5; i++)
{
List<ListMember> ListMembers = new List<ListMember>();
for (int j = 1; j <= 3; j++)
ListMembers.Add(new ListMember() { ListId = j, MemberName = "Member" + i + j, MemberType = "Type" + i, Position = "Position" + i });
_allPersonalLists.Add(new PersonalList() { ListNumber = i, ListMembers = ListMembers, Description = "Desc" + i });
}
var personalLists = _allPersonalLists.ToDictionary(x => x.ListNumber, x => x.ListMembers.Select(y => new { y.MemberName, y.MemberType }).ToList());
Console.ReadLine();
}
var personalLists = _allPersonalLists
.Select(x => new
{
x.ListNumber,
members = x.ListMembers
.Select(y => new
{
y.MemberName,
y.MemberType
}).ToList()
}).ToArray();
`.ToList()` i included to keep actual values otherwise it will be enumerable
I have a list defined as below in each of 11 different classes (which handle web-services)
private List<edbService> genEdbService;
internal class edbService
{
public string ServiceID { get; set; }
public string ServiceName { get; set; }
public string ServiceDescr { get; set; }
public string ServiceInterval { get; set; }
public string ServiceStatus { get; set; }
public string ServiceUrl { get; set; }
public string SourceApplication { get; set; }
public string DestinationApplication { get; set; }
public string Function { get; set; }
public string Version { get; set; }
public string userid { get; set; }
public string credentials { get; set; }
public string orgid { get; set; }
public string orgunit { get; set; }
public string customerid { get; set; }
public string channel { get; set; }
public string ip { get; set; }
}
The list is populated in each class by reading the web-service configuration data from xml files in each class:
public DCSSCustomerCreate_V3_0()
{
try
{
XElement x = XElement.Load(global::EvryCardManagement.Properties.Settings.Default.DataPath + "CustomerCreate.xml");
// Get global settings
IEnumerable<XElement> services = from el in x.Descendants("Service")
select el;
if (services != null)
{
edb_service = new List<edbService>();
// edb_service= Common.populateEDBService("CustomerCreate.xml");
foreach (XElement srv in services)
{
edbService edbSrv = new edbService();
edbSrv.ServiceID = srv.Element("ServiceID").Value;
edbSrv.ServiceName = srv.Element("ServiceName").Value;
edbSrv.ServiceDescr = srv.Element("ServiceDescr").Value;
edbSrv.ServiceInterval = srv.Element("ServiceInterval").Value;
edbSrv.ServiceStatus = srv.Element("ServiceStatus").Value;
edbSrv.ServiceUrl = srv.Element("ServiceUrl").Value;
foreach (XElement ServiceHeader in srv.Elements("ServiceHeader"))
{
...
now what I want to do is have this code in one place in my Common.cs class so I tried:
public static List<edbService> populateEDBService(string xmlDataFile)
{
try
{
XElement x = XElement.Load(global::EvryCardManagement.Properties.Settings.Default.DataPath + xmlDataFile);
// Get global settings
IEnumerable<XElement> services = from el in x.Descendants("Service")
select el;
if (services != null)
{
//edb_Service = new List<edbService>();
foreach (XElement srv in services)
{
edbService edbSrv = new edbService();
edbSrv.ServiceID = srv.Element("ServiceID").Value;
edbSrv.ServiceName = srv.Element("ServiceName").Value;
edbSrv.ServiceDescr = srv.Element("ServiceDescr").Value;
edbSrv.ServiceInterval = srv.Element("ServiceInterval").Value;
edbSrv.ServiceStatus = srv.Element("ServiceStatus").Value;
edbSrv.ServiceUrl = srv.Element("ServiceUrl").Value;
foreach (XElement ServiceHeader in srv.Elements("ServiceHeader"))
{
edbSrv.SourceApplication = ServiceHeader.Element("SourceApplication").Value;
edbSrv.DestinationApplication = ServiceHeader.Element("DestinationApplication").Value;
edbSrv.Function = ServiceHeader.Element("Function").Value;
edbSrv.Version = ServiceHeader.Element("Version").Value;
foreach (XElement ClientContext in ServiceHeader.Elements("ClientContext"))
{
edbSrv.userid = ClientContext.Element("userid").Value;
edbSrv.credentials = ClientContext.Element("credentials").Value;
edbSrv.orgid = ClientContext.Element("orgid").Value;
edbSrv.orgunit = ClientContext.Element("orgunit").Value;
edbSrv.customerid = ClientContext.Element("customerid").Value;
edbSrv.channel = ClientContext.Element("channel").Value;
edbSrv.ip = ClientContext.Element("ip").Value;
}
}
// populateEDBService.Add(edbSrv);
}
}
}
catch (Exception ex)
{
/* Write to log */
Common.logBuilder("CustomerCreate : Form --> CustomerCreate <--", "Exception", Common.ActiveMQ,
ex.Message, "Exception");
/* Send email to support */
emailer.exceptionEmail(ex);
}
return;
}
Now I get a compile error on the return; saying that An object of a type convertible to 'System.Collections.Generic.List<EvryCardManagement.Common.edbService>' is required
and in the class that should call this method, I want to do something like:
edb_service = Common.populateEDBService("CustomerUpdate.xml");
but I get an error Cannot implicitly convert type 'System.Collections.Generic.List<EvryCardManagement.Common.edbService>' to 'System.Collections.Generic.List<EvryCardManagement.CustomerUpdate.edbService>'
So firstly how should I return the list from my generic method and how should I call it to return the list populated with the configuration data?
It sounds like you have your class edbService defined in two namespaces,
EvryCardManagement.Common and
EvryCardManagement.CustomerUpdate
I would suggest defining it in only EvryCardManagement.Common and have everything reference it from there.
This is my code for retrieving the list of comments from couchbase. The design document name is "Task" and the view name is: "GetComments".
public List<CommentsVO> GetComments(string TaskID, int LastCommentID, int totalCommentCount)
{
int startCount = LastCommentID - 1;
int endCount = startCount - 19;
int remainingCount = totalCommentCount - endCount;
if (endCount < 0)
{
endCount = 0;// totalCommentCount - remainingCount;
}
IView<CommentsVO> results = oCouchbase.GetView<CommentsVO>("Task", "GetComments");
results.StartKey(new object[] { TaskID, startCount }).EndKey(new object[] { TaskID, endCount });
if (results != null)
{
List<CommentsVO> resultlist = new List<CommentsVO>();
foreach (CommentsVO vo in results)//Here it is not entering inside the loop... Am i missing anything in this condition
{
resultlist.Add(vo);
}
resultlist.Reverse();
return resultlist;
}
return null;
}
My CommentsVo code is:
public class CommentsVO
{
public CommentsVO()
{
CommentedOn = Convert.ToString(DateTime.Now);
IsActive = "1";
}
[JsonIgnore]
public string TaskID { get; set; }
[JsonProperty("commented_user_id")]
public string CommentedUserID { get; set; }
[JsonProperty("commented_user_name")]
public string CommentedUserName { get; set; }
[JsonProperty("comment_description")]
public string CommentDescription { get; set; }
[JsonProperty("commented_on")]
public string CommentedOn { get; set; }
[JsonProperty("is_active")]
public string IsActive { get; set; }
[JsonProperty("seq")]
public string Sequence { get; set; }
}
My couchbase view code is:
function(doc) {
for(var i in doc.comments) {
emit([doc._id,doc.comments[i].seq],doc.comments[i]);
}
}
I have tried without using startkey and endkey its iterating but when i tried using startkey and endkey it is not entering inside the loop..
Kindly help me out..
When using a composite key, you would specify an array of keys in StartKey/EndKey. In your code, you're actually overwriting the keys with your second calls to StarKey and EndKey.
So something like:
results.StartKey(new object[] { TaskId, startCount }).EndKey(new object[] { TaskId, endCount });