strongly typed data set throws CastException - vb.net

When I run this code:
'Dim Tab As ActDS.ACTDataImportDataTable = CType(Session("WorkData"), ActDS).ACTDataImport'
I get this error:
'System.InvalidCastException was unhandled by user code. Message=Unable to cast object of type 'ACTDataImportDataTable' to type 'ActDS'.'
'ActDS' is a strongly type data set and 'ACTDataImportDataTable' is a member of the data set.
What am I doing wrong?
Red.

Judging from the error message Session("WorkData") already is of type ActDS.ACTDataImportDataTable. It looks like the line should just be:
Dim Tab As ActDS.ACTDataImportDataTable =
CType(Session("WorkData"), ActDS.ACTDataImportDataTable)

Related

How to fix 'The string was not recognized as a valid DateTime.' error in BizTalk Test map?

I'm working on a BizTalk orchestrations with a map which contains an XSLT script. When I launch the orchestration I got this error
Error encountered while executing the transform. Error: Unable to create the transform.
So I go back to the map
XSL transform error:
Unable to write output instance. Exception has been thrown by the target of an invocation. The string was not recognized as a valid DateTime. There is an unknown word starting at index 0.
I already tried to do a ParseExact but got the same error
Here is my code to convert DateTime:
public string FormatDate(string inputDate)
{
System.DateTime date = System.DateTime.Parse(inputDate);
return date.ToString("yyyy-MM-dd");
}
...and the code I tried with ParseExact:
public string FormatDate(string inputDate)
{
System.Globalization.CultureInfo culture = System.Globalization.CultureInfo.InvariantCulture;
System.DateTime date = System.DateTime.ParseExact(inputDate, "yyyyMMdd", culture);
return date.ToString("yyyy-MM-dd");
}
The expected result is to have the date with "yyyy-MM-dd" format.
The problem came from several scripting functoid with the same method name inside. Just gave each methods a different name and the errors has gone.
Thank you to all users for your time.

Populate picture box from eID vb.net

Hi i got form that reads eID card, smart cards
text data reads correctly
picturebox name is picLK
but last statement is a picture
in VB6 and VBA I used
me.pctLK.Picture = ReaderEngine.portrait
ReaderEngine is procedure that reads data from card
when I use command in vb.net I get an error
me.pctLK = ReaderEngine.portrait
reader is reading card, but I got this message
An unhandled exception of type 'System.InvalidCastException' occurred in Project1.exe
Additional information: Unable to cast COM object of type 'stdole.StdPictureClass' to class type 'System.Windows.Forms.PictureBox'. Instances of types that represent COM components cannot be cast to types that do not represent COM components; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface.
I am new to VB .net
Is there any suggestions?
VB.NET has a helper function in the Microsoft.VisualBasic.Compatibility.VB6.Support module, named IPictureDispToImage, which accepts an StdPictureClass object (which implements IPictureDisp) and returns a .NET System.Drawing.Image object which you can assign to the PictureBox.Image property. Be sure you appropriately dispose of the Image when you're finished with it:
Dim comImage As StdOle.StdPictureClass = ReaderEngine.portrait
If Me.picLK.Image Is Not Nothing Then
Me.picLK.Image.Dispose()
Me.picLK.Image = Nothing
End If
Dim newImage As System.Drawing.Image = Support.IPictureDispToImage( comImage )
Me.picLK.Image = newImage

How do I get the Kind of Elements in an Array using Roslyn

I am trying to get the Type that is iterated through using Roslyn. I can get the fact that the object is defined as String() using
Dim ElementTypeInfo As TypeInfo = SemanticModel.GetTypeInfo(ForEachStatement.Expression)
Dim expressionType As ITypeSymbol = ElementTypeInfo.Type
and in the Visual Studio debugger I can look at expressionType.ElementType and find out it is a String. But when I try to access ElementType in code I get an error saying the ElementType is not a member of ITypeSymbol.
If you know that expressionType is going to be an array, you can cast it to IArrayTypeSymbol. After that, you will be able to access its ElementType:
Dim expressionType = DirectCast(elementTypeInfo.Type, IArrayTypeSymbol)
Dim elementType As ITypeSymbol = expressionType.ElementType

Disable an Exchange 2010 mailbox using VB.Net

I'm trying to disable a mailbox in Exchange 2010 using VB.Net.
Dim rsConfig As RunspaceConfiguration
rsConfig = RunspaceConfiguration.Create()
Dim snapInException As PSSnapInException = Nothing
Dim info As PSSnapInInfo = rsConfig.AddPSSnapIn("microsoft.exchange.management.powershell.e2010", snapInException)
Dim myRunSpace As Runspace
myRunSpace = RunspaceFactory.CreateRunspace(rsConfig)
myRunSpace.Open()
Dim pipeLine As Pipeline
pipeLine = myRunSpace.CreatePipeline()
Dim sScript As String = "disable-mailbox -Identity 'Bill Smith' -Confirm:$false"
pipeLine.Commands.AddScript(sScript)
pipeLine.Invoke()
pipeLine.Dispose()
I get this error:
System.Management.Automation.CmdletInvocationException was unhandled
Message=Value cannot be null.
Parameter name: serverSettings
Source=System.Management.Automation
WasThrownFromThrowStatement=False
StackTrace:
at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input, Hashtable errorResults, Boolean enumerate)
at System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput, CommandParameterInternal[][] pipeElements, CommandBaseAst[] pipeElementAsts, CommandRedirection[][] commandRedirections, FunctionContext funcContext)
at System.Management.Automation.Interpreter.ActionCallInstruction`6.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
InnerException: System.ArgumentNullException
Message=Value cannot be null.
Parameter name: serverSettings
ParamName=serverSettings
Source=Microsoft.Exchange.Configuration.ObjectModel
StackTrace:
at Microsoft.Exchange.Configuration.Tasks.TaskVerboseStringHelper.GetADServerSettings(String cmdletName, ADServerSettings serverSettings)
at Microsoft.Exchange.Configuration.Tasks.TaskVerboseStringHelper.GetADServerSettings(ADServerSettings serverSettings)
at Microsoft.Exchange.Configuration.Tasks.Task.LogCmdletIterationEvent()
at Microsoft.Exchange.Configuration.Tasks.Task.BeginProcessing()
at System.Management.Automation.Cmdlet.DoBeginProcessing()
at System.Management.Automation.CommandProcessorBase.DoBegin()
InnerException:
Can anyone help?
Thanks in Advance.
This is the important part of the error:
Message=Value cannot be null. Parameter name: serverSetting
Stack traces can be tricky to read, but the first impression is that you're passing a null/Nothing value to a function that wants an instance of something.
I'm not familiar with the Exchange objects and you didn't share which line throws the error, but my best guess reading through the code is this line throws the error:
myRunSpace = RunspaceFactory.CreateRunspace(rsConfig)
And you can fix it by changing this line near the top:
Dim rsConfig As RunspaceConfiguration
to this:
Dim rsConfig As New RunspaceConfiguration
Unfortunately, I suspect that this will only help you spot the next error. I expect there is a reason you need to pass a configuration object to that method, and the default instance may not be good enough.

VB.NET Deserialize JSON to anonymous object using newtonsoft returned error

I would like to deserialize the returned JSON from a service call in VB.NET to an anonymous type but I was having error. It works in C# using dynamic type but i dont know how to do it in VB.
Here is my JSON returned from a web service call:
{"format":"png","height":564,"width":864}
Here is my VB code json above assigned to param text:
Dim testObj = Newtonsoft.Json.JsonConvert.DeserializeObject(text)
But when i tried to access testObj.format, an exception was thrown with message
{"Public member 'format' on type 'JObject' not found."}
I already have added Option Strict Off. I dont want to use an Object/Class to deserialize the JSON. If its in C# assigning this to dynamic type will be working fine.
Can anyone please help? I am not expert in VB but I need to have this running on VB. TIA
Dim js As New System.Web.Script.Serialization.JavaScriptSerializer
Dim testObj = js.Deserialize(source, New Object().GetType())
Then you can access the key(attribute name)/values via:
value=testobj(key)
One more thing, you can access your Newtonsoft key(attribute name)/values through:
value=testObj.item(key)
Dim js As New System.Web.Script.Serialization.JavaScriptSerializer
Dim DeSerialObjEventData = New With {.Prop1 = String.Empty, .Prop2 = String.Empty, .Prop3 = String.Empty}...
Dim testObj = js.DeserializeAnnonomusType(source, DeSerialObjEventData)