I have created an Interface called IClientModule in a class libarary and
have compiled the library to a .dll.
In my main app, I scan a folder for .dll's and load each one that
implements the interface. For each one that is loaded, it is stored in a
collection object which is an instance of a typed collection class called
ModuleCollectio n.
In the code, I want to iterate through the collection so I tried this code:
For Each oMod As IClientModule In m_Modules
...
Next
When it gets to that line of code, it pukes with an "Specified Cast is
Invalid" on the For Each line.
Yet if I change the code to this:
Dim oMod As IClientModule
For x As Integer = 0 To m_Modules.Count - 1
oMod = m_Modules(x)
oMod.Initialize Plugin(AppConte xt)
Next
It works!?!?! What gives? Why would it fail with For Each?
--
Chris
dunawayc[AT]sbcglobal_lunch meat_[DOT]net
To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address. 9 1034
Hi Chris,
You could try using an ArrayList instead of a type collection and convert
the array list to a typed array at the last minute.
For example:
For Each oMod As IClientModule In m_Modules.ToArr ay(GetType(ICli entModule))
...
Next
Phil Harvey
-------------------- http://spaces.msn.com/members/dotnetspace
On Fri, 3 Dec 2004 17:56:56 -0000, Phil Harvey wrote: Hi Chris, You could try using an ArrayList instead of a type collection and convert the array list to a typed array at the last minute. For example:
For Each oMod As IClientModule In m_Modules.ToArr ay(GetType(ICli entModule)) ... Next
Phil Harvey
-------------------- http://spaces.msn.com/members/dotnetspace
The problem is that on the For Each line, it throws the "Specified Cast Is
Invalid" error. Why does for each do this when a regular for loop does
not?
--
Chris
dunawayc[AT]sbcglobal_lunch meat_[DOT]net
To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
Are you inheriting your collection from an existing one are have you
implemented IEnumerable/IEnumerator? I had a go with the
IEnumerable/IEnumerator implementations and in that case, 'for each' worked
fine even with an interface variable. Looks like the Current() method of the
IEnumerator is returning an object that doesn't implement
IClientModule.. .seems like the most obvious reason for an invalid cast but
I'm not sure how this would apply in the case where you have inherited from
an exisiting collection. Could you provide a little more detail about your
collection class?
Imran.
"Chris Dunaway" <"dunawayc[[at]_lunchmeat_sbcg lobal[dot]]net"> wrote in
message news:1h******** *************** ******@40tude.n et... On Fri, 3 Dec 2004 17:56:56 -0000, Phil Harvey wrote:
Hi Chris, You could try using an ArrayList instead of a type collection and
convert the array list to a typed array at the last minute. For example:
For Each oMod As IClientModule In
m_Modules.ToArr ay(GetType(ICli entModule)) ... Next
Phil Harvey
-------------------- http://spaces.msn.com/members/dotnetspace
The problem is that on the For Each line, it throws the "Specified Cast Is Invalid" error. Why does for each do this when a regular for loop does not?
-- Chris
dunawayc[AT]sbcglobal_lunch meat_[DOT]net
To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and replace certain words in my E-Mail address.
On Fri, 3 Dec 2004 17:10:21 -0500, Imran Koradia wrote: Are you inheriting your collection from an existing one are have you implemented IEnumerable/IEnumerator? I had a go with the IEnumerable/IEnumerator implementations and in that case, 'for each' worked
I didn't create my collection class from scratch, I inherited from
DictionaryBase and overrode the Add, Insert, etc.
I guess in that case, Im relying on the base class enumerator. You think
that could be causing the problem?
--
Chris
dunawayc[AT]sbcglobal_lunch meat_[DOT]net
To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
Not sure if I fully understood your scenario, but unless your interface is defined in a single dll that your other dll's then reference and use, instances from
different assemblies (dlls) will be considered different, and casts will fail.
In .Net, a type is identified not only by its name, but also by the assembly it was defined in.
To work, you need:
MainDll
defines IClientModule
dll1
references IClientModule, has class that implements it
dll2
references IClientModule, has another class that implements it
dll3
...
mainexe
references maindll
dynamically loads dll1-dll3, and searches for types that implement IClientModule
code: dim x as IClientModule = assembly1.creat einstance("Clas sthatimplements ClientModule")
Hope that helps
Alex
-------------------- From: Chris Dunaway <"dunawayc[[at]_lunchmeat_sbcg lobal[dot]]net"> Subject: Interface question User-Agent: 40tude_Dialog/2.0.10.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Date: Fri, 3 Dec 2004 09:54:45 -0600 Message-ID: <1r************ *************** *@40tude.net> Newsgroups: microsoft.publi c.dotnet.langua ges.vb NNTP-Posting-Host: 216.143.212.98 Lines: 1 Path: cpmsftngxa10.ph x.gbl!TK2MSFTFE ED02.phx.gbl!TK 2MSFTNGP08.phx. gbl!TK2MSFTNGP1 1.phx.gbl Xref: cpmsftngxa10.ph x.gbl microsoft.publi c.dotnet.langua ges.vb:246691 X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.vb
I have created an Interface called IClientModule in a class libarary and have compiled the library to a .dll.
In my main app, I scan a folder for .dll's and load each one that implements the interface. For each one that is loaded, it is stored in a collection object which is an instance of a typed collection class called ModuleCollecti on.
In the code, I want to iterate through the collection so I tried this code:
For Each oMod As IClientModule In m_Modules ... Next
When it gets to that line of code, it pukes with an "Specified Cast is Invalid" on the For Each line.
Yet if I change the code to this:
Dim oMod As IClientModule For x As Integer = 0 To m_Modules.Count - 1 oMod = m_Modules(x) oMod.Initialize Plugin(AppConte xt) Next
It works!?!?! What gives? Why would it fail with For Each?
-- Chris
dunawayc[AT]sbcglobal_lunch meat_[DOT]net
To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and replace certain words in my E-Mail address.
Sorry I don't take feature request for WinRes: it belongs to the .NET Framework SDK. I'm a consumer of WinRes, just like you...
--------------------From: Thomas Adams <th************ @gmail.com> Newsgroups: microsoft.publi c.dotnet.intern ationalization Subject: RE: How to launch WinRes in full screen mode by another program? Date: 29 Sep 2004 19:31:46 GMT Organization : DFN.CIS Senior Customer Lines: 17 Message-ID: <Xn************ *************** *******@127.0.0 .1> References: <2q************ @uni-berlin.de> <r3************ **@cpmsftngxa06 .phx.gbl> X-Trace: news.uni-berlin.de cGk7xWd2iWxkO9H VbF7isQODBzMeOP RUidb0ZHc/H3nGY= User-Agent: Xnews/06.08.25 X-Converter: MorVer Version 1.0.305 Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG XA03.phx.gbl!TK 2MSFTNGP08.phx. gbl!newsfeed00. sul.t-online.de!newsf eed01.sul.t-online.de!t-online.de!fu-
berlin.de!uni-berlin.de!not-for-mailXref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.intern ationalization: 947 X-Tomcat-NG: microsoft.publi c.dotnet.intern ationalization
Hi
Your assumption is correct. I did not want to call out its long name since I didn't know if that could be regarded as breach of NDA. :)
Thanks for the explanation. Do you take feature requests for WinRes? I'd like to see a "remember last size and location" some day...
~T.
xu*@online.mic rosoft.com (Xu Yang[MSFT]) wrote:
--
[Formerly appended fullquote was nuked by morver, the versatile morphing server.]
I'm afraid that LocStudio (when you say LS, I assume you are using LocStudio) does not have the option, and WinRes does not remember its size and
location when it was shut down.
If you are trying to call it in your own application, you can always use ProcessWindowSt yle.Maximized when you start the process.
--------------------From: Thomas Adams <me*@privacy.ne t> Newsgroups: microsoft.publi c.dotnet.intern ationalization Subject: How to launch WinRes in full screen mode by another program? Date: 11 Sep 2004 21:26:17 GMT Organization : DFN.CIS Senior Customer Lines: 9 Message-ID: <2q************ @uni-berlin.de> X-Trace: news.uni-berlin.de 9sj2ViefNkwlw4t mA89WfA6mie8fmr CfbXqlIJqRehUb0 = User-Agent: Xnews/06.08.25 X-Face: #Rk@TOQ|^!ZG|&z 6lA@-CY>/xB[Ei1mG*&S.+A5z;N g?3OxX[#DVZw!"o!c`S|p: (zsX-EkdZZ(IVnFRTX%! :Sv^L&Gk~s]vJ@Z~%Rm@G]fr*r2P}u5
*&k/-_2+&Qowj6hiJ1b$ ^JQf:uy9456HIdK q*B`NC##kyO,>7" Ztnav+=71b*"E+D Ime;{i&)ii{#6e? i8P,1Xpc[q0}i:Tm];B1X-Converter: MorVer Version 1.0.305 Path: cpmsftngxa10.ph x.gbl!TK2MSFTFE ED01.phx.gbl!TK 2MSFTNGP08.phx. gbl!newsfeed00. sul.t-online.de!newsf eed01.sul.t-online.de!t-online.de!fu-
berlin.de!uni-berlin.de!not-for-mailXref: cpmsftngxa10.ph x.gbl microsoft.publi c.dotnet.intern ationalization: 902 X-Tomcat-NG: microsoft.publi c.dotnet.intern ationalization
Hi
Let's imagine you're using a translation environment (LS) that's launching WinRes every now and then. Is it possible to open WinRes in full screen mode in this case? It's quite annoying that it doesn't remember if I switch it to full screen mode the next time it is invoked.
thanks, Thomas
On 2004-12-03, Chris Dunaway <> wrote: On Fri, 3 Dec 2004 17:10:21 -0500, Imran Koradia wrote:
Are you inheriting your collection from an existing one are have you implemented IEnumerable/IEnumerator? I had a go with the IEnumerable/IEnumerator implementations and in that case, 'for each' worked I didn't create my collection class from scratch, I inherited from DictionaryBase and overrode the Add, Insert, etc.
^^^^^^^^^^^^^^ I guess in that case, Im relying on the base class enumerator. You think that could be causing the problem?
Why DictionaryBase? Assuming you inherited in a ordinary way...
For Each obj In m_modules
is going to return a DictionaryKey object that contains the key/value
pair, while
m_modules(i)
will return the actual object you inserted with the key of 'i'.
That's why you have this situation. You seem to want a simple indexed
collection here rather than key/value pairs, so I would guess that you
really want CollectionBase rather than DictionaryBase.
Chris, I didn't create my collection class from scratch, I inherited from DictionaryBase and overrode the Add, Insert, etc.
Ah! There's the rub.
When you use a For Each on a DictionaryBase you need to use a
DictionaryEntry for the item as it returns both the key & the value.
Change your For Each to be something like:
For Each de As DictionaryEntry In m_Modules
Dim oMod As IClientModule = DirectCast(de.V alue, IClientModule)
...
Next
As David, suggests you may want to consider using a CollectionBase instead
of a DictionaryBase. I would also consider using a
System.Collecti ons.Specialized .NameObjectColl ectionBase instead of either of
the other two...
Hope this helps
Jay
"Chris Dunaway" <"dunawayc[[at]_lunchmeat_sbcg lobal[dot]]net"> wrote in
message news:p6******** *************** *****@40tude.ne t... On Fri, 3 Dec 2004 17:10:21 -0500, Imran Koradia wrote:
Are you inheriting your collection from an existing one are have you implemented IEnumerable/IEnumerator? I had a go with the IEnumerable/IEnumerator implementations and in that case, 'for each' worked
I didn't create my collection class from scratch, I inherited from DictionaryBase and overrode the Add, Insert, etc.
I guess in that case, Im relying on the base class enumerator. You think that could be causing the problem?
-- Chris
dunawayc[AT]sbcglobal_lunch meat_[DOT]net
To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and replace certain words in my E-Mail address.
On Fri, 3 Dec 2004 09:54:45 -0600, Chris Dunaway wrote:
Thanks, All, for the help.
--
Chris
dunawayc[AT]sbcglobal_lunch meat_[DOT]net
To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
On Sat, 4 Dec 2004 11:38:11 -0600, Jay B. Harlow [MVP - Outlook] wrote: When you use a For Each on a DictionaryBase you need to use a DictionaryEntry for the item as it returns both the key & the value.
Thanks, David, Jay, I knew this, I don't know why my brain was not working
in this instance!! I guess it needs a service pack!
--
Chris
dunawayc[AT]sbcglobal_lunch meat_[DOT]net
To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: perseus |
last post by:
I think that everyone who told me that my question is irrelevant,
in particular Mr. David White,
is being absolutely ridiculous. Obviously, most of you up here
behave like the owners of the C++ language. A C++ interface
installation IS ABOUT THE C++ LANGUAGE! The language
does not possess the ability to handle even simple file directory
manipulation.
Those wise people that created it did not take care of it. So, BOOST
is a portable...
|
by: Marius Horak |
last post by:
As in subject.
Thanks
MH
|
by: jm |
last post by:
Consider:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbconwhenshouldiimplementinterfacesinmycomponent.asp
// Code for the IAccount interface module.
public interface IAccount
{
void PostInterest();
void DeductFees(IFeeSchedule feeSchedule);
}
|
by: Ole Hanson |
last post by:
I am accessing my database through an interface, to allow future
substitution of the physical datastore - hence I would like to declare in my
Interface that my DAL-objects implementing the interface and accessing the
datastore MUST pass in a UserToken in the constructor of the object.
Is this not possible?
Am I forced to add the UserToken as a property on the object instead?
/Ole
|
by: John Salerno |
last post by:
Hi all. I have a question about interfaces now. According to the book
I'm reading, when you implement an interface, the class or structure
has to declare all the methods that the interface includes.
My question is, if you must declare each method (as opposed to simply
'using' those methods like an #included file), then why not just
declare the methods on your own as if you created them yourself? What
advantage does using an interface...
| |
by: John Salerno |
last post by:
I understand how they work (basically), but I think maybe the examples
I'm reading are too elementary to really show their value. Here's one
from Programming C#:
#region Using directives
using System;
using System.Collections.Generic;
using System.Text;
|
by: Joe |
last post by:
My question is more an OOD question. I know *how* to implement both abstract
classes and interfaces. Here's my question - under what circumstacnes does
one use an abstract class and under what circumstacnes does one implement an
interface?
TIA,
--
Joe
VBA Automation/VB/C++/Web and DB development
|
by: Ray Dukes |
last post by:
What I am looking to do is map the implementation of interface
properties and functions to an inherited method of the base class.
Please see below.
'****************************************************************************
' Issues
'****************************************************************************
|
by: Colin McGuire |
last post by:
Hi all, when I write the class below
Private Class employee
End Class
and then add the line "Implements IVF" which is an interface I have
written, the IDE modifies my code to display
|
by: Ben Voigt [C++ MVP] |
last post by:
I get
C:\Programming\LTM\devtools\UselessJunkForDissassembly\Class1.cs(360,27):
error CS0535: 'UselessJunkForDissassembly.InvocableInternals' does not
implement interface member
'UselessJunkForDissassembly.IInvocableInternals.OperationValidate(string)'
C:\Programming\LTM\devtools\UselessJunkForDissassembly\Class1.cs(360,27):
error CS0535: 'UselessJunkForDissassembly.InvocableInternals' does not
implement interface member...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |