You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: In the above scenario, due to other problems, the assembly Gelf4NLog.Target can not be loaded (details to follow)
Expected Result: Since Gelf4NLog.Target can not be loaded, NLog configuration fails. Since throwConfigExceptions is set to true, the app should fail with an exception.
Current Result: No exceptions are thrown. The only hint that NLog had problems is in its internal log. In my case the internal log looks like:
2016-06-15 14:06:58.3440 Error Failed to add type 'Gelf4NLog.Target.GelfMessage'. Exception: System.IO.FileLoadException: Could not load file or assembly 'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'
at System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type)
at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg)
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent)
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeType type, RuntimeType caType, Boolean inherit)
at System.RuntimeType.GetCustomAttributes(Type attributeType, Boolean inherit)
at NLog.Config.Factory`2.RegisterType(Type type, String itemNamePrefix)
at NLog.Config.Factory`2.ScanTypes(Type[] types, String prefix)
Workarounds: Well, fix the issue that is preventing the assembly from being loaded, for one. But I'd rather get notified when NLog's config step fails.
Unit Tests: I managed to create the following tests for similar issues around throwConfigExceptions, but I'm not sure how to test the case where the assembly exists but one of its dependencies doesn't. The weird try/catch stuff is because the referenced version of xUnit doesn't support ThrowsAny, and I personally don't care what the exception type is. You probably do. :)
[Fact]
public void ExtensionInvalidTypeTest()
{
Assert.NotNull(typeof(FooLayout));
var configXml = @"
<nlog throwConfigExceptions='true'>
<extensions>
<add type='some_type_that_doesnt_exist'/>
</extensions>
</nlog>";
System.Exception e = null;
try
{
CreateConfigurationFromString(configXml);
}
catch(System.Exception ex)
{
e = ex;
}
Assert.NotNull(e);
}
[Fact]
public void ExtensionInvalidAssemblyTest()
{
Assert.NotNull(typeof(FooLayout));
var configXml = @"
<nlog throwConfigExceptions='true'>
<extensions>
<add assembly='some_assembly_that_doesnt_exist'/>
</extensions>
</nlog>";
System.Exception e = null;
try
{
CreateConfigurationFromString(configXml);
}
catch (System.Exception ex)
{
e = ex;
}
Assert.NotNull(e);
}
The text was updated successfully, but these errors were encountered:
Type (choose one): Bug
NLog version: 4.3.5
Platform: .Net 4.5
Current NLog config (xml or C#, if relevant)
Note: In the above scenario, due to other problems, the assembly Gelf4NLog.Target can not be loaded (details to follow)
Expected Result: Since Gelf4NLog.Target can not be loaded, NLog configuration fails. Since
throwConfigExceptions
is set to true, the app should fail with an exception.Current Result: No exceptions are thrown. The only hint that NLog had problems is in its internal log. In my case the internal log looks like:
Workarounds: Well, fix the issue that is preventing the assembly from being loaded, for one. But I'd rather get notified when NLog's config step fails.
Unit Tests: I managed to create the following tests for similar issues around
throwConfigExceptions
, but I'm not sure how to test the case where the assembly exists but one of its dependencies doesn't. The weird try/catch stuff is because the referenced version of xUnit doesn't support ThrowsAny, and I personally don't care what the exception type is. You probably do. :)The text was updated successfully, but these errors were encountered: