[ 
https://issues.apache.org/jira/browse/LOG4NET-388?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13739278#comment-13739278
 ] 

Dominik Psenner edited comment on LOG4NET-388 at 8/14/13 6:37 AM:
------------------------------------------------------------------

Is your code able to detect dynamic assemblies when running on Mono? There may 
be dragons:

--- quote ---
                        if (assembly is System.Reflection.Emit.AssemblyBuilder)
                        {
                                return true;
                        }
                        try 
                        {
                                if (assembly.GetType().FullName == 
"System.Reflection.Emit.InternalAssemblyBuilder")
                                {
                                        return true;
                                }
                        }
                        catch (TargetInvocationException)
                        {
                        }
--- /quote ---

I'm inclined to keep the method as simple as:

--- quote ---
                public static string AssemblyLocationInfo(Assembly myAssembly)
                {
#if NETCF
                        return "Not supported on Microsoft .NET Compact 
Framework";
#else
                        if (myAssembly.GlobalAssemblyCache)
                        {
                                return "Global Assembly Cache";
                        }
#if NET_4_0
                        else if (myAssembly.IsDynamic)
                        {
                                return "Dynamic Assembly";
                        }
#endif
                        
                        else
                        {
                                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;
                                }
                                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 (ArgumentException ex)
                                {
                                        return "Location Detect Failed (" + 
ex.Message + ")";
                                }
                                catch (System.Security.SecurityException)
                                {
                                        return "Location Permission Denied";
                                }
                        }
#endif
                }
--- /quote ---
                
      was (Author: nachbarslumpi):
    Is your code able to detect dynamic assemblies when running on Mono?
                  
> [PATCH] NotSupportedException is thrown in SystemInfo.AssemblyLocationInfo 
> for dynamic assemblies
> -------------------------------------------------------------------------------------------------
>
>                 Key: LOG4NET-388
>                 URL: https://issues.apache.org/jira/browse/LOG4NET-388
>             Project: Log4net
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 1.2.11
>            Reporter: Piotr Westfalewicz
>            Priority: Minor
>              Labels: easyfix, patch
>         Attachments: NotSupportedExceptionInSystemInfo2.patch, 
> NotSupportedExceptionInSystemInfo.patch
>
>
> For dynamic assemblies "Location" property shouldn't be used 
> (http://msdn.microsoft.com/en-us/library/system.reflection.assembly.location.aspx).
> Therefore in log4net.Util.SystemInfo we can test if assembly is dynamic and 
> in result avoid exception.
> Exception is very annoying and popular with NHibernate 3.3.3.4001.
> I have added both fix and test.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to