Compile Error: log4net:ERROR Failed to initialize configuration file watcher for file

m.saman's Avatar

m.saman

13 Sep, 2018 01:03 PM

Hello during compilation at VS2017 I got this strange errors.
I can't found any solution anywhere, please help.

[PostSharp30] C:\BuildAgent\work\fc6b0564b1ce8139\Sources\packages\PostSharp.5.0.55\build\PostSharp.targets(323, 5): log4net:ERROR Failed to initialize configuration file watcher for file [C:\ProgramData\PostSharp\5.0.55\bin.Release\config\log4net.xcf.config.xml]
[14:47:37] [PostSharp30] C:\BuildAgent\work\fc6b0564b1ce8139\Sources\packages\PostSharp.5.0.55\build\PostSharp.targets(323, 5): System.ArgumentException: The directory name C:\ProgramData\PostSharp\5.0.55\bin.Release\config is invalid.
[14:47:37] [PostSharp30] C:\BuildAgent\work\fc6b0564b1ce8139\Sources\packages\PostSharp.5.0.55\build\PostSharp.targets(323, 5): at System.IO.FileSystemWatcher.set_Path(String value)
[14:47:37] [PostSharp30] C:\BuildAgent\work\fc6b0564b1ce8139\Sources\packages\PostSharp.5.0.55\build\PostSharp.targets(323, 5): at log4net.Config.XmlConfigurator.ConfigureAndWatchHandler..ctor(ILoggerRepository repository, FileInfo configFile)
[14:47:37] [PostSharp30] C:\BuildAgent\work\fc6b0564b1ce8139\Sources\packages\PostSharp.5.0.55\build\PostSharp.targets(323, 5): at log4net.Config.XmlConfigurator.InternalConfigureAndWatch(ILoggerRepository repository, FileInfo configFile)

  1. Support Staff 1 Posted by PostSharp Techn... on 13 Sep, 2018 02:56 PM

    PostSharp Technologies's Avatar

    Hello,

    please check our documentation and sample to see if you've followed all steps for setting up the log4net logging back-end correctly.
    http://doc.postsharp.net/log4net
    http://samples.postsharp.net/f/PostSharp.Samples.Logging.Log4Net/

    If you don't find any difference, we'd need a sample project reproducing the issue to investigate.

    Please note that support for PostSharp 5.0 has ended on September 10. See https://www.postsharp.net/support/policies for details.

    I recommend to upgrade to PostSharp 6.0.

    Best regards,
    -tony

  2. 2 Posted by m.saman on 13 Sep, 2018 04:20 PM

    m.saman's Avatar

    I update NuGet packages to latest 6.0.26.
    At VisualStudio2017 I'm able to compile OK. But with TeamCity MSBuild agent, I get very strange error now:
    [PostSharpCore] PostSharpCompile (5s)
    [18:07:46] [PostSharpCompile] Merging assembly binding policy file C:\BuildAgent\work\fc6b0564b1ce8139\Sources\xcf\obj\Release\PostSharp\postsharp.app.config.
    [18:07:46] [PostSharpCompile] Executing "C:\ProgramData\PostSharp\6.0.26\bin.Release\net471\postsharp-x86.exe" /config obj\Release\PostSharp\postsharp.merged.app.config /path "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Microsoft\Microsoft.NET.Build.Extensions\net461\lib" /path "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Microsoft\Microsoft.NET.Build.Extensions\net462\lib" /path "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Microsoft\Microsoft.NET.Build.Extensions\net47\lib" /path "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Microsoft\Microsoft.NET.Build.Extensions\net471\lib" obj\Release\Before-PostSharp\xcf.exe C:\BuildAgent\work\fc6b0564b1ce8139\Sources\xcf\obj\Release\PostSharp\postsharp.config /NoLogo /cancel:Local\postsharp-cancel-d72b69e7-9e4b-4321-819c-c65ce8a15ccd
    [18:07:50] [PostSharpCompile] POSTSHARP error: Unhandled exception (postsharp-x86.exe 6.0.26 release | .NET Framework 4.7.1): Cannot find the assembly 'mscorlib, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089'. See below for details.
    [18:07:51] [PostSharpCompile] POSTSHARP PostSharp.Sdk.CodeModel.Binding.AssemblyLoadException: Cannot find the assembly 'mscorlib, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089'.
    [18:07:51] [PostSharpCompile] POSTSHARP at PostSharp.Sdk.CodeModel.Domain.GetAssembly(IAssemblyName assemblyName, BindingOptions bindingOptions, LoadAssemblyOptions loadAssemblyOptions) in ^4j4eG+IaRkPW:line 410
    [18:07:51] [PostSharpCompile] POSTSHARP at PostSharp.Sdk.CodeModel.Domain.FindTypeDefinition(AssemblyQualifiedTypeName assemblyQualifiedTypeName, BindingOptions bindingOptions) in ^4j4eG+IaRkPW:line 377
    [18:07:51] [PostSharpCompile] POSTSHARP at PostSharp.Sdk.CodeModel.TypeRefDeclaration.GetTypeDefinition(BindingOptions bindingOptions) in ^R8LD/aClHM7K:line 343
    [18:07:51] [PostSharpCompile] POSTSHARP at PostSharp.Sdk.CodeModel.ModuleDeclaration.^ZqXSbd+/(String _0, String _1, BindingOptions _2) in ^n88jyR5amO7i:line 1509
    [18:07:51] [PostSharpCompile] POSTSHARP at PostSharp.Sdk.CodeModel.ModuleDeclaration.FindType(String fullTypeName, BindingOptions bindingOptions) in ^n88jyR5amO7i:line 1552
    [18:07:51] [PostSharpCompile] POSTSHARP at ^7W5SDrB/I3hP.^IdhW9qc1(String _0) in ^5yeY5aJI2VBa:line 116
    [18:07:51] [PostSharpCompile] POSTSHARP at PostSharp.Sdk.Binary.ModuleReader.ImportPermissionSet(Int32 _0, ISecurable _1) in ^/3jP/AkXycOn:line 3566
    [18:07:51] [PostSharpCompile] POSTSHARP at PostSharp.Sdk.Binary.ModuleReader.ImportPermissionSets() in ^/3jP/AkXycOn:line 3521
    [18:07:51] [PostSharpCompile] POSTSHARP at PostSharp.Sdk.Binary.ModuleReader.ReadModule(Boolean _0) in ^/3jP/AkXycOn:line 371
    [18:07:51] [PostSharpCompile] POSTSHARP at PostSharp.Sdk.CodeModel.Domain.LoadAssembly(String assemblyLocation, LoadAssemblyOptions options) in ^4j4eG+IaRkPW:line 260
    [18:07:51] [PostSharpCompile] POSTSHARP at PostSharp.Sdk.Extensibility.Project.^pFnf8wEt(ProjectInvocationParameters _0) in ^wJ3oIHJDddm/:line 604
    [18:07:51] [PostSharpCompile] POSTSHARP at PostSharp.Sdk.Extensibility.Project.LoadProject(ProjectInvocationParameters projectInvocationParameters, Domain& domain) in ^wJ3oIHJDddm/:line 562
    [18:07:51] [PostSharpCompile] POSTSHARP at PostSharp.Hosting.PostSharpObject.InvokeProject(ProjectInvocation projectInvocation) in D:\src\PostSharp-5\Core\PostSharp.Hosting\PostSharpObject.cs:line 260
    [18:07:51] [PostSharpCompile] POSTSHARP at PostSharp.Hosting.Program.ExecuteImpl() in D:\src\PostSharp-5\Core\PostSharp.Hosting\Program.cs:line 851

  3. 3 Posted by m.saman on 13 Sep, 2018 04:20 PM

    m.saman's Avatar

    [18:07:50] [PostSharpCompile] POSTSHARP error: Unhandled exception (postsharp-x86.exe 6.0.26 release | .NET Framework 4.7.1): Cannot find the assembly 'mscorlib, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089'. See below for details.
    [18:07:51] [PostSharpCompile] POSTSHARP PostSharp.Sdk.CodeModel.Binding.AssemblyLoadException: Cannot find the assembly 'mscorlib, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089'.

  4. 4 Posted by m.saman on 14 Sep, 2018 09:06 AM

    m.saman's Avatar

    OK, so problem with 6.* version was in TargetFramework version, I must add "/p:TargetFrameworkVersion=v4.7.1" parametr to get it run.
    Problem with log4net. I don't use any PostSharp logging in project, so it is very strange. I use log4net only internally in code.
    Problem with log4net error was solved by manually creating "config" folder under "C:\ProgramData\PostSharp\6.0.26\bin.Release\net471\".

    I do not understand why it is, but it was only solution to get thing runs to build it over msbuild from command line.

  5. 5 Posted by m.saman on 14 Sep, 2018 09:09 AM

    m.saman's Avatar

    My problem is that our project log4net xml config file is in config subdirectory. But I don't understand why PostSharp reflect this, when we don't use log4net for PostSharp. Alse strange is, why when I compile it from VS2017 IDE is OK, even without creating config folder under PostSharp programdata folder. When I compile it from msbuild command line, only way is to create config subfolder manually.

  6. Support Staff 6 Posted by PostSharp Techn... on 14 Sep, 2018 03:45 PM

    PostSharp Technologies's Avatar

    Hello,

    thank you for clarifying the situation.

    Regarding the issue with TargetFrameworkVersion property: Could you please share your project file (.csproj) with us? Do you have .NET Framework 4.7.1 targeting pack installed on your build agent?

    Regarding the log4net issue: This might be caused by some initialization code like a static constructor, which is being executed by PostSharp in build time. You may skip log4net initialization completely by checking the value of PostSharpEnvironment.IsPostSharpRunning property. This property is true when your code is running in build-time and false when it's running in run-time.

    Best regards,
    -tony

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac