6

I have a simple C#/4.0 console app that reference Log4Net 1.2.13.0 in VS2010.

In debug mode the app compiles and runs fine on my machine. However, as soon as I change to 'Release' I get the error

"Could not load file or assembly 'file:///C:\Users\mike\Documents\Visual Studio 2010\Projects\xxxx\yyyyy\log4net.dll' or one of its dependencies. Operation is not supported."

In the AssemblyInfo.cs I have added the line:

[assembly: log4net.Config.XmlConfigurator(Watch = true)]

According to the configuration mgr, but Debug and Release are set to use platform x86. This is also happening in another C# service application on my laptop, but I thought it easier if stick with getting it working here first.

The app.config file contains a section for:

<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />

Thanks in advance Mike

toadflakz
  • 7,764
  • 1
  • 27
  • 40
mikcatta
  • 191
  • 8
  • 1
    How did you add log4net to your project? Might be worth a try to use the NuGet packetmanager to install Log4Net – Marco Feb 19 '15 at 10:54
  • 2
    Could this have something to do with it? http://stackoverflow.com/questions/21753979/visual-studio-could-not-load-file-or-assembly-operation-is-not-supported-erro – RenniePet Feb 19 '15 at 11:31
  • I changed the app.config to this
    and then it worked. Very frustrating that its not all obvious. Thanks guys
    – mikcatta Feb 19 '15 at 14:55
  • @mikcatta, if that was the solution for you, please add and accept your answer. – matth Feb 24 '15 at 18:22

2 Answers2

1

Changing the type definition in the app.config to specify the fully qualified assembly name resolved the issue for me:

<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a" /> 
Mike Goodwin
  • 8,810
  • 2
  • 35
  • 50
mikcatta
  • 191
  • 8
  • If you're going to mark your own answer as an answer, at least make your answer even minimally useful. Copying your comment above would probably help somebody else attempting to find a simalar answer. – Jack Hughes Mar 02 '15 at 14:27
  • 1
    @JackHughes: He forgot to mark his XML snippet as a code block so it was not visible. Fixed now. – Mike Goodwin Mar 02 '15 at 16:02
0

I too had the same issue. I just checked the Unblock checkbox at the properties of log4net.dll which resolved the issue for me.

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 05 '22 at 01:44