Calling assemblies compiled in different framework versions

R

Richard

I have a service which is used to call differenct versions
of an application depending on the database version that
is being used.

The service has been compiled in framework 1.1 and it
needs to call the current version of the application (also
compiled in framework 1.1) and also historic versions
(compiled in framework 1.0).

The application compiled in framework 1.1 loads correctly,
however, when it attempts to load the assemblies compiled
in framework 1.0 I get an InvalidCastException when
calling the unwrap method. Example code is shown below:

ObjectHandle obj = System.Activator.CreateInstance
(fullAssemblyName, pc.Type);
IInstance m_instance = (IInstance)obj.Unwrap();

The DLL highlighted by the thrown exception is stored in
the GAC. And a different assembly version applies to each
instance. I have a application config file but it doesn't
appear to have had an effect.

Any Ideas?
 
G

Grant Richins [MS]

Where is IInstance defined? If the IInstance in your service is not the
same IInstance that is implemented in the other assembly then you'll get the
InvalidCastException. Remember that a type with the same name in 2
different assemblies is considered 2 different types.
 
R

Richard

Thanks

Am I correct in assuming that the only way around this is
to recompile the application with references to the same
interface?

Richard
 
G

Grant Richins [MS]

Possibly a config file can help. It all depends on where IInstance is
defined. If IInstance is in the application, then you're stuck. If
IInstance is in the service, then you might be able to get it working
without recompiling.

If I were to design this from the ground-up, I would have 1 assembly/dll
that just has interfaces like IInstance that dictate how the application and
the service communicate. That assembly is now the 'lowest common
denominator'. Then the application and service both reference that assembly
when they build.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top