Obfuscating an Uno WASM app with Dotfuscator results in only Uno icon and no errors #11985
-
Hello all, I am trying to obfuscate the WASM version of a proof of concept app that I wrote. I am using Dotfuscator 6.4 to do the obfuscation on the .clr after publishing the WASM app. I am running the app on Firefox (64-bit, v108.0.2) and on Ubuntu Desktop 20.04. The app loads and runs fine unobfuscated. However when I obfuscate it, all I get is the Uno logo after the loading screen completes. I cannot figure out how to see any errors. I even modified my App.xaml.cs to put a try-catch around the entire OnLaunched event, which will show an error screen with a stack trace in the event of an exception during startup. I've tested this with injected exceptions and it works as expected when unobfuscated. However when I run obfuscated I do not get the error screen. Just the Uno icon. So my first question is: Where can I see any errors Uno might have in loading a WASM app? I've tried opening up the developer options in my browser (F12 in Firefox), but I don't see anything useful in there. To at least prove out that Uno WASM can be obfuscated, I created a very small test app with only a single View Model and a single Model. The MainView page just shows a value from the Model as exposed via the ViewModel. This runs fine when obfuscated, so I know that obfuscating an Uno WASM app is possible. To add to the mystery, though, going back to my PoC, when I change the obfuscation settings to exclude renaming and control-flow for EVERYTHING, it STILL does not load properly. So I imagine there must be something in my PoC code that is causing Dotfuscator to mess something up when obfuscating-but-not-really-obfuscating the .clr. So my second question is: Does anyone have any experience or knowledge of caveats that should be taken into account when obfuscating a .clr from a published WASM app? I appreciate any thoughts/ideas. |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 3 replies
-
I seem to have found the culprit, although I'm not sure why. It looks like my IoC container is to blame. I've already noticed that Uno WASM doesn't work with Autofac. So I switched to TinyIoC. That worked with unobfuscated code. Now, it looks like that even when I just register types with the TinyIoC container, it will break my obfuscated code. I don't even need to resolve the types. When I comment out all UI controls so that my main page is just a bunch of tabs, but am still registering types with the IoC container, then it doesn't load the WASM. When I comment out the registration of types, then the WASM does load. I'll verify this by adding TinyIoC to the hello world that I got working as obfuscated, and will update here what I find. |
Beta Was this translation helpful? Give feedback.
-
Welp, I don't know what's going on. So first of all, adding TinyIoC to my other hello world project did not break it. So it doesn't seem like it's intrinsic to that IoC container. Then, in my PoC I've whittled down the code to where it's not even referencing any IoC container, and it still breaks. This is my Dependency Service, with all the code commented out referring to any IoC container:
As you can see, almost all of it is commented out. And then by adding JUST this line in the App.xaml.cs.OnLaunched:
it will no longer work obfuscated. Without this line, then obfuscated works (albeit with no real functionality because I don't have any VMs or Models). I'm tearing my hair out here trying to identify why this is failing once obfuscated. |
Beta Was this translation helpful? Give feedback.
-
BTW, in case anyone is interested, here is my Dotfuscator config that I'm using:
Salient points to consider:
|
Beta Was this translation helpful? Give feedback.
-
So I removed all IoC code and am building the dependency tree manually. With that out of the way, I finally got a more useful (hopefully) error message to show up on the error screen: (Company and project name elided in order to maintain at least some degree of confidentiality) |
Beta Was this translation helpful? Give feedback.
-
So at this point I have two issues:
|
Beta Was this translation helpful? Give feedback.
Have you tried updating
LinkerConfig.json
to include your assemblies? I'm wondering whether the obfuscation coupled with IoC is causing essential code to be trimmed. Using the IL Linker