Skip to content

Commit 35ffa47

Browse files
Add XPThemes.manifest as embedded resource to resolve EntryPointNotFoundException in .NET Core/.NET5
1 parent 2a64fea commit 35ffa47

File tree

4 files changed

+51
-34
lines changed

4 files changed

+51
-34
lines changed

Ookii.Dialogs.Wpf.sln.DotSettings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=IdentifierTypo/@EntryIndexedValue">DO_NOT_SHOW</s:String>
44
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=MarkupTextTypo/@EntryIndexedValue">DO_NOT_SHOW</s:String>
55
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateConstants/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /&gt;</s:String>
6+
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticReadonly/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /&gt;</s:String>
67
<s:Boolean x:Key="/Default/UserDictionary/Words/=Augusto/@EntryIndexedValue">True</s:Boolean>
78
<s:Boolean x:Key="/Default/UserDictionary/Words/=augustoproiete/@EntryIndexedValue">True</s:Boolean>
89
<s:Boolean x:Key="/Default/UserDictionary/Words/=Groot/@EntryIndexedValue">True</s:Boolean>

src/Ookii.Dialogs.Wpf/ComCtlv6ActivationContext.cs

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Security.Permissions;
6-
using System.Security;
72
using System.IO;
83
using System.Runtime.InteropServices;
94

@@ -58,45 +53,50 @@ private void Dispose(bool disposing)
5853

5954
private static bool EnsureActivateContextCreated()
6055
{
61-
lock( _contextCreationLock )
56+
lock (_contextCreationLock)
6257
{
63-
if( !_contextCreationSucceeded )
58+
if (_contextCreationSucceeded)
6459
{
65-
// Pull manifest from the .NET Framework install
66-
// directory
67-
68-
string assemblyLoc = null;
60+
return _contextCreationSucceeded;
61+
}
6962

70-
assemblyLoc = typeof(Object).Assembly.Location;
63+
const string manifestResourceName = "Ookii.Dialogs.XPThemes.manifest";
64+
string manifestTempFilePath;
7165

72-
string manifestLoc = null;
73-
string installDir = null;
74-
if( assemblyLoc != null )
66+
using (var manifest = typeof(ComCtlv6ActivationContext).Assembly.GetManifestResourceStream(manifestResourceName))
67+
{
68+
if (manifest is null)
7569
{
76-
installDir = Path.GetDirectoryName(assemblyLoc);
77-
const string manifestName = "XPThemes.manifest";
78-
manifestLoc = Path.Combine(installDir, manifestName);
70+
throw new InvalidOperationException($"Unable to retrieve {manifestResourceName} embedded resource");
7971
}
8072

81-
if( manifestLoc != null && installDir != null )
73+
manifestTempFilePath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
74+
75+
using (var tempFileStream = new FileStream(manifestTempFilePath, FileMode.CreateNew, FileAccess.ReadWrite,
76+
FileShare.Delete | FileShare.ReadWrite))
8277
{
83-
_enableThemingActivationContext = new NativeMethods.ACTCTX();
84-
_enableThemingActivationContext.cbSize = Marshal.SizeOf(typeof(NativeMethods.ACTCTX));
85-
_enableThemingActivationContext.lpSource = manifestLoc;
78+
manifest.CopyTo(tempFileStream);
79+
}
80+
}
8681

87-
// Set the lpAssemblyDirectory to the install
88-
// directory to prevent Win32 Side by Side from
89-
// looking for comctl32 in the application
90-
// directory, which could cause a bogus dll to be
91-
// placed there and open a security hole.
92-
_enableThemingActivationContext.lpAssemblyDirectory = installDir;
93-
_enableThemingActivationContext.dwFlags = NativeMethods.ACTCTX_FLAG_ASSEMBLY_DIRECTORY_VALID;
82+
_enableThemingActivationContext = new NativeMethods.ACTCTX
83+
{
84+
cbSize = Marshal.SizeOf(typeof(NativeMethods.ACTCTX)),
85+
lpSource = manifestTempFilePath,
86+
};
9487

95-
// Note this will fail gracefully if file specified
96-
// by manifestLoc doesn't exist.
97-
_activationContext = NativeMethods.CreateActCtx(ref _enableThemingActivationContext);
98-
_contextCreationSucceeded = !_activationContext.IsInvalid;
99-
}
88+
// Note this will fail gracefully if file specified
89+
// by manifestFilePath doesn't exist.
90+
_activationContext = NativeMethods.CreateActCtx(ref _enableThemingActivationContext);
91+
_contextCreationSucceeded = !_activationContext.IsInvalid;
92+
93+
try
94+
{
95+
File.Delete(manifestTempFilePath);
96+
}
97+
catch (Exception)
98+
{
99+
// We tried to be tidy but something blocked us :(
100100
}
101101

102102
// If we return false, we'll try again on the next call into

src/Ookii.Dialogs.Wpf/Ookii.Dialogs.Wpf.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@
8585
<None Remove="*.DotSettings" />
8686
</ItemGroup>
8787

88+
<ItemGroup>
89+
<None Remove="Properties\XPThemes.manifest" />
90+
<EmbeddedResource Include="Properties\XPThemes.manifest">
91+
<LogicalName>Ookii.Dialogs.XPThemes.manifest</LogicalName>
92+
</EmbeddedResource>
93+
</ItemGroup>
94+
8895
<ItemGroup>
8996
<None Remove="CredentialDialog.bmp" />
9097
<None Remove="CustomDictionary.xml" />
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
2+
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
3+
<description>Windows Forms Common Control manifest</description>
4+
<dependency>
5+
<dependentAssembly>
6+
<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*" />
7+
</dependentAssembly>
8+
</dependency>
9+
</assembly>

0 commit comments

Comments
 (0)