简体   繁体   中英

Error in visual studio setup project-Could not load file or assembly log4net or one of it's dependencies. The system cannot find the file specified

I know there are lots of thread and question out there. So, Please let me clarify the situation here.

I am working on Ms-Word addin using visual c#, vsto and add-in express framework . I added a log4net assmeble from nuget package manager. When I try to build or debug the project. It works just fine.

But just when I try to create setup project using add-in express extension ( right click on project > add-in express> create setup project ). It gives me an error (in a popup) just after the click

Could not load file or assembly "log4net, Version=2.0.8.0 Cultural=neutral,PublicKeyToken=669e0ddf0bb1aa2a" or one of it's dependencies. The system cannot find the file specified.

I have checked the version, multiple references of log4net.dll in my project, path in package.config and in the project.csproj file. All these things are of no issue.

When I try to create a fresh similar project from scratch add log4net. it worked. But not with the current project. What would be the possible cause?

I would appreciate any help. I am really got stuck at this.

Following are the configuration :

Project target framework is " .Net framework 4 "

package.config

<packages>
  <package id="Apache.NMS" version="1.7.1" targetFramework="net40" />
  <package id="Apache.NMS.ActiveMQ" version="1.7.2" targetFramework="net40" />
  <package id="log4net" version="2.0.8" targetFramework="net40" />
  <package id="Newtonsoft.Json" version="10.0.3" targetFramework="net40" />
</packages>

app.config

<configSections>    
...
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL" />
...
</configSections>
<log4net>
      <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
        <param name="File" value="logFile.log"/>
        <param name="DatePattern" value="'logFile_'yyyy-MM-dd'.log'"/>
        <preserveLogFileNameExtension value="true" />
        <appendToFile value="true" />
        <rollingStyle value="Size" />
        <maxSizeRollBackups value="5" />
        <maximumFileSize value="5MB" />
        <staticLogFileName value="true" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%date [%thread] %level %logger - %message %newline %exception" />
        </layout>
      </appender>
      <root>
        <level value="INFO"/>
        <appender-ref ref="RollingFileAppender"/>
      </root>
    </log4net>

Product.csproj

<ItemGroup>
<Reference Include="Accessibility" />
<Reference Include="AddinExpress.MSO.2005, Version=8.2.4371.0, Culture=neutral, PublicKeyToken=4416dd98f0861965, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>..\..\..\..\..\..\..\Program Files (x86)\Add-in Express\Add-in Express for .NET\Bin\AddinExpress.MSO.2005.dll</HintPath>
</Reference>
<Reference Include="AddinExpress.OL.2005, Version=8.2.4371.2005, Culture=neutral, PublicKeyToken=e69a7e0f3592d2b8, processorArchitecture=MSIL" />
<Reference Include="AddinExpress.ToolbarControls.2005, Version=8.2.4371.2005, Culture=neutral, PublicKeyToken=16211aef6795d6cc, processorArchitecture=MSIL" />
<Reference Include="AddinExpress.WD.2005, Version=7.5.4072.2005, Culture=neutral, PublicKeyToken=e69a7e0f3592d2b8, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="ADXOLWizard.2005, Version=8.2.4371.2005, Culture=neutral, processorArchitecture=MSIL" />
<Reference Include="Apache.NMS">
  <HintPath>..\packages\Apache.NMS.1.7.1\lib\net40\Apache.NMS.dll</HintPath>
</Reference>
<Reference Include="Apache.NMS.ActiveMQ">
  <HintPath>..\packages\Apache.NMS.ActiveMQ.1.7.2\lib\net40\Apache.NMS.ActiveMQ.dll</HintPath>
</Reference>
<Reference Include="log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
  <HintPath>..\packages\log4net.2.0.8\lib\net40-full\log4net.dll</HintPath>
  <Private>True</Private>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Microsoft.Office.Interop.Outlook, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL">
  <EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="Microsoft.Office.Interop.Word, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL">
  <EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="Microsoft.Office.Tools.Word, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
  <EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="Microsoft.Vbe.Interop, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL">
  <EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
  <HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net40\Newtonsoft.Json.dll</HintPath>
  <Private>True</Private>
</Reference>
<Reference Include="Office, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL">
  <EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System" />
<Reference Include="System.configuration" />
<Reference Include="System.Configuration.Install" />
<Reference Include="System.Data" />
<Reference Include="System.DirectoryServices" />
<Reference Include="System.DirectoryServices.AccountManagement" />
<Reference Include="System.Drawing" />
<Reference Include="System.Management" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Web" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xaml" />
<Reference Include="System.Xml" />
<Reference Include="UIAutomationProvider" />
<Reference Include="WindowsBase" />
<Reference Include="WindowsFormsIntegration" />

I had this issue before. In my case the problem was that different versions of the same NuGet were used by different components. The solution was to add assembly binding, basically set up a mapping, saying "when any version of log4net is referenced from 0.0.0.0 up to 2.0.8.0, just use 2.0.8.0".

Try adding the following block in your app.config . If it's already there, ensure the versions are correct (when updating NuGet packages, sometimes it gets out of sync).

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity name="log4net" publicKeyToken="669e0ddf0bb1aa2a" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-2.0.8.0" newVersion="2.0.8.0" />
        </dependentAssembly>
        ...
    </assemblyBinding>
</runtime>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

Related Question Exception: Could not load file or Assembly XXXX or one of it's dependencies. The system cannot find the file specified Could not load file or assembly 'Extensions' or one of its dependencies. The system cannot find the file specified Could not load file or assembly 'Ajax' or one of its dependencies. The system cannot find the file specified A specific: Could not load file or assembly 'xxxx' or one of its dependencies. The system cannot find the file specified Could not load file or assembly 'XXX' or one of its dependencies. The system cannot find the file specified Could not load file or assembly or one of its dependencies. The system cannot find the file specified. (No GAC allowed) Could not load file or assembly 'ServiceStack' or one of its dependencies. The system cannot find the file specified Could not load file or assembly 'Logging.SNLLoggingStandard3' or one of its dependencies. The system cannot find the file specified Could not load file or assembly 'Elmah' or one of its dependencies. The system cannot find the file specified Could not load file or assembly 'System.Net.Http.Formatting' or one of its dependencies. The system cannot find the path specified
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM