Is there a way for a managed dll to call functions in a managed COM server? - com

I have a .net 3.5 dll and a .net 4.0 dll. The .net 3.5 dll need to call some functions in the .net 4.0 dll. To do this, I made the 4.0 .net dll as a COM server. However, I cannot tlbimp the tlb file exported from the 4.0 dll. Is it possible for a .net dll to call functions from a .net COM server? Thanks.

If possible you should either upgrade the 3.5 to 4.0 or downgrade the 4.0 to 3.5/2.0, so you can properly add the managed reference.
If you can't do that the alternative is to copy the declaration and replace [ComVisible(true)] by [ComImport] - however this may fail with a typecast exception on runtimes earlier than 4.0. I don't know if it works when 3.5 talks to 4.0, you'd have to test.

Related

Accessing the .Net 4.0 Com from .Net 1.1 Project [duplicate]

I have external .net library compiled with .net framework 4 (it's provider moved recently to .net 4)
My code currently runs on .net framework 3.5
How to use that external library in my application ?
Moving whole application to .net 4 needs time and testing, so maybe in a future i will do that, but now, what are the possibilities ?
There are no possibilities, the CLR version that comes with .NET 3.5 cannot load 4.0 assemblies. The metadata format was changed. You have to force your app to use the .NET 4.0 CLR version. Do so by recompiling it with VS2010, targeting 4.0, or by using a .config file that contains the <requestedRuntime> element to ask for "v4.0".
Compatibility for .NET 4.0 is excellent btw.
While you cannot load the .Net DLL directly, you can wrap it in a COM interface, and load that COM interface in your .Net 3.5 process.
See Using a .NET 4 Based DLL From a .NET 2 Based Application
For more background information, Microsoft originally added In-Process Side-by-Side in .Net 4 to better support the scenario where an application loads add-ins via COM, and the add-ins were written with various versions of .Net. The ability to load .Net 4 DLLs in a .Net 3.5 process is just a nice side effect of that.

Problem using Managed C++ (.Net 2.0) in .Net 2.0 project in VS2010. Referencing 4.0 .NET functionalities

I have exactly the same problem asked here.
Problem using Managed C++ (.Net 2.0) in .Net 2.0 project in VS2010.
Basically I have a C++/CLI project in .NET 2.0 and it indirectly references some 4.0 version dll via MFCMIFC80.DLL.
The only solution the person found was to delete MFCMIFC80.DLL.
How safe is that? Is there any other way to do this?
Solution:
The C++ project was using the v100 Platform toolset. This makes it depend on 4.0 .NET versions of some libraries.
Changing the toolset to v90 solves the problem.

Using a .NET 4.0 DLL in Unity3d via COM/SxS?

In an attempt to oversimplify my issue, I'll try to keep it short:
I'm using the pro version of Unity, and I have 2 DLLs:
A .NET 3.5 assembly (acting as a COM client)
A .NET 4.0 assembly (with an interface exposed via COM)
The 3.5 uses COM to work with the 4.0. Using the 3.5 assembly in a Windows app works fine, it loads the 4.0 dll using SxS via Type.GetTypeFromCLSID() or Type.GetTypeFromProgID() (which I've confirmed with SxStrace), and can use it's functionality just fine. (The windows app mentions it's dependency on the 4.0 DLL via a manifest, I'm not registering the COM DLL.)
I'm trying to use the .NET 4.0 DLL in Unity. Obviously I can't use it directly, since the current flavor of Mono that Unity uses only supports up to 3.5, thus I created the 3.5 assembly to be my middleman. I'm able to use the 3.5 assembly fine in unity, but either of the Type methods I mentioned before throw NotImplementedException(s), as apparently they aren't supported by Unity (or rather, Mono), so I'm at a loss.
Any ideas?
Although this question was made 1 year ago..sadly the middleman tactic still wont work, it is not possible to use .NET 4.0 dlls within Unity3D since Mono is just not supporting the dependencies.
You could try to remove any 4.0 dependencies from the dll and compile it as 3.5, if that is possible for you.

Backwards compatability between .Net 2.0/3.5 and 4.0

I have an app that I've upgraded from 3.5 to 4.0. But not all my 3rd party assemblies are built on .net 4.0. How is it that I'm still able to reference those assemblies without any problems? For instance, if another assembly references system.dll 2.0, and my upgraded project references system.dll 4.0 how does .net handle this?
Obviosly this wasn't a problem upgrading between 2.0 and 3.5 because they use the same BCL and CLR versions, but 4.0 uses a completely different BCL and CLR right?
Here's an example. I have an app built using WF (Windows Workflow) in v3.5. I've upgraded the app to v4.0, but I wasn't required to implement all the breaking changes in the new version of workflow. It still using the old 3.5 version of WF.
.NET 4.0 can reference .NET 2.0 assemblies, but the reverse is not true.
.NET 4.0 assemblies support everything that 2.0 had, but adds in things like optional parameters, dynamic types, and etc...
So, since 2.0 doesn't have anything that 4.0 doesn't, 4.0 can easily support 2.0.
BCL and CLR are different but not completely different. Basically they worked hard to not break backwards compatibility.
You could also force your 3rd party assemblies to run under 3.5, as described in this post.

.NET 4 side by side problem

If the host program is compiled with .NET 4, but a referenced dll is .net 3.5.
Then the target deploy machine need to install both .net 4 framework and .net 3.5 framework runtime?
No, in this case the target machine needs only the 4.0 framework runtime.