You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-user@logging.apache.org by John Moreno <jo...@gmail.com> on 2011/10/18 00:37:41 UTC

log4net is throwing TargetInvocationException

Hello,

log4net 1.2.10 is throwing an exception when I try to create it.

Exception has been thrown by the target of an invocation.;
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean
publicOnly, Boolean noCheck, Boolean& canBeCached,
RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
  at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly,
Boolean skipCheckThis, Boolean fillCache)
  at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly,
Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean
fillCache)
  at System.Activator.CreateInstance(Type type, Boolean nonPublic)
  at log4net.Core.DefaultRepositorySelector.CreateRepository(String
repositoryName, Type repositoryType)
  at log4net.Core.DefaultRepositorySelector.CreateRepository(Assembly
repositoryAssembly, Type repositoryType, String repositoryName,
Boolean readAssemblyAttributes)
  at log4net.Core.DefaultRepositorySelector.CreateRepository(Assembly
repositoryAssembly, Type repositoryType)
  at log4net.Core.DefaultRepositorySelector.GetRepository(Assembly
repositoryAssembly)
  at log4net.Core.LoggerManager.GetRepository(Assembly repositoryAssembly)
  at log4net.LogManager.GetRepository(Assembly repositoryAssembly)
  at log4net.Config.XmlConfigurator.Configure(XmlElement element)
  at MyAbstractClass.get_Logger();System.Reflection.TargetInvocationException:
Exception has been thrown by the target of an invocation. --->
System.TypeLoadException: Inheritance security rules violated while
overriding member:
'log4net.Util.ReadOnlyPropertiesDictionary.GetObjectData(System.Runtime.Serialization.SerializationInfo,
System.Runtime.Serialization.StreamingContext)'. Security
accessibility of the overriding method must match the security
accessibility of the method being overriden.
  at log4net.Repository.Hierarchy.Hierarchy..ctor(ILoggerFactory loggerFactory)
  at log4net.Repository.Hierarchy.Hierarchy..ctor()
  --- End of inner exception stack trace ---
  at System.RuntimeTypeHandle.CreateInstance(RuntimeType type,
Boolean publicOnly, Boolean noCheck, Boolean& canBeCached,
RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
  at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly,
Boolean skipCheckThis, Boolean fillCache)
  at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly,
Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean
fillCache)
  at System.Activator.CreateInstance(Type type, Boolean nonPublic)
  at log4net.Core.DefaultRepositorySelector.CreateRepository(String
repositoryName, Type repositoryType)
  at log4net.Core.DefaultRepositorySelector.CreateRepository(Assembly
repositoryAssembly, Type repositoryType, String repositoryName,
Boolean readAssemblyAttributes)
  at log4net.Core.DefaultRepositorySelector.CreateRepository(Assembly
repositoryAssembly, Type repositoryType)
  at log4net.Core.DefaultRepositorySelector.GetRepository(Assembly
repositoryAssembly)
  at log4net.Core.LoggerManager.GetRepository(Assembly repositoryAssembly)
  at log4net.LogManager.GetRepository(Assembly repositoryAssembly)
  at log4net.Config.XmlConfigurator.Configure(XmlElement element)
  at MyAbstractClass.get_Logger();Inheritance security rules violated
while overriding member:
'log4net.Util.ReadOnlyPropertiesDictionary.GetObjectData(System.Runtime.Serialization.SerializationInfo,
System.Runtime.Serialization.StreamingContext)'. Security
accessibility of the overriding method must match the security
accessibility of the method being overriden.;   at
log4net.Repository.Hierarchy.Hierarchy..ctor(ILoggerFactory
loggerFactory)
  at log4net.Repository.Hierarchy.Hierarchy..ctor();System.TypeLoadException:
Inheritance security rules violated while overriding member:
'log4net.Util.ReadOnlyPropertiesDictionary.GetObjectData(System.Runtime.Serialization.SerializationInfo,
System.Runtime.Serialization.StreamingContext)'. Security
accessibility of the overriding method must match the security
accessibility of the method being overriden.
  at log4net.Repository.Hierarchy.Hierarchy..ctor(ILoggerFactory loggerFactory)
  at log4net.Repository.Hierarchy.Hierarchy..ctor();

Re: log4net is throwing TargetInvocationException

Posted by John Moreno <jo...@gmail.com>.
On Friday, October 21, 2011, Stefan Bodewig <bo...@apache.org> wrote:
> On 2011-10-21, John Moreno wrote:
>> I was using the 1.2.10 codebase and .net 4.0, but I have switched over
>> to the 1.2.11 version, and I am still getthing the same exception from
>> the call to the XmlConfigurator.Configure.
>
> Is this the official binary or did you compile it yourself?  If using
> the official binary, make sure you have the .NET 4.0 one.  If you
> compile it yourself, ensure you define the NET_4_0 compilation symbol.

This is the official binary, from the 4.0 directly.  It is being built on a
new VM, which hasn't previously had log4net installed and being ILMerged and
the deployed to a MS CRM server.

> One other thing to look out for is the GAC (you may still be using
> 1.2.10).

I had previously put the 1.2.10 binary on the sever, but not in the GAC.

> The exception occurs as the GetObjectData method of ISerializable needs
> a SecurityCritical attribute attached to it now and this only happens if
> the code is compiled for 4.0 - and knows that it is.

I'll look into that a bit before giving up.

Re: log4net is throwing TargetInvocationException

Posted by Stefan Bodewig <bo...@apache.org>.
On 2011-10-21, John Moreno wrote:

> On Mon, Oct 17, 2011 at 11:45 PM, Stefan Bodewig <bo...@apache.org> wrote:
>> On 2011-10-18, John Moreno wrote:

>>> log4net 1.2.10 is throwing an exception when I try to create it.

>> This happens with the 1.2.10 codebase if you compile it as a .NET 4.0

> I was using the 1.2.10 codebase and .net 4.0, but I have switched over
> to the 1.2.11 version, and I am still getthing the same exception from
> the call to the XmlConfigurator.Configure.

Is this the official binary or did you compile it yourself?  If using
the official binary, make sure you have the .NET 4.0 one.  If you
compile it yourself, ensure you define the NET_4_0 compilation symbol.

One other thing to look out for is the GAC (you may still be using
1.2.10).

The exception occurs as the GetObjectData method of ISerializable needs
a SecurityCritical attribute attached to it now and this only happens if
the code is compiled for 4.0 - and knows that it is.

Stefan

Re: log4net is throwing TargetInvocationException

Posted by John Moreno <jo...@gmail.com>.
On Mon, Oct 17, 2011 at 11:45 PM, Stefan Bodewig <bo...@apache.org> wrote:
> On 2011-10-18, John Moreno wrote:
>
>> log4net 1.2.10 is throwing an exception when I try to create it.
>
> This happens with the 1.2.10 codebase if you compile it as a .NET 4.0

I was using the 1.2.10 codebase and .net 4.0, but I have switched over
to the 1.2.11 version, and I am still getthing the same exception from
the call to the XmlConfigurator.Configure.

I'm fairly certain this is a problem with ILMERGE and needing to
specify the correct assembly somehow or other, but regardless it's
still an exception being thrown by log4net from within the
XmlConfigurator.Configure method...

Re: log4net is throwing TargetInvocationException

Posted by Stefan Bodewig <bo...@apache.org>.
On 2011-10-18, John Moreno wrote:

> log4net 1.2.10 is throwing an exception when I try to create it.

This happens with the 1.2.10 codebase if you compile it as a .NET 4.0
project.  If you do so, the "new security rules" apply instead of CAS
and the 1.2.10 code base violates quite a few of them.

You basically have two options:

(1) use log4net 1.2.11 instead.

(2) configure your application to use the old CAS security model.

Stefan