I have the following problem with MEF: Interface definition to be used by host:
Public Interface IExecuteDoSomething Inherits IAddinSettings Event DataReceived As EventHandler(Of DataReceivedEventArgs) Function DoSomething() As Boolean End Interface
[Code]...
Everything seems to work fine until the Button2_Click routine is executed, then an InvalidCastException is thrown with the info:Unable to cast object of type 'System.Collections.Generic.List1[SharedLibrary.IExecuteDoSomething]' to type 'System.Collections.Generic.List1[SharedLibrary.IAddinSettings]'.
How can i solve this problem, because the imported object implements both of the interfaces?
I have a object type variable (control .Tag) that I need to cast to a structured type, and change a member in. This is a contrived but representative example
get around this. I have a data base field that is a decimal data type and I want to display it in a text box with the following txtWeekdayRate = CType(RoomsDataRow!WeekdayRate, TextBox)I get the following error when I run my program.Unable to cast object of type 'System.Decimal' to type 'System.Windows.Forms.TextBox'.
I am getting the followin error from my code. System.InvalidCastException was unhandled Message="Unable to cast object of type 'QADBASE.DMRDataLists' to type 'QADBASE.DMRData'." Source="QADBASE" I am getting the error in the code below on the createDMRIssue
I have an Entity class which Implements IWeightable:
Public Interface IWeightable Property WeightState As WeightState End Interface
I have a WeightCalculator class:
Public Class WeightsCalculator Public Sub New(...) .. End Sub
Why can I not do wc.Calculate(entities)? I receive:
Unable to cast object of type 'System.Collections.Generic.List1[mynameSpace.Entity]' to type 'System.Collections.Generic.IList1[myNamespace.IWeightable]'.
If Entity implements IWeightable why is this not possible?
I have tried everything to no avail. I need to cast the value from a user selected dropdownlist to another dropdownlist on another page. The data in the textboxes are a series of numbers. Also is there a way to display the value in the second dropdown list as well as other values? For example, my dropdown has the values 1-6, user selects 4, which displays first in the dropdown on page 2 but the other values also display in case they want to change there selection??
If Not Page.PreviousPage Is Nothing Then Dim table As Control = PreviousPage.Controls(0).FindControl("table1") Dim ddl As DropDownList = CType(table.FindControl("ddlB_Codes"),c DropDownList)
I'm trying to obfuscate some VB.NET 2003 app.The resulting assemblyes are obfuscated and "run" with some errors.I cleaned all potential reflection problems, but I'm not being able to read the selected value of a combobox.
I load the Combobox using their Datasource properties, using a collection of "VTPair" (a class created by me with 2 properties: one of string type and other of object type to store the value)
This combobox handle pairs like "Male | M" or "Female | F".When trying to see what is selected, I use if mycombo1.SelectedValue = "M" then.This code, after obfuscation, throws me an exception that cannot cast type "XX" to string "M".
So, I changed the code to something more correct, explicitly casting the selected value to String:
if ctype(mycombo1.SelectedValue,string) = "M" then But the error is the same.Debugin my original code, the SelectedValue property is of type "Object" but it is a string.I tried using the ComboBox.SelectedItem property that is also an object but this time what is inside is of type "VTPair" (my own class) and then trying to access its "Value" property (which is of type Object) and trying to cast to string fails again.
Does anyone have an idea to "translate" this piece of code to work OK after Dotfucate it?
I have an object that inherits from an interface. I can create and return the following:
Dim o As IRequest o = New Request Return o
This works fine. Now I want to return a List(Of Requests), so I try the following:
Dim o As List(Of IRequest) o = New List(Of Request) Return o
The error below is being given on o = New List(Of Request)
System.Collections.Generic.List(Of MyObjects.Request)' cannot be converted to System.Collections.Generic.List(Of MyInterfaces.IRequest)'.Consider using 'System.Collections.Generic.IEnumerable(Of MyInterfaces.IRequest)'
Say I have a interface called IProperties and I have a collection called colMyProperties that is a collection of IProperties. Then I have an object called clsProperty that implements the IProperty interface. Now, in my code where I add objects to the colMyProperties collection I add a bunch of clsProperty objects. so far so good.
Now when I try to access an object in the collection I can only access properties and methods of the IProperties interface, not the clsProperty object. What am I doing wrong? Do I need to cast the object?
I usually avoid VB's built-in conversion functions (CStr, CDate, CBool, CInt, etc.) unless I need to do an actual conversion. If I'm just casting, say from an object to a string, I normally use either DirectCast or TryCast, under the assumption that CStr, etc., are doing some extra stuff I don't need. But sometimes the DirectCast syntax is a little cumbersome, as in the following example.[code]SqlDataReader.Item returns an Object, which needs to be cast to a String. CStr is easier to read, type, and explain (IMO). My question is, does it matter which one I use? Should I just go with CStr (and CDate and CBool, etc.) and not worry about the extra work I assume those functions are doing? Is there any other downside to using these functions?
i have the following code which walks through an Excel file and this works fine note that the following line does work well (folder is being set earlier in the code)
When I have many controls on a Form (i.e. Label, Button etc) that do almost the same thing, I often use one method to handle all the controls Click, MouseDown, MouseUp events.But to know which of the controls throwing the event and access the properties of that control I need to cast the "sender" object to the correct type.
The thing is that I always know which type it is, I don't really have to "TryCast", "DirectCast" and check if the operation returns true. I some times use CType as well.
Delegate Sub UpdateTextHandler(ByVal recbuffpass() As Integer)
Private Sub someSub() Dim f As frmMain = My.Application.OpenForms("frmMain") f.Invoke(New UpdateTextHandler(AddressOf f.UpdateTextMethod), New Object() {recbuf})
I've got a project called Service.Inside the project, i've got 2 windows classes.ClassA is the main windows class which opens up when I run the program.On ClassA, I've got a button which, when I click it, opens up ClassB which is the other windows class. Inside the button's eventhandler (click), I've got a string which contains the name of ClassB's class ie "ClassB". I will probably get this from a table. Is it possible to initiate the object ClassB without using if statments to check what the type of object is. In the code below, i've managed to create a o of type object, but i need to new it with the ClassB
vb.net Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
I have the following VB.NET code that I am using to sort a Data.DataTable by column count.
For Each dtTarget As Data.DataTable In _ From x In Target.Tables _ Where DirectCast(x, Data.DataTable).Rows.Count > 0 _ Order By DirectCast(x, Data.DataTable).Columns.Count ... Next
Is there a way to indicate that x is a Data.DataTable without having to DirectCast it each time it is referenced (twice in this case) in the LINQ query?
I wonder if this is not possible dim mystring as string="1" dim myint As Nullable(Of Integer) myint=0 myint=mystring It crashes on the last line why is that? mystring is already integer (1) , i dont have to cast using cint, i thought. option strict off- if this cause the problem
In C# you can use the implicit keyword to define an implicit user-defined type conversion operator.In VB.NET you can define a CType conversion operator that will explicitly convert a user-defined type into another type.Is there a way to declare an implicit conversion operator in VB.NET?
I'm trying to implement a grid based RPG style inventory (teaching myself by making a game keeps me focused ) and I have an array of "item" objects. Part of this array is a picture box, which I then lay out in code to display the inventory. how to detect when one of these picture boxes is clicked. However, I'm having a little trouble getting my head around the Directcast command.
When a box is clicked, I would like the function 'boardclicked' to pass over not only the picture box, but the whole object it is associated with it, so I can print these values out the screen (detailing the objects name, value etc) [Code]. As you can see, this passes the picture box element of the object, but I'd like to be able to pass the whole structure, so I can retrieve the other associated values.
When writing some Outlook code in VS2005, I came across a situation that, to me, does not make any sense. For reference, the version of Outlook running on this machine is Outlook 2003.The program I'm writing is designed to iterate through the emails in the inbox, to identify certain types of emails based on their subjects and bodies, and then to generate new emails based on the existing ones. However, the problem that I'm having is with simply iterating through the collection of items that comes from the Inbox folder. Specifically, what happens is that this line consistently fails on items that should be processed: