1

I've used Obfuscar on my C# application, but the obfuscated version throws an exception where the normal version doesn't.

I'm trying to figure out what the problem is, but I'm struggling. I've used the XML options to turn off as much obfuscation as I can - essentially only changing the local variable names is in effect (can you turn that off?) - but the problem remains.

It appears to be caused by this line, concerning the Magick.NET library:

MagickImageCollection rowImages = new MagickImageCollection();

and throws this error:

The type initializer for 'NativeMagickImageCollection' threw an exception

Using ILSpy, I can't see anything in the obfuscated method that would trip this up - it's the very first thing in that method, more or less.

I'm at a loss as to what to try next - any ideas?

Kyudos
  • 625
  • 4
  • 18
  • Are you including MagickImageCollection in the obfuscation? It is possible it uses some reflection that breaks when obfuscating. I would probably recommend only obfuscating your own dlls if you are not already doing that. There is no telling what kind of code libraries are using, and if they can be safely obfuscated or not. It might be that the code fails in a static constructor/field initializer for the class, these are run sometime before the first usage of the class, likely when the first method that uses the type is first run. – JonasH May 11 '23 at 09:22

1 Answers1

0

It turns out to just be my unfamiliarity with C#! Thanks to ChatGPT which told me to check the "InnerException" I found I was just missing a Magick DLL in my "Obfuscated" directory - nothing to do with the obfuscation at all, at least not directly. I guess I'm used to a more strident / obvious complaint when a DLL is missing. The "benefits" of managed code I suppose!

(Note I had, of course, run "Dependencies" on the obfuscated app - the missing DLL was not reported that way!)

Kyudos
  • 625
  • 4
  • 18