wpf
wpf copied to clipboard
.NET Core WPF app doesn't correctly list NativeReference in manifest file
Description
Hi. Our .NET Core WPF App needs to interact with a 3rd-party API. These APIs are exposed via COM objects using a primary interop assembly, for development purposes, or via a NativeReference, by using their *.manifest file, for production-ready purposes. This manifest is needed to make sure all the API assemblies are sitting next to any application consuming them, avoiding the registration of COM objects in the registry, but registering them instead on runtime.
When I build the app with Visual Studio 2022 17.2.6, targeting .NET Core 6.0.302, the output directory looks okay, but the content of its manifest (auto-generated) is the following:
<?xml version="1.0" encoding="utf-8"?>
<assembly xsi:schemaLocation="urn:schemas-microsoft-com:asm.v1 assembly.adaptive.xsd" manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" xmlns:co.v1="urn:schemas-microsoft-com:clickonce.v1" xmlns:co.v2="urn:schemas-microsoft-com:clickonce.v2">
<assemblyIdentity name="TestNativeReferenceNetCore.exe" version="1.0.0.0" type="win32" />
<file name="MyComReference.manifest" size="3530" xmlns="urn:schemas-microsoft-com:asm.v2">
<hash>
<dsig:Transforms>
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
<dsig:DigestValue>pbYOjDIqVH6zsRyWLwxG7BfYooI=</dsig:DigestValue>
</hash>
</file>
</assembly>
The above app's manifest reports the NativeReference ("MyComReference.manifest") as an extra file, but not as a dependency.
If I build the same app targeting .NET Framework 4.8 instead, its manifest will look like this instead:
<?xml version="1.0" encoding="utf-8"?>
<assembly xsi:schemaLocation="urn:schemas-microsoft-com:asm.v1 assembly.adaptive.xsd" manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" xmlns:co.v1="urn:schemas-microsoft-com:clickonce.v1" xmlns:co.v2="urn:schemas-microsoft-com:clickonce.v2">
<assemblyIdentity name="TestNativeReferenceNetFramework.exe" version="1.0.0.0" type="win32" />
<dependency>
<dependentAssembly asmv2:dependencyType="install" asmv2:codebase="MyComReference.manifest" asmv2:size="3528">
<assemblyIdentity name="MyComReference" version="4.6.460.21" processorArchitecture="x86" type="win32" />
<hash xmlns="urn:schemas-microsoft-com:asm.v2">
<dsig:Transforms>
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
<dsig:DigestValue>ExA6jtLLMAdytHAraysKsEVIgPo=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>
</assembly>
As you can see, the "MyComReference.manifest" is instead correctly considered listed as a dependency.
In a few words, .NET Core lists a NativeReference in a WPF app like a file, but not as a dependency, like .NET Framework does.
Reproduction Steps
- Create a solution with a WPF app targeting .NET Core 6 and another WPF app targeting .NET Framework 4.8;
- Add a NativeReference to both projects;
- Build both projects;
- Inspect both apps' manifest files;
Expected behavior
Both manifest files list the NativeReference using <dependency>
and <dependentAssembly>
nodes.
Actual behavior
The .NET Core's manifest file lists the NativeReference as a file, instead of a dependentAssembly, like .NET Framework does.
This issue causes our application not to correctly instantiate the COM objects, because of "Class not registered" error. Without marking the NativeReference as a dependent assembly, the application doesn't load and register the COM objects.
Error: Unable to initialise TypeFromComReference.
System.Runtime.InteropServices.COMException (0x80040154): Retrieving the COM class factory for component with CLSID {AAA44754-CC81-4692-91AF-7064E58EB22A} failed due to the following error: 80040154 Class not registered (0x80040154 (REGDB_E_CLASSNOTREG)).
at System.RuntimeTypeHandle.AllocateComObject(Void* pClassFactory)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)
at System.Activator.CreateInstance(Type type, Boolean nonPublic, Boolean wrapExceptions)
Regression?
It works in .NET Framework 4.7.2 and 4.8.
Known Workarounds
No response
Configuration
- dotnet --info
.NET SDK (reflecting any global.json): Version: 6.0.302 Commit: c857713418
Runtime Environment: OS Name: Windows OS Version: 10.0.19044 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\6.0.302\
global.json file: Not found
Host: Version: 6.0.7 Architecture: x64 Commit: 0ec02c8c96
.NET SDKs installed: 6.1.421 [C:\Program Files\dotnet\sdk] 7.0.214 [C:\Program Files\dotnet\sdk] 5.0.404 [C:\Program Files\dotnet\sdk] 5.0.408 [C:\Program Files\dotnet\sdk] 8.0.101 [C:\Program Files\dotnet\sdk] 6.0.107 [C:\Program Files\dotnet\sdk] 6.0.202 [C:\Program Files\dotnet\sdk] 6.0.203 [C:\Program Files\dotnet\sdk] 6.0.302 [C:\Program Files\dotnet\sdk]
.NET runtimes installed: Microsoft.AspNetCore.All 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.22 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.27 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.22 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.27 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.22 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.1.27 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.13 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.14 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.7 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
- Visual Studio 2022 17.2.6
Other information
No response
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.
This looks like an SDK/build issue. The registration isn't correct in the manifest, at least based on the OPs analysis. The SDK team, or perhaps Roslyn, should take a look at this and determine what they think about the composition of these manifest files.
/cc @jaredpar @marcpopMSFT
Any updates on this issue?
Not sure where the code lives that updates that manifest file. @jaredpar since seems like it might be compiler as I haven't seen something like that in the SDK. CC @dsplaisted
Any updates on this issue?
Emmm, it looks like the sdk issues.
I opened this issue also in the dotnet/runtime repo as I was unsure where to report it, but it was transferred here. Is there anything I should do about this issue? Do I need to open it somewhere else?