.net - Casting Interfaces And MEF?
Mar 13, 2009
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?
View 1 Replies
ADVERTISEMENT
Nov 14, 2010
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?
View 2 Replies
Oct 16, 2009
Are Interfaces used often? Need opinions.
View 4 Replies
Dec 30, 2011
In this discussion let us discuss every usage of interfaces in .NET. Any real time examples and difficulties in using interfaces can also be discussed here.
View 6 Replies
Aug 6, 2009
Im building a game with VB.NET I designed the core of the game in form1 window But now I need menus. How can I implement this without having 5 or so windows that I show() and hide() ? Doing that slows it down a lot and uses lots of memory. I tried tabs, but I don't want the tabs to appear, just switch. Whats the best way to implement multiple interfaces?
View 1 Replies
Jul 14, 2011
Has someone a hint what I'm doing wrong in VB.Net?
Module Module1
Interface ISearch(Of T As ISearchResult)
Function ids() As List(Of T)
End Interface
[CODE]...
The third cast isn't working. Why? did I miss a oop lesson?
View 2 Replies
Sep 12, 2009
What I would like to do is make an abstract class that will hold objects in a dictionary and manage the adding/deleting/key changes of those items in the dictionary. My problem is that in order to make the class as generic as possible I declared the dictionary as dictionary(of long, of SomeInterface).The problem is when I try to pass a strongly typed dictionary in the constructor using dictionary( of long, ClassThatImplementsSomeInterface) I get a compiler error because it cannot convert to that type.
The reason I want to pass the dictionary in the abstract class's constructor is so that I can use the strongly typed dictionary in the subclass and have the abstract class manage the keys when it needs to. So how can I do something like this? Also- If there is a much better way to manage keys than what I am doing feel free to let me know, but I am much more interested in how to make this work since I have encountered this type of problem a few times before.
Here's the abstract class:
Public MustInherit Class HasChildrenKeys
Protected m_childItems As Dictionary(Of Long, IHasKey)
[code].....
View 7 Replies
Dec 9, 2009
The next code works fine in C#:
[Code]...
But this code crash with a OverflowException in VB.Net.
[Code]...
Both codes seems the same to me. What is the difference and how can I get the C# code converted to VB.Net?
View 6 Replies
Aug 19, 2011
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
[code]...
View 2 Replies
Oct 16, 2009
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'.
View 20 Replies
Mar 1, 2009
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
[code]...
View 1 Replies
Oct 20, 2011
I have a solution with multiple projects, some of the projects are written in VB, some in C#. I am wondering if there's a way to use interfaces and/or enums written in VB in C# classes? My C# code below doesn't compile, however I am able to see the interface in intellisense.
[Code]...
P.S It's a console/service application, not ASP.Net (where I know it's doable).UPD: Sorry guys, was missing a reference to the project with the interface. It's fixed now. I think the thing that in VB projects references are done slightly different than in C# confused me.
View 2 Replies
May 1, 2009
I have a program written in Visual Studio to me 3 values ( 0-255, 0-255, 0-255) to send the serial interfaces, and While assigned to the 3 values of 3 sliders together.[code...]
View 1 Replies
Oct 4, 2011
I have a project that has several different interfaces (a website, a local application, and some webservices), that all use the same class library. The library is an API to a database. Some settings, like log level, database connection etc, i want to store in a single place, and I want them editable. What is the best way to accomplish this? I am concerned both about ease of editing, and ease of access for the dll, as there will be a lot of calls to it and a lot of lookups for the values. I have considered using app.config, a standalone XML file, and writing values to the registry, but I cannot find any good comparisons.
View 2 Replies
Dec 8, 2009
I have three classes which implement an Interface iComparesWith, and I wish there to be a single function such that each iComparesWith object of any of the three implementing classes should be able to compare itself with any other iComparesWith object, again, of any of the three implementing classes, and know if the two objects are equal. How can I code this so that the comparison code is only written once? Is it the case that I will have to create a top-level MustInherit class which implements the equality comparison, and have MustOverride methods for all of the methods of iComparesWith?
View 1 Replies
Jul 5, 2010
I am working on creating a customized UI composite control. This control would be a container to several other custom controls.As a first step, i am creating the container UI using a singleton pattern. This is because at any point in time only one isntance of this container is allowed to be created. This is fine.Now i want to practice interface based desgin. So i introduced a sinple interface calleD IdesignSurface which has two properties. I would like my singleton class to implement this interface,so i tried something like this and got an error saying "end of line
NotInheritable
Class DesignSurface
implements IDesignSurface
[code]......
View 2 Replies
Aug 25, 2011
I am a VB programmer of some 13 years. I started briefly with VB5 back in the mid-to-late 1990s, but then quickly moved to VB6 which I did for several years on PCs and HPCs (CE 1.x devices).I have done .NET 2002, 2003, 2005, and 2008 each for stints, intermingled with VB6 coding, at various jobs. But, I never got formally trained on VB.NET. In fact, I taught myself VB5/6 too. I have a degree in Computer Science and Mathematics, but the university CS program only had Unix systems. I basically learned everything I know on the fly from various Microsoft Press and other company's books (and the MS website/MSDN CDs too) while doing projects.I was wondering what everyone would suggest to really learn the .NET workings and why they are setup like that for Windows client/server applications. It doesn't have to be technical and brain-numbing.I have recently run into things dealing with MSFlexGrid vs DataGridView and how they link/work with database sources that confounds me. And, I am assuming there's just something I don't know about how/why VB.NET works the way it does...and I want to learn it to become a better developer.I want kind of that fun book that's easy to read, is thorough in that it teaches you a wide range of how to use/implement .NET controls/interfaces, and will fill in the gaps in my knowledge and experience.
View 1 Replies
Apr 21, 2010
When I pass an an object 'MyObject' which implements 'IMyInterface' to a method parameter declared as IMyInterface, I understand that this method parameter 'sees MyObject through the eyes of its interface'.
View 2 Replies
May 8, 2010
Can we call firewall an interface?
View 1 Replies
Nov 3, 2010
I have an interface called IBaselineControl. Now I'm trying to write a procedure which requires, as an argument, a Control which implements the IBaselineControl interface. However, I don't know the syntax for this. VB.Net allows us to require multiple interface implementations along with class inheritance when writing constraints for generic types. The syntax used there suggests that something like this might work:Public Sub Test(X As {Control, IBaselineControl})Unfortunately, that syntax doesn't work and I'm unable to find any syntax which does.
View 6 Replies
Mar 13, 2011
Is is possible to implement a type specifier with 2 interfaces in .net? Something like:
Public Sub New(obj as ICollection and INotifyCollectionChanged)
''Initialize Code
End Sub
View 2 Replies
Apr 22, 2011
I have a Delphi written DLL that exposes some interfaces to a vb.net application.
The interfaces inherit from IUnknown (but this could be changed if required), simplified example:
IWindow = interface(IUnknown)
['{E9A11D0B-8A05-4CBA-83FA-C5CC6818DF6E}']
function GetCaption(var Caption: PChar): HRESULT; stdcall;
end;
[Code]....
Now I want to transfer a collection of IWindow to vb.net, and in the vb.net application I want to be able to loop through it with a for in loop.
I read that it's possible using IEnumerable/IEnumerator but I don't quite understand how to implement them. Are there any good tutorials about this, specifically showing the declarations on both side? Example code would be great.
Please note that I prefer not create a com dll that should be registered and imported. Currently I export a function that enabled me to obtain an interface.
View 1 Replies
Oct 17, 2011
how to do something that seems that it should be simple.
I tried it on a larger project I'm working on and got an error, so I reduced it to the simplest possible that I could find:
Public Interface IF1
Event WakeUp(ByVal TheObject As Object)
End Interface
[Code]....
View 3 Replies
Apr 9, 2009
I just started playing around with interfaces recently and I have a couple things I want to ask. First off I always understood that an Interface cannot contain code, you are merely creating almost a "template" of methods, property's etc...Lets say I have this:
Public Class MyTest
Implements IMyTest
Public Sub iDispose() Implements IMyTest.iDispose
[code].....
View 3 Replies
Jan 8, 2010
I have the following code compiles without issue. Of course, I get an invalid cast xception when executing the Dim C As IDoThingsC = GetThing_C(). Am I missing something?Would you ever want to return an object that does not meet the interface requirement for a function return value?
Public Class ClassA
Public Sub DoThings_A()
Debug.Print("Doing A things...")
[code].....
View 3 Replies
Jan 19, 2010
is there any reason why we couldn't add/extend an interface to an already existing class?
i believe this would be v useful. it would be like drawing links from my class to already existing classes, and drawing links from already existing classes to already existing classes
View 8 Replies
Apr 20, 2010
Public Function CastToT(Of T)(ByVal GenericType(Of Object) data) As GenericType(Of T)Return DirectCast(data, GenericType(Of T))End Function
The above clearly does not work. Is there any way to perform this cast if I know that all objects inside data are in fact of Type T?
View 2 Replies
Jan 12, 2011
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?
View 2 Replies
Mar 11, 2011
I am passing Date Field to SQL Database. Field is declared as String in the VB.Net Application. I wrote a piece of code for casting to Date
[Code]...
View 2 Replies
Apr 14, 2009
I'm a C# programmer who is forced to use VB (eh!!!!). I want to check multiple controls state in one method, in C# this would be accomplished like so:
if (((CheckBox)sender).Checked == true)
{
// Do something...
[code]...
View 4 Replies