specified case is not valid

  • Thread starter Thread starter Greg
  • Start date Start date
G

Greg

I have a class that's a project by itself within a project and I'm
referencing this class in a Windows Application as well as a Windows Service
that are both separate projects of the same solution. I'm able to use the
class just fine in the Window app, but the service returns the exception
"specified cast is not valid". For an additional test I created a brand new
solution and Windows app and that worked... it's just the service that isn't
working with it.

Is there any way to find out a more useful explanation for the problem? I
took a look through the exception in debug mode but didn't notice anything.
 
I am just guessing. Separate projects create separate assemblies. You
may
need to break out the common classes into a separate library.

In other words, if two assemblies contain the same class with the same
fully
qualified name, the runtime still sees the two classes as different
types. In a
sense, I conceptualize this as having the runtime "prepend" the assembly
"name" to the fully qualified class name. Got that? Check here for more
information about InvalidCastExceptions and plug ins, compliments of Jon
Skeet: http://www.yoda.arachsys.com/csharp/plugin.html

Regards,
Jeff
I have a class that's a project by itself within a project and I'm
referencing this class in a Windows Application as well as a Windows
Service
that are both separate projects of the same solution. I'm able to use
the
class just fine in the Window app, but the service returns the exception
"specified cast is not valid". For an additional test I created a brand
new
solution and Windows app and that worked... it's just the service that
isn't
working with it.<
 
Jeff Louie said:
I am just guessing. Separate projects create separate assemblies. You
may
need to break out the common classes into a separate library.

In other words, if two assemblies contain the same class with the same
fully
qualified name, the runtime still sees the two classes as different
types. In a
sense, I conceptualize this as having the runtime "prepend" the assembly
"name" to the fully qualified class name. Got that? Check here for more
information about InvalidCastExceptions and plug ins, compliments of Jon
Skeet: http://www.yoda.arachsys.com/csharp/plugin.html

Regards,
Jeff

I don't completely understand, but I did try changing the class name,
project name, and namespace to something else but still have the same
problem. I'm not sure where it would be getting two different ones since
it's a unique name and none of the references have referenced this
particular project with the class.
 
Greg... If the class that's a project by itself is creating a _library_
then there
should be no problem with the type of this library referenced from an
application or a service. I suspect that some application calls are not
available
to services.

Regards,
Jeff
I don't completely understand, but I did try changing the class name,
project name, and namespace to something else but still have the same
problem.<
 
Jeff Louie said:
Greg... If the class that's a project by itself is creating a _library_
then there
should be no problem with the type of this library referenced from an
application or a service. I suspect that some application calls are not
available
to services.

Regards,
Jeff

I think I figured out the problem. InteropServices isn't working within my
Windows Service and it looks like the only way to make it work (from what
I've read) is to enable something called interact with desktop, which I'm
not sure I'll be able to do or even want to do.
 
Back
Top