-
Hi Marko,
I solved your problem...
I told you before. In OptySistem (in the exe) you should not include ComponentLibrary1 with the using keyword because it compiles it again and it consideres that they are different classes (or interfaces). Instead using only the reference and using everywhere Project.interface. In your code it was converting to ComponentLibrary1.ILayoutComponent and than you were trying to convert it implicitly to an ILayoutComponent.
So do like this:
exclude the line "using ComponentLibrary1;"
and change the line
"ILayoutComponent lc = (ComponentLibrary1.ILayoutComponent)obj;"
with
"ComponentLibrary1.ILayoutComponent lc = (ComponentLibrary1.ILayoutComponent)obj;"
Best regards,
Robi
-
Sorry, no luck again
Robi, thanks man, you've been spending a lot of time on this, but unfortunately still, after making the changes as you suggested, it still doesn't work for me. Can you send me a zip with my solution that you modified to work. Maybe I'm missing something.
I removed the using directive, and am using namespace.interface exactly as you specified in your post. Still the freakin' invalid cast :mad: .
Again, if you can post the modified working solution, I'd very much appreciate it.
Cheers,
Marko
-
Hi again Marko,
Don't worry I hadn't spent a lot of time... :)
Here is what was wrong:
In my last post I omited to tell you something. I was not able to build your solution because (at least I think that is the cause) I have .Net Beta 2 and it was telling me that can't use System.Byte (even thou it wasn't use in the project) and that I should reinstall the .Net. So I just compiled the library (it worked) and then copied the dll in the same directory with the form1.cs for a easier path and compiled the exe manually :
csc /target:exe Form1.cs /r:ComponentLibrary1.dll
and it worked.
Now, today when i read your post I was intrigued why on your computer it does not work and I made a solution (exactly like yours - I had to make anouther one because of the "Byte problem") and indeed it didn't work ;) - famous InvalidCast Exception.
So here is what happens:
We have built the library, so under \componentlibrary\debug we have the dll. Then we build the exe. If at the reference properties there is the setting to make a local copy, it copies the dll, this time in the \opti\debug directory, where the exe is. However when you compile with the command line csc, if the directory is not the same, it does not make a copy.
Anyway the thing is that when you use the name of a class or of an interface, in your exe or in your dlls, he expects to find the dll in the directory where the exe lies (probably some other win/Net directories too).
So try using asm = Assembly.LoadFrom("ComponentLibrary1.dll");
But if you want to have the dlls in another directory I think that a good practice, would be to create a dll with all the interfaces and this dll will be in the same directory as the exe, and then all the dlls and the exe to be compiled with a reference to this dll.
Hope my post wasn't very boring and I really hope it helps ;)
By the way if I am wrong with anything that I have said, I would be happy if anyone corrects me.
Good luck,
Robi