سؤال

I have a project in .NET 2.0 (let's call it Project A). I wanted to use WCF, so I created another project (in .NET 3.0, let's call it Project B) where I put all WCF logic, so all I do in my Project A is calling some method from class from Project B. When I add reference to Project B, Project A does not see it and I get warnings:

The primary reference "Project B/Some.dll" could not be resolved because it has an indirect dependency on the framework assembly "System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=XXX" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v2.0".

How can I make this work?

هل كانت مفيدة؟

المحلول

Yes, this is perfectly possible. You just expose the components written in 3.0 as COM objects. The 2.0 hosting application just uses them as COM objects and has no idea whether they are native, 2.0, 3.0 or whatever. COM is the common interface that both runtime versions have to implement identically.

نصائح أخرى

To use WCF (at runtime) .NET 3 (or better 3.5) will need to be installed anyway. Therefore change ProjectA to target 3 (or 3.5).

You can not do this directly, your projects target different versions of .NET.

What you can do is communicate between two processes.

Make your 3.0 project an executable, and allow it to accept a commandline argument that invokes the method you want to use.

In your 2.0 project, spawn your 3.0 project as a new Process with the proper commandline arguments. If necessary, write to your 3.0 project's StandardOutput and read it from your 2.0 project.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top