I am new to .Net framework and I am getting an error message
Value of type 'List(Of AdminSetEmployeeParams)' cannot be converted to
'AdminSetEmployeeParams'"
Dim SetNewEmployee As New List(Of AdminSetEmployeeParams)
SetNewEmployee.Add(New AdminSetEmployeeParams With {
.departmentId = ddlDept.SelectedValue,
.familyName = txtLastOrSurname.Text,
.firstName = txtFirstOrGivenName.Text,
.secondName = txtSecondName.Text,
.contactPhone = txtPhone.Text,
.user = ""})
SetNewEmployee = EmployeeAPIService.AdminSetEmployee(SetNewEmployee).Result
How would I resolve this error?
Update:
System.Threading.Tasks
Public Class Task(Of TResult)
Public ReadOnly Property Result As TResult
It's probably this, but it's hard to be sure:
Dim newEmployee As New AdminSetEmployeeParams
newEmployee = New AdminSetEmployeeParams With {
.departmentId = ddlDept.SelectedValue,
.familyName = txtLastOrSurname.Text,
.firstName = txtFirstOrGivenName.Text,
.secondName = txtSecondName.Text,
.contactPhone = txtPhone.Text,
.user = ""})
Dim newEmployeeResult As List(Of AdminSetEmployeeParams) = EmployeeAPIService.AdminSetEmployee(newEmployee).Result
I'm not sure why your API returns a list of employees in its result (I'm assuming it does because you don't say you have an error message complaining about the assignment of the result to a list(of...) ) but the error as given would reasonably only occur if the API call demanded a single new employee and you handed it a list of new employees
If it doesn't work out, try this last line
Dim newEmployeeResult As AdminSetEmployeeParams = EmployeeAPIService.AdminSetEmployee(newEmployee).Result
And if that doesn't work out, edit your question to give more info on what kind of arguments AdminSetEmployee takes and what kind of object .Result is
Related
Dim name As String = "hello"
If CType(My.Application.OpenForms(name), Faker) Is Nothing Then
New Faker() With {.Name = name, .Title = String.Format("{0} - ID:{1}", "hello", Me.ClassClient.ClientAddressID)}.Show()
End If
Syntax error in New , if i remove all code and write Dim F As New Faker() With {} and F.show() no error but not work and give me error while running the program object reference not set to an instance of an object
can any one here help me pls
There are two answers here Constructing an object and calling a method without assignment in VB.Net that should help.
Use With ... End With
Use Call
I think you're having an issue because you're trying to use the C# style of creating an instance of an object without assigning it before chaining a method call.
Your code becomes:
Dim name As String = "hello"
If CType(My.Application.OpenForms(name), Faker) Is Nothing Then
With New Faker() With {.Name = name, .Title = String.Format("{0} - ID:{1}", "hello", Me.ClassClient.ClientAddressID)}
.Show()
End If
Or
Dim name As String = "hello"
If CType(My.Application.OpenForms(name), Faker) Is Nothing Then
Call New Faker() With {.Name = name, .Title = String.Format("{0} - ID:{1}", "hello", Me.ClassClient.ClientAddressID)}.Show()
End If
I am trying to create dynamic report subscriptions through rs.exe. How ever I cannot get the parameters to work. The enddate value is data/time, so I think that might be causing it, but I do not know what to do about it. I have tried casting, but the error msg. stays the same.
rs.exe call:
C:\Program Files (x86)\Microsoft SQL Server\130\Tools\Binn>rs.exe -i C:\Users\me\Desktop\rss_gen\subs.rss -s "localhost/ReportserverT"
subs.rss file:
Public Sub Main()
rs.Credentials = System.Net.CredentialCache.DefaultCredentials
Dim desc As String = "Report description"
Dim eventType As String = "TimedSubscription"
Dim scheduleXml As String = "<ScheduleDefinition><StartDateTime>2017-12-08T15:00:00</StartDateTime><WeeklyRecurrence><WeeksInterval>1</WeeksInterval><DaysOfWeek><Thursday>True</Thursday></DaysOfWeek></WeeklyRecurrence></ScheduleDefinition>"
Dim parameters() As ParameterValue
' If you need setup parameters
Dim parameter As ParameterValue
parameter.Name = "enddate"
parameter.Value = "2017-12-30 10:03:01.250" 'this is date/time
parameters(0) = parameter
Dim matchData As String = scheduleXml
Dim returnValue As String
Dim reports() As String = { _
"/My Folder/report"}
For Each report As String In reports
returnValue = rs.CreateSubscription(report, parameters)
Console.WriteLine(returnValue)
Next
End Sub 'Main`enter code here`
Error msg:
C:\Users\mee\AppData\Local\Temp\11\dhexge0m.1.vb(43) : error BC30455:
Argument n ot specified for parameter 'Parameters' of 'Public Function
CreateSubscription(R eport As String, ExtensionSettings As
Microsoft.SqlServer.ReportingServices2005. ExtensionSettings,
Description As String, EventType As String, MatchData As Stri ng,
Parameters() As
Microsoft.SqlServer.ReportingServices2005.ParameterValue) As String'.
Let me teach you a trick to program in .Net and in general. It sounds simple, all you need to do is pass functions what they expect. Let me give you a simple example.
With this code I've got a similar error to you:
CS7036 There is no argument given that corresponds to the required formal parameter 'fileName' of 'FileInfo.FileInfo(string)'
The squiggle red line tells you where the problem is. If I type the opening bracket it will give me a tooltip with what it expects:
Ok it needs a string, so I declare a string and give it to the function as it expects:
So the problem you have is because you are not giving the CreateSubscription function the parameters it expects.
Argument not specified for parameter 'Parameters' of 'Public Function CreateSubscription
To fix it provide all the mandatory parameters to the ReportingService2005.CreateSubscription Method:
public static void Main()
{
ReportingService2005 rs = new ReportingService2005();
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
string report = "/SampleReports/Employee Sales Summary";
string desc = "Send email to anyone#microsoft.com";
string eventType = "TimedSubscription";
string scheduleXml = #"<ScheduleDefinition><StartDateTime>2003-02-24T09:00:00-08:00</StartDateTime><WeeklyRecurrence><WeeksInterval>1</WeeksInterval><DaysOfWeek><Monday>True</Monday></DaysOfWeek></WeeklyRecurrence></ScheduleDefinition>";
ParameterValue[] extensionParams = new ParameterValue[8];
extensionParams[0] = new ParameterValue();
extensionParams[0].Name = "TO";
extensionParams[0].Value = "dank#adventure-works.com";
extensionParams[1] = new ParameterValue();
extensionParams[1].Name = "ReplyTo";
extensionParams[1].Value = "reporting#adventure-works.com";
ParameterValue parameter = new ParameterValue();
parameter.Name = "EmpID";
parameter.Value = "38";
ParameterValue[] parameters = new ParameterValue[1];
parameters[0] = parameter;
string matchData = scheduleXml;
ExtensionSettings extSettings = new ExtensionSettings();
extSettings.ParameterValues = extensionParams;
extSettings.Extension = "Report Server Email";
try
{
rs.CreateSubscription(report, extSettings, desc, eventType, matchData, parameters);
}
catch (SoapException e)
{
Console.WriteLine(e.Detail.InnerXml.ToString());
}
}
As part of the 2005 report service for ms SQL, none of the parameters passed to CreateSubscription are optional. Please refer to the link and update the way you are calling the function. The error is clear, you are missing the parameters which is the last one. Look at the bottom of the page for an example.
https://technet.microsoft.com/en-us/library/microsoft.wssux.reportingserviceswebservice.rsmanagementservice2005.reportingservice2005.createsubscription(v=sql.90).aspx
Hi I got the error when return EF as the list. Here are my codes.
WCF
Public Function GetMerchantList() As List(Of Merchant) Implements IMerchant.GetMerchantList
Dim ws As New aMerchantService.MerchantServiceClient
Dim General As New General
Dim kWSUrl As String = ""
Dim endpointAddress = ws.Endpoint.Address
Dim newEndpointAddress As New EndpointAddressBuilder(endpointAddress)
kWSUrl = General.ConvertWsURL("App")
newEndpointAddress.Uri = New Uri(kWSUrl & "MerchantService.svc")
ws = New aMerchantService.MerchantServiceClient("BasicHttpBinding_IMerchantService", newEndpointAddress.ToEndpointAddress())
Dim Data = ws.GetMerchantList()
Return Data
End Function
Merchant Class
Public Function GetMerchantList() As List(Of Merchant)
Dim Db As New TTMSEntities
Dim Data = (From p In Db.TT_MERCHANT Join r In Db.TT_BRANCH_SETTING On _
p.MERCHANT_BRANCH_INTERNAL_NUM Equals r.INTERNAL_NUM _
Select New Merchant With {.MerchantID = p.MERCHANT_ID,
.MerchantName = p.DESCRIPTION,
.BranchID = r.INTERNAL_NUM,
.BranchName = r.BRANCH_DESC})
If Data IsNot Nothing Then
Return Data.ToList
Else
Return Nothing
End If
End Function
The error is Error Value of type '1-dimensional array of
TTMS.App.WebSites.Data.Merchant' cannot be converted to
'System.Collections.Generic.List(Of TTMS.Web.WebSites.WCF.Merchant)'.
Please help. Thanks
It looks like you're using a service reference. By default, WCF will serialize generic lists as arrays. To override this behavior, when you go to add the service reference, click on the Advanced button at the bottom left corner. This will bring up the Service Reference Settings. Select System.Generics.List for the collection type (the default is System.Array):
I am trying to get the following to work
Function AddService(id As Integer) As ViewResult
Dim serv As RequestedService = New RequestedService
serv.JobId = id
Dim ServiceList = New List(Of RequestedService)()
Dim ServiceQuery = From s In db.Services
Select s
ServiceList.AddRange(ServiceQuery)
ViewBag.ServiceId = New SelectList(ServiceList, s.IDServices, s.ServiceName)
Return View(serv)
End Function
But
ViewBag.ServiceId = New SelectList(ServiceList, s.IDServices, s.ServiceName)
Gives me the following error: 's' is not declared. It may be inaccessible due to its protection level.
I cannot work out how to correct this. Essentially I need to populate the SelectList with both an id and string and pass it to the view?
Assuming that the RequestedService model has properties called IDServices and ServiceName you could use the following:
ViewBag.ServiceId = New SelectList(ServiceList, "IDServices", "ServiceName")
But you really don't need this intermediary list:
Function AddService(id As Integer) As ViewResult
Dim serv As RequestedService = New RequestedService
serv.JobId = id
ViewBag.ServiceId = New SelectList(db.Services, "IDServices", "ServiceName")
Return View(serv)
End Function
And you really, really, really don't need to use ViewBag, but use view models instead.
Function AddService(id As Integer) As ViewResult
Dim model = New RequestedServiceViewModel
model.JobId = id
model.Services = New SelectList(db.Services, "IDServices", "ServiceName")
Return View(model)
End Function
and now your view is strongly typed to the view model:
#ModelType RequestedServiceViewModel
#Html.DropDownListFor(Function(x) x.ServiceId, Model.Services)
I have a function that updates a user in the asp.net membership provider.
<AcceptVerbs(HttpVerbs.Post)>
Public Function EnableUser(ByVal id As String) As JsonResult
Dim usr As StargatePortalUser = _membershipService.GetUser(id, Nothing)
usr.IsApproved = True
_membershipService.UpdateUser(usr)
Dim response As New AjaxResponse(usr.UserName)
Return Json(response)
End Function
I am trying to test this function to ensure the IsApproved property is set correctly
<TestMethod()>
Public Sub Service_Can_Enable_A_User_Account()
' Arrange
Dim usr As New Mock(Of MembershipUser)
usr.SetupProperty(Function(u) u.IsApproved)
_membershipService.Setup(Function(m) m.GetUser(It.IsAny(Of String), It.IsAny(Of Boolean))).Returns(usr.Object)
Dim target As New UsersController(_membershipService.Object)
target.ControllerContext = New ControllerContext(FakeAuthenticatedHttpContext("testuser", String.Empty, True, True, False), New RouteData, target)
' Act
Dim actual As JsonResult = target.EnableUser("userId")
' Assert
Assert.IsTrue(DirectCast(actual.Data, AjaxResponse).Success)
_membershipService.Verify(Sub(m) m.UpdateUser(It.IsAny(Of MembershipUser)), Times.Once)
usr.Verify(Function(u) u.IsApproved = True)
End Sub
When I try to verify that the IsApproved property has been set to True an exception is returned:
System.ArgumentException: Expression is not a method invocation: u => (u.IsApproved == True)
There are so few examples of using Moq in VB that I can't figure this out, any help would be appreciated.
This is an ASP.NET MVC2 app in VB.NET 10 (.NET 4.0)
EDIT:
Ok, turns out it's not quite so straight forward in VB.
usr.Verify(Function(u) u.IsApproved = True)
needs to be
usr.VerifySet(Function(u) InlineAssignHelper(u.IsApproved, True))
and you need to add the following function:
Private Shared Function InlineAssignHelper(Of T)(ByRef target As T, ByVal value As T) As T
target = value
Return value
End Function
FURTHER EDIT:
Thinking around the problem I arrived at a more simple solution. I changed
Dim usr As New Mock(Of MembershipUser)
usr.SetupProperty(Function(u) u.IsApproved)
_membershipService.Setup(Function(m) m.GetUser(It.IsAny(Of String), It.IsAny(Of Boolean))).Returns(usr.Object)
for
Dim usr As New Mock(Of MembershipUser)
usr.SetupProperty(Function(u) u.IsApproved)
Dim usrObj = usr.Object
_membershipService.Setup(Function(m) m.GetUser(It.IsAny(Of String), It.IsAny(Of Boolean))).Returns(usrObj)
and then can replace
usr.VerifySet(Function(u) InlineAssignHelper(u.IsApproved, True))
with the more straightforward
Assert.IsTrue(usrOb.IsApproved)
Sometimes I just don't see the simple solution :)
You want to use the following (from http://code.google.com/p/moq/wiki/QuickStart):
// or verify the setter directly
mock.VerifySet(foo => foo.Name = "foo");
Right now the thing that you're feeding in is a comparison rather than an assignment, so even if Moq did process the statement without an exception, it would still not be Doing What You Mean.
Well this may be a little late, but I was facing the same problem and the solution was way simpler then using a InlineAssignHelper method.
Just change the Function to a Sub and it should work.
So try this instead:
usr.VerifySet(Sub(u) u.IsApproved = True)