I have following vb.net code and i am getting syntax error in it
Update
Protected Sub OpenLogin_Click(ByVal src As Object, ByVal e As CommandEventArgs)
Dim StrUri As String = e.CommandArgument.ToString()
Dim openid As New OpenIdRelyingParty()
Dim b = New UriBuilder(Request.Url)
With Key
.Query = ""
End With
'var b = new UriBuilder(Request.Url) { Query = "" };
Dim req = openid.CreateRequest(StrUri)
Dim fetchRequest = New FetchRequest()
fetchRequest.Attributes.AddRequired(WellKnownAttributes.Contact.Email)
fetchRequest.Attributes.AddRequired(WellKnownAttributes.Name.First)
fetchRequest.Attributes.AddRequired(WellKnownAttributes.Name.Last)
req.AddExtension(fetchRequest)
req.RedirectToProvider()
End Sub
Now the error in code is “Key is Not declared” What should i do now for this
Two problems:
The
Keyreserved word is only to be used when identifying a multi-part key for grouping usingEnumerable.GroupBy. It is not required for setting object properties inline with their constructor.You are experiencing a problem whereby you have separated the
Withdecorator onto a new line, which is syntactically incorrect because you are now treating it as aWithblock, which means that every dot access will target the variable immediately following theWithstatement. You need to use a line continuation character or putWithon the same line as the object constructor:Ex 1
Ex 2
EDIT:
You cannot use this syntax with a Visual Studio 2005/.NET 2.0 project. Just construct the object then initialize the property: