By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,889 Members | 1,297 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,889 IT Pros & Developers. It's quick & easy.

Calling assemblies compiled in different framework versions

P: n/a
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?

Nov 15 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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.

--
--Grant
This posting is provided "AS IS" with no warranties, and confers no rights.
"Richard" <an*******@discussions.microsoft.com> wrote in message
news:0c****************************@phx.gbl...
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?

Nov 15 '05 #2

P: n/a
Thanks

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

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

--
--Grant
This posting is provided "AS IS" with no warranties, and confers no rights.

"Richard" <an*******@discussions.microsoft.com> wrote in messagenews:0c****************************@phx.gbl...
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?

.

Nov 15 '05 #3

P: n/a
And shouldn't an application config file be able to help?
-----Original Message-----
Thanks

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

Richard
-----Original Message-----
Where is IInstance defined? If the IInstance in yourservice is not the
same IInstance that is implemented in the other assembly

then you'll get the
InvalidCastException. Remember that a type with the samename in 2
different assemblies is considered 2 different types.

--
--Grant
This posting is provided "AS IS" with no warranties, and

confers no rights.


"Richard" <an*******@discussions.microsoft.com> wrote in

message
news:0c****************************@phx.gbl...
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 loadscorrectly, however, when it attempts to load the assembliescompiled 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 toeach instance. I have a application config file but itdoesn't appear to have had an effect.

Any Ideas?

.

.

Nov 15 '05 #4

P: n/a
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.

--
--Grant
This posting is provided "AS IS" with no warranties, and confers no rights.
Nov 15 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.