Closed snechaev closed 8 months ago
I'm not going to lie, COM interop support and troubleshooting this is not going to make it to the list of priorities.
We're long past portable class libraries and into supporting .NET Core SDKs and netstandard
.
The issue you mentioned, #211, is from 2010 - 13 years ago now and many, many breaking-change-major-releases ago. If it's not working now... it's not supported. Likely somewhere in there, transitioning from per-platform libraries to portable class libraries to .NET core, we lost that ability.
If you want support for this put back, we'd be happy to look at a PR for it. We will not accept PRs that target .NET desktop framework, have a lot of #ifdef
sorts of things in it, or will otherwise cause a maintenance challenge for us. If it's something simple like changing an ==
to a .Equals
call, awesome; if it's super complex, probably not.
Describe the Bug
The embedded interop types (at least enums) are treated as the different types when embedded into the different assemblies. So, if the registration and resolving are in the different assemblies, the resolution will fail. More details and sample project below.
I'm using the COM interop in my project. The interop assembly (made with the
tlbimp
) is referenced in several projects in the solution (everywhere with the Embedded interop types = true). In the following description thepsBlendMode
is the enum from the interop assembly (so, it is also embedded into the each assembly in the solution).I have two assemblies - the
Lib
(class library) and theApp
(exe). The container registrations are made in theLib
. The resolutions are made in theApp
.The registred service are dependent on the
psBlendMode
If I trying to resolve from the code inside the
Lib
, all works fine. If I move resolution code into theApp
, resolution will fail. If I will get the same type from theLib
assembly with reflection, the resoltion will succeedThe runtime treated these types as the equivalent:
typeof(PsBlendMode).IsEquivalentTo(libType) is true
.Steps to Reproduce
Expected Behavior
Registered service
IService<PsBlendMode>
should resolve correctly regardless of the assembly resolution code is called from.Exception with Stack Trace
The code attached does not throw any exception, but if use
Resolve
instead of theTryResolve
, the exception will be the followingDependency Versions
Autofac:
tlbimp
(may be replaced with any other com reference), for exampleAnd then use
AMovie.AppearanceConstants
enum instead of `Photoshop.PsBlendMode'Additional Info
Related issue which claims that No-PIA scenario is supported: https://github.com/autofac/Autofac/issues/211
I digged into the history and found this related commits
Support added in d053b51ce9bdab081c14581ea521d017b0036273 Issue 211: Resolve service types that are embedded interop types ("No-PIA")
Code moved in e3b5eb9c2b4658de490d98fde4be81fc7024448a No-PIA support for additional service types. (src/Source/Autofac/Util/ReflectionExtensions.cs)
Moved into another file in 82075a83d8f6e84509f6ce65c5c00f29dffc4e44 Moved predicates on System.Type commonly used in scanning registrations to public extension methods; this makes scanning rules that are the inversion of other rules (e.g. like Except(t => t.IsClosedTypeOf(x))) easier to write. (src/Source/Autofac/Util/ReflectionExtensions.cs -> src/Source/Autofac/Util/TypeExtensions.cs)
Support removed in 1db4ee417e16ea878953041a54a9b2b33b8d30f1 Removed separate PCL and converted core Autofac library into PCL instead. (Core/Source/Autofac/Util/TypeExtensions.cs)
Additional info about type equivalence and embedded interop types: https://learn.microsoft.com/en-us/dotnet/framework/interop/type-equivalence-and-embedded-interop-types