logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1513912 - in /logging/log4net/branches/1.2.12: ./ src/Util/SystemInfo.cs tests/src/Util/SystemInfoTest.cs
Date Wed, 14 Aug 2013 14:46:39 GMT
Author: bodewig
Date: Wed Aug 14 14:46:39 2013
New Revision: 1513912

URL: http://svn.apache.org/r1513912
Log:
merge fix for LOG4NET-388

Modified:
    logging/log4net/branches/1.2.12/   (props changed)
    logging/log4net/branches/1.2.12/src/Util/SystemInfo.cs
    logging/log4net/branches/1.2.12/tests/src/Util/SystemInfoTest.cs

Propchange: logging/log4net/branches/1.2.12/
------------------------------------------------------------------------------
  Merged /logging/log4net/trunk:r1513751

Modified: logging/log4net/branches/1.2.12/src/Util/SystemInfo.cs
URL: http://svn.apache.org/viewvc/logging/log4net/branches/1.2.12/src/Util/SystemInfo.cs?rev=1513912&r1=1513911&r2=1513912&view=diff
==============================================================================
--- logging/log4net/branches/1.2.12/src/Util/SystemInfo.cs (original)
+++ logging/log4net/branches/1.2.12/src/Util/SystemInfo.cs Wed Aug 14 14:46:39 2013
@@ -457,10 +457,38 @@ namespace log4net.Util
 			{
 				try
 				{
-					// This call requires FileIOPermission for access to the path
-					// if we don't have permission then we just ignore it and
-					// carry on.
-					return myAssembly.Location;
+#if NET_4_0
+					if (myAssembly.IsDynamic)
+					{
+						return "Dynamic Assembly";
+					}
+#else
+					if (myAssembly is System.Reflection.Emit.AssemblyBuilder)
+					{
+						return "Dynamic Assembly";
+					}
+					else if(myAssembly.GetType().FullName == "System.Reflection.Emit.InternalAssemblyBuilder")
+					{
+						return "Dynamic Assembly";
+					}
+#endif
+					else
+					{
+						// This call requires FileIOPermission for access to the path
+						// if we don't have permission then we just ignore it and
+						// carry on.
+						return myAssembly.Location;
+					}
+				}
+				catch (NotSupportedException)
+				{
+					// The location information may be unavailable for dynamic assemblies and a NotSupportedException
+					// is thrown in those cases. See: http://msdn.microsoft.com/de-de/library/system.reflection.assembly.location.aspx
+					return "Dynamic Assembly";
+				}
+				catch (TargetInvocationException ex)
+				{
+					return "Location Detect Failed (" + ex.Message + ")";
 				}
 				catch (ArgumentException ex)
 				{

Modified: logging/log4net/branches/1.2.12/tests/src/Util/SystemInfoTest.cs
URL: http://svn.apache.org/viewvc/logging/log4net/branches/1.2.12/tests/src/Util/SystemInfoTest.cs?rev=1513912&r1=1513911&r2=1513912&view=diff
==============================================================================
--- logging/log4net/branches/1.2.12/tests/src/Util/SystemInfoTest.cs (original)
+++ logging/log4net/branches/1.2.12/tests/src/Util/SystemInfoTest.cs Wed Aug 14 14:46:39 2013
@@ -23,6 +23,11 @@ using log4net.Util;
 
 using NUnit.Framework;
 
+#if NET_4_0
+using System.Linq.Expressions;
+using System.Reflection;
+#endif
+
 namespace log4net.Tests.Util
 {
 	/// <summary>
@@ -31,6 +36,39 @@ namespace log4net.Tests.Util
 	[TestFixture]
 	public class SystemInfoTest
 	{
+
+#if NET_4_0
+		/// <summary>
+		/// It's "does not throw not supported exception" NOT
+		/// "returns 'Dynamic Assembly' string for dynamic assemblies" by purpose.
+		/// <see cref="Assembly.GetCallingAssembly"/> can be JITted and inlined in different
release configurations,
+		/// thus we cannot determine what the exact result of this test will be.
+		/// In 'Debug' GetCallingAssembly should return dynamic assembly named: 'Anonymously Hosted
DynamicMethods Assembly'
+		/// whereas in 'Release' this will be inlined and the result will be something like 'X:\Y\Z\log4net.Tests.dll'.
+		/// Therefore simple check against dynamic assembly
+		/// in <see cref="SystemInfo.AssemblyLocationInfo"/> to avoid <see cref="NotSupportedException"/>
'Debug' release.
+		/// </summary>
+		[Test]
+		public void TestAssemblyLocationInfoDoesNotThrowNotSupportedExceptionForDynamicAssembly()
+		{
+			var systemInfoAssemblyLocationMethod = GetAssemblyLocationInfoMethodCall();
+
+			Assert.DoesNotThrow(() => systemInfoAssemblyLocationMethod());
+		}
+
+		private static Func<string> GetAssemblyLocationInfoMethodCall()
+		{
+			var method = typeof(SystemInfoTest).GetMethod("TestAssemblyLocationInfoMethod", new Type[0]);
+			var methodCall = Expression.Call(null, method, new Expression[0]);
+			return Expression.Lambda<Func<string>>(methodCall, new ParameterExpression[0]).Compile();
+		}
+
+		public static string TestAssemblyLocationInfoMethod()
+		{
+			return SystemInfo.AssemblyLocationInfo(Assembly.GetCallingAssembly());
+		}
+#endif
+
 		[Test]
 		public void TestGetTypeFromStringFullyQualified()
 		{



Mime
View raw message