NLog: App crash on UWP (.Net Standard 1.3) when built in release mode and submitted to Store
NLog versions tested: 4.6.3 and 4.5.0
(Both versions were installed via NuGet)
Platform: UWP with minimum sdk version set to 14393 ( = .Net Standard 1.3 )
Steps to reproduce:
I created a blank project with minimum sdk version set to 14393 and target sdk version set to 17763.
Then, I put some code in the constructor of App
class, to initialize NLog and send a test log:
public App()
{
var config = new LoggingConfiguration();
var testTarget = new DebugTarget("testtarget")
{
Layout = "${logger}|${message}",
};
config.AddTarget(testTarget);
config.AddRule(LogLevel.Debug, LogLevel.Fatal, testTarget);
LogManager.Configuration = config;
var logger = LogManager.GetCurrentClassLogger();
logger.Warn("Test!");
this.InitializeComponent();
this.Suspending += OnSuspending;
}
(I’ve also tested by adding a FileTarget
instead of DebugTarget
, and got exactly the same results)
When testing on debug mode, this code works fine.
Then, I associated the app to an app in the Store and built it for uploading to the Store. The flow creates a appxbundle file for test, as well as an appxupload file for uploading to the Store.
The appxbundle test file also works fine (but Store does not accept it, saying it’s a precompiled .Net Native binary and I should upload the appxupload file instead).
Then, I uploaded the appxupload to the Store and got it from the Store, it crashes on startup. I’ve also extracted the contents of the appxupload (there’s an appxbundle there) and installed it manually, it also crashes.
I’ve attached Visual Studio debugger to it (from Debug->Other Debug Targets->Debug Installed App Package), and enabled exceptions. I saw these three exceptions being thrown:
1)
System.MethodAccessException: 'Attempt by security transparent method 'NLog.Internal.ReflectionHelpers.SafeGetTypes(System.Reflection.Assembly)' to access security critical method 'System.Reflection.AssemblyExtensions.GetTypes(System.Reflection.Assembly)' failed.
Assembly 'NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c' is marked with the AllowPartiallyTrustedCallersAttribute, and uses the level 2 security transparency model. Level 2 transparency causes all methods in AllowPartiallyTrustedCallers assemblies to become security transparent by default, which may be the cause of this exception.'
at NLog.Internal.ReflectionHelpers.SafeGetTypes(Assembly assembly)
2)
System.ArgumentException: 'LayoutRenderer cannot be found: 'longdate''
at NLog.Config.Factory`2.CreateInstance(String itemName)
3)
System.MethodAccessException: 'Attempt by security transparent method 'NLog.Internal.PropertyHelper.GetAllReadableProperties(System.Type)' to access security critical method 'System.Reflection.TypeExtensions.GetProperties(System.Type, System.Reflection.BindingFlags)' failed.
Assembly 'NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c' is marked with the AllowPartiallyTrustedCallersAttribute, and uses the level 2 security transparency model. Level 2 transparency causes all methods in AllowPartiallyTrustedCallers assemblies to become security transparent by default, which may be the cause of this exception.'
at NLog.Internal.PropertyHelper.GetAllReadableProperties(Type type)
It seems that setting minimum sdk version to 16299 (.Net Standard 2.0) fixes the issue, but that’s not always an option for apps.
(Please note that extracting appxupload and installing it manually does not work anymore when min sdk version is set to 16299, I assume something’s changed in that version and Store does some processing on the package before making it available; but when submitted through the Store and downloaded from the Store, it works fine)
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 25 (17 by maintainers)
https://ci.appveyor.com/project/nlog/nlog/builds/24877260/artifacts is now ready. See
NLog.4.6.3.10087-PR3438.nupkg
I’m glad is has been resolved 👍
Guys, I submitted multiple submissions to the Store today, and it seems that this issue was a mistake on my part, and NLog even without the modification in #3438 works fine when submitted to the Store.
The issue was, as described in the stackoverflow page metioned in the previous posts twice, that the test case I submitted to the Store had
runFullTrust
permission enabled, and the test cases I created later was only tested locally, not submitted through Store.There seem to be no proper documentation about .Net Native behavior on Store on the related docs (or I missed them if there are), so I didn’t know before that
runFullTrust
causes the .Net Native to not run on the Store submission, and I observed the issue both locally and when I submitted the app to the Store, so I thought this is an issue related to the library, not incomplete compilation.Sorry about that.
@MahdiGhiasi Maybe interesting for you:
https://stackoverflow.com/questions/50216085/missing-system-assembly-in-appxupload-only
The previous errors are not appearing on this build! They seemed to happen on creating
DebugTarget
, now that code succeeds, but I’m getting some missing assembly exceptions a few lines after that onGetCurrentClassLogger()
.I thought maybe I’m doing something wrong, so I waited for the NuGet. But I’m getting the exception with that as well. However, it seems that it is to be expected, as the
appxupload
is not completely compiled and it finalizes when you upload the package to the Store.(Creating
FileTarget
also throws the same missing assembly exception, maybe there’s a reflection method that is missing from this incomplete build thatFileTarget
uses, butDebugTarget
doesn’t?)My guess is that the issue is solved now, as I’m getting a different error now and creating
DebugTarget
seem to go well, but it seems that the only way to really confirm that it works correctly is to submit the app into the Store and see how it behaves.This will take a while as there’s a certification process; I’ll submit a test to the Store and will report back as soon as I can.
you can get the nupkg as follows:
wait for green on appveyor:
https://github.com/NLog/NLog/pull/3438
then press “details”
then go to artifacts tab
Nope, the build queue is a bit busy as we have only 1 machine and i’m also releasing 4.6.4 😉
you could clone and switch to master (we are using gitflow). Just build the sln in src folder (https://github.com/NLog/NLog/blob/master/src/NLog.sln)
or do
Created #3438. Maybe @MahdiGhiasi can test the build when it completes