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.

TypeInitializationException when used with Costura.Fody

See original GitHub issue

Hi,

I’m using OpenGL.Net for an app I’m working on, and would like to embed its dependencies as resources with Costura.Fody to simplify deployment. However, OpenGL.Net fails to initialize a context when it’s embedded like this, failing with the following error message:

image

My FodyWeavers.xml file is simple:

<?xml version="1.0" encoding="utf-8" ?>
<Weavers>
  <Costura>
    <IncludeAssemblies>
      OpenGL.Net
      OpenGL.Net.WinForms
    </IncludeAssemblies>
  </Costura>
</Weavers>

I’m using OpenGL.Net and OpenGL.Net.WinForms, both v0.5.2.

The issue appears to be this line, where Assembly.GetAssembly(typeof(Egl)).Location is an empty path when embedded, causing Path.GetDirectoryName to fail with the error above.

Since that code is related to ANGLE stuff, which may be tricky to do nicely when embedded, a simple solution would seem to be to fall back on Directory.GetCurrentDirectory() for assemblyPath, or simply short-circuit that block of code entirely.

I’m not sure which option would be preferred, but I would be happy to submit a PR for whatever should be done (this issue is a bit of a show-stopper for me 😀).

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Xyenecommented, Sep 17, 2017

Thanks!

I had a chance to try it out today, and it looks like it’s still not working. If I’m not mistaken, GetAssemblyLocation should look more like this:

	protected static string GetAssemblyLocation()
	{
#if   NETSTANDARD1_1
			string assemblyPath = null; // XXX
#elif NETSTANDARD1_4 || NETCORE
			string assemblyPath = Directory.GetCurrentDirectory();
#else
			string assemblyPath = Assembly.GetAssembly(typeof(KhronosApi)).Location;

			if (String.IsNullOrEmpty(assemblyPath))
				assemblyPath = Directory.GetCurrentDirectory();
			else
				assemblyPath = Path.GetDirectoryName(assemblyPath);
#endif
			return (assemblyPath);
	}

…as it was Assembly.Location returning the empty path causing Path.GetDirectoryName to fail.

0reactions
luca-piccionicommented, Sep 17, 2017

Ops. I completely missed it! Sorry. Just fixed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The type initializer for '<Module>' threw an exception when ...
If the assembly you're trying to embed using Unmanaged32Assemblies is not a mixed-mode assembly, then that method won't work.
Read more >
resource dlls and costura fody
The "same key" exception in costura fody when I set a reference to the resource files too: C#. System.TypeInitializationException ...
Read more >
Newest 'fody' Questions - Stack Overflow
I have just taken over a C# application, which seems to use some Fody library (whatever that means). First I had some problems...
Read more >
Issues with Fody Costura : r/csharp
Our projects are .NET framework 4.8. The issue is when we add fody we get 52 new packages! From my understanding Fody.Costura has...
Read more >
C#使用SqlCipher以及使用Costura.Fody合并DLL进EXE 原创
C#使用SqlCipher以及使用Costura.Fody合并DLL进EXE创建C# Windows 桌面窗体应用使程序支持长路径默认项目属性的BUG使用NuGetSqlCipher的使用Costura.
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