question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ILMerge fails to properly merge WpfMath

See original GitHub issue

Repository https://github.com/davidagross/ILMerge-vs-WpfMath provides a MWE of this error.

Basically, when WpfMath.dll isn’t next to the merged, standalone executable, the render fails:

System.TypeInitializationException: The type initializer for 'WpfMath.DefaultTexFont' threw an exception. ---> System.IO.FileNotFoundException: The system cannot find the file specified. (Exception from HRESULT: 0x80070002)
   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode, IntPtr errorInfo)
   at MS.Internal.Text.TextInterface.Native.Util.ConvertHresultToException(Int32 hr)
   at MS.Internal.Text.TextInterface.Factory.CreateFontFace(Uri filePathUri, UInt32 faceIndex, FontSimulations fontSimulationFlags)
   at System.Windows.Media.GlyphTypeface.Initialize(Uri typefaceSource, StyleSimulations styleSimulations)
   at WpfMath.DefaultTexFontParser.CreateFont(String name)
   at WpfMath.DefaultTexFontParser.GetFontDescriptions()
   at WpfMath.DefaultTexFont..cctor()
   --- End of inner exception stack trace ---
   at WpfMath.DefaultTexFont..ctor(Double size)
   at WpfMath.TexFormula.GetRenderer(TexStyle style, Double scale, String systemTextFontName)
   at WpfMath.Extensions.RenderToPng(TexFormula texForm, Double scale, Double x, Double y, String systemTextFontName)
   at ILMerge_vs_WpfMath.Renderer.DisplayEquation()
   at ILMerge_vs_WpfMath.Renderer..ctor()

indicating that the merge was not successfull. This is also tracked in https://github.com/dotnet/ILMerge/issues/70.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ForNeVeRcommented, Jan 3, 2020

Unfortunately, not yet; sorry for the pause.

I’ll try to make it till 2020-01-09.

0reactions
ForNeVeRcommented, Mar 14, 2020

I’ve taken a look at the issue. The following patch doesn’t solve the problem, even if it was supposed to:

Index: src/WpfMath/DefaultTexFontParser.cs
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/WpfMath/DefaultTexFontParser.cs	(revision 7ae7168a86dcd425a238ee25a9c9e2e72d21d1ec)
+++ src/WpfMath/DefaultTexFontParser.cs	(date 1584174774150)
@@ -221,7 +221,8 @@
         private GlyphTypeface CreateFont(string name)
         {
             // Load font from embedded resource.
-            var fontUri = new Uri(string.Format("pack://application:,,,/WpfMath;component/{0}{1}", fontsDirectory, name));
+            var assemblyShortName = Assembly.GetExecutingAssembly().GetName().Name;
+            var fontUri = new Uri($"pack://application:,,,/{assemblyShortName};component/{fontsDirectory}{name}");
             return new GlyphTypeface(fontUri);
         }

Even when I’m trying to use a correct assembly name (according to the pack URIs documentation), the following exception gets thrown (note it’s not “file not found” anymore, but something about “I/O Error occurred”):

There was an error:System.TypeInitializationException: The type initializer for 'WpfMath.DefaultTexFont' threw an exception. ---> System.IO.IOException: I/O error occurred.

   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode, IntPtr errorInfo)
   at MS.Internal.Text.TextInterface.Native.Util.ConvertHresultToException(Int32 hr)
   at MS.Internal.Text.TextInterface.Factory.CreateFontFace(Uri filePathUri, UInt32 faceIndex, FontSimulations fontSimulationFlags)
   at System.Windows.Media.GlyphTypeface.Initialize(Uri typefaceSource, StyleSimulations styleSimulations)
   at System.Windows.Media.GlyphTypeface..ctor(Uri typefaceSource)
   at WpfMath.DefaultTexFontParser.CreateFont(String name) in D:\X-Files\Projects\wpf-math\src\WpfMath\DefaultTexFontParser.cs:line 226
   at WpfMath.DefaultTexFontParser.GetFontDescriptions() in D:\X-Files\Projects\wpf-math\src\WpfMath\DefaultTexFontParser.cs:line 74
   at WpfMath.DefaultTexFont..cctor() in D:\X-Files\Projects\wpf-math\src\SharedMath\DefaultTexFont.cs:line 26
   --- End of inner exception stack trace ---
   at WpfMath.DefaultTexFont..ctor(Double size)
   at WpfMath.TexFormula.GetRenderer(TexStyle style, Double scale, String systemTextFontName) in D:\X-Files\Projects\wpf-math\src\WpfMath\TexFormula.cs:line 27
   at WpfMath.Extensions.RenderToPng(TexFormula texForm, Double scale, Double x, Double y, String systemTextFontName) in D:\X-Files\Projects\wpf-math\src\WpfMath\Extensions.cs:line 14
   at ILMerge_vs_WpfMath.Renderer.DisplayEquation() in T:\Temp\ILMerge-vs-WpfMath\ILMerge-vs-WpfMath\ILMerge-vs-WpfMath\Renderer.cs:line 43
   at ILMerge_vs_WpfMath.Renderer..ctor() in T:\Temp\ILMerge-vs-WpfMath\ILMerge-vs-WpfMath\ILMerge-vs-WpfMath\Renderer.cs:line 27

Here’s the resource section of the binary after ILMerge: Resource section as shown by Rider decompiler

It looks like WpfMath.g.resources should be renamed to ILMerge-vs-WpfMath.Standalone.g.resources or something like that, but I haven’t tried that.

From this investigation, it’s clear that we cannot do anything about the issue in the WPF-Math code currently.

If you’ll ever found a way to rename the resource using ILMerge, then please inform me, and I’ll try if the patch helps the resulting application to work. If it is, then we’ll merge it.

I’ll not merge that patch to the main code base for now, because we’ve no proof that it’ll work even after some resource-related workarounds with ILMerge.

For now, I’ll close the issue as (supposedly) non-actional from our side. Feel free to comment though, if it becomes actionable then I’ll gladly reopen and fix it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ILMerge fails to properly merge WpfMath · Issue #202
Basically, when WpfMath.dll isn't next to the merged, standalone executable, ... ILMerge fails to properly merge WpfMath #202.
Read more >
ILMerge fails to merge: The assembly 'xxx' was not ...
A common problem is that after merging some assemblies, you get an error message stating that an input assembly was not merged in...
Read more >
error merging with ILmerge
Hello i have created a simple tool a console application to read the appointments from an scheduler and send it a report, i...
Read more >
ILMerge WPF Controls
ILMerge is not able to merge WPF assemblies. They contain resources with encoded assembly identities. ILMerge is unable to deserialize the ...
Read more >
ILMerge for Infragistics 13.2 assemblies fails
Do you want to use the /alllowDup option? An exception occurred during merging: ILMerge.Merge: ERROR!!: Duplicate type 'Infragistics.Win.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found