locked
Could not load file or assembly 'log4net' or one of its dependencies. An attempt was made to load a program with an incorrect format. RRS feed

  • Question

  • Some background...

    My web server is running Windows Server 2008 R2 (x64).  My development machine is running Windows 7 (x86).  Previously, I was using Visual Studio 2008 - and Crystal Reports for VS 2008.  The CR x64 runtime was installed on the server.  Everything published and worked fine.

    I recently upgraded to Visual Studio 2010 - and Crystal Reports for VS 2010.  I installed the new runtime on the server.  After publishing the upgraded project, I get this error:

    Could not load file or assembly 'log4net' or one of its dependencies. An attempt was made to load a program with an incorrect format.

    Yes, I compile for Any CPU... it wasn't a problem before, so I don't think it should be a problem now.  Furthermore, log4net is not directly referenced by my project (yet it does end up in the bin).  I have made sure that all of the Crystal Reports references have "Copy Local" set to false.

    As a workaround, if I delete the log4net.dll from the bin directory on the server after the site is published - everything works fine.  If the solution was just to prevent log4net from being copied - I'd be ok with that... just tell me how :)

    There are several similar log4net issues on other forums - I have read them, and haven't found a solution.

    Tuesday, May 10, 2011 2:49 PM

All replies

  • Hello,

    See this SAP Crystal Reports forum post for a solution.

    We have discovered that you must set your project for either x86 or x64, not both. The install detects what the OS and hardware support and simply installs the x64 runtime only. If you app pool is running in as x86 this is going to cause problems so it's recommended you build for specific bit versions.

    The link also links to a few Microsoft articles on why...

    Thank you

    Don


    Don Williams
    • Marked as answer by abs Struct Wednesday, May 11, 2011 6:51 PM
    • Unmarked as answer by abs Struct Wednesday, May 11, 2011 6:58 PM
    • Proposed as answer by SAPDon Friday, July 22, 2011 8:25 PM
    Tuesday, May 10, 2011 8:53 PM
  • Well, in theory, I understand what you're suggesting; however, both the installed SAP Crystal Reports runtime and the App Pool are x64 on the target server.  Is is possible that the log4net that is being copied over is x86?  Keep in mind that my development workstation is x86 - and I publish rather than create an install.

    There are several complexities involved in specifying the build to be x64 - for instance some referenced COM assemblies are x86 on my development box - and VS won't complains about it when trying to explicitely compile x64.  Using Any CPU works because the COM assembly on the target server is x64 (or at least I believe that is why it works).


    Wednesday, May 11, 2011 7:04 PM
  • Hi abs,

    To clarify have you installed the x64 MSI on your WEB server? Publishing simply pushes your app onto the server, you still need to deploy the CR runtime.

    On your DEV PC the IDE is only 32 bit and you may be using Cassini as the web server ( built into VS Studio for testing only ) so running from the IDE you are still using 32 bits.

    Here are the links to get the SP1 redist package if you need them:

    Download Crystal Reports for Visual Studio 2010

    Also, check the links on the SAP forum to MS kbases and articles.

    Or if you simply want to rename that log4net dll and close the post that works also. It's only there for debugging anyways and not sure why SAP Deployment team includes it.

    Thanks again

    Don

     


    Don Williams
    Wednesday, May 11, 2011 7:51 PM
  • Hi abs,

    To clarify have you installed the x64 MSI on your WEB server? Publishing simply pushes your app onto the server, you still need to deploy the CR runtime.

    On your DEV PC the IDE is only 32 bit and you may be using Cassini as the web server ( built into VS Studio for testing only ) so running from the IDE you are still using 32 bits.

    Here are the links to get the SP1 redist package if you need them:

    Download Crystal Reports for Visual Studio 2010

    Also, check the links on the SAP forum to MS kbases and articles.

    Or if you simply want to rename that log4net dll and close the post that works also. It's only there for debugging anyways and not sure why SAP Deployment team includes it.

    Thanks again

    Don

     


    Don Williams
    Wednesday, May 11, 2011 7:51 PM
  • I have installed the x64 runtime on the web server.

    I understand that my dev pc is 32 bit - all issues mentioned were in reference to running the web site on the web server.

    Is there any way to prevent log4net.dll from being copied to the bin directory - either at compile time, or when publishing the site?  I have seen others mention an option to exclude files on the Publishing tab in the project properties - but I fail to see that option.

    Wednesday, May 11, 2011 7:56 PM
  • If you go to that SAP forum post the very first post is how to excluded parts:

    There have been a number of posts on the forums lately about problems with log4net.dll and other files like CrystalDecisions.ReportAppServer.CommonObjectModel. These have all been tied together with ClickOnce deployments, or adding the Crystal Reports for Visual Studio 2010 runtime as a prerequisite.

    I recently found some settings in Visual Studio that have an impact on this.

    - Go into your project Properties.
    - Then go to the Publish tab.
    - Click the Application Files button.
    - Select to Exclude any file with CrystalDecisions or BusinessObjects in the name. Plus exclude log4net.dll.
    - Click OK
    - Rebuild your application, then republish it to your site or file share to be installed by your clients.

    Thanks

    Don


    Don Williams
    Wednesday, May 11, 2011 8:03 PM
  • Problem is, I don't see an 'Application Files' button when I go to the 'Package/Publish Web' tab.

    Thursday, May 12, 2011 8:54 PM
  • See the KBase 1550854 - \"Could not load file or assembly 'log4net' or one of its dependencies\" Error when building Visual Studio 2010 solution utilizing the Crystal Reports .NET Runtime.

    If that resolves your issue. I believe your problem is you need to create a deployment project, it's not part of your app properties.

    Don

     

     


    Don Williams
    Saturday, May 14, 2011 4:19 PM
  • That KB pertains to a different issue relating to log4net.dll issues.  The error it addresses occurs at compile time - not after the site has been published.

    In short -

    I build using 'Any CPU'.

    32-bit log4net.dll is copied to the bin directory when I publish the web site to a 64-bit app pool.

    I delete log4net.dll... and move on with life. 

     

    If anyone can tell me how to prevent log4net.dll from being copied - that'd be wonderful.  As mentioned previously, 'Application Files' is not an option on the 'Package/Publish Web' tab in my project properties.

    Monday, May 16, 2011 2:29 PM
  • OK so I believe the issue is depending on how you created your app, WEB App or WEB Service depends on how it's all built and published. If you create a WEB Service then the web site compiles the dependencies at start up. So what this means is you have told the app to use the 32 bit log4net...

    Remove the 32 bit CR runtime if you have deployed it and then it should use the 64 bit runtime in your app pool.

    Thanks again

    Don


    Don Williams
    Monday, May 16, 2011 4:37 PM
  • As previously specified, the x64 CR runtime is installed on the web server.  The issue is that my development machine is x86 - and the x86 version of log4net.dll is being copied to the web server when I publish the web app.

    Monday, May 16, 2011 8:19 PM
  • As I also noted depending on the way you create your app depends on if the dependency is required or not. I any event the issue is resolved as you had noted to simply delete the log4net dll and which is also noted in the Kbase article.

    If you create a WEB site then the dll's are not compiled into the app dll and then you don't get the error/message. All depends on how you start off. There are prerequisites for windows applications also, just one of those things to get used to preconfiguring now that we support both platforms.

    Thank you

    Don


    Don Williams
    Monday, May 16, 2011 8:56 PM
  • Ok - so then the real question becomes - how do I prevent log4net.dll from being copied when publishing the web app?  Deleting the dll manually after publish is an extra step - and gets to be a pain in the butt after a while.

    I'm not trying to be a stickler here - but let's face it, if someone else comes upon this thread, 'manually delete the dll after publish' is kind of a poor end-solution to the problem.

    Tuesday, May 17, 2011 1:33 PM
  • Exclude it from your dependencies in your app is the only way other than manually deleting it.
    Don Williams
    Tuesday, May 17, 2011 11:49 PM
  • HI abs struct,

                      log4net.dll problem arise in your application bcoz when you install SAP crystal report, may it was not installed correctly. as a reason your crystal report

    can't load. Hare is a given link in which i replay the post, for SAP crystal report for VS-2010. you will get hare step by step help for crystal report VS-2010 setup.

      http://social.msdn.microsoft.com/Forums/en-US/vscrystalreports/thread/e649d4bf-e131-4bdb-96da-5bd541b6e8a9

     

                    Hope it will help for your.


    Regards atik sarker
    Thursday, May 19, 2011 12:17 PM
  • I have set all CrystalDecisions references so that CopyLocal is false.  I would have thought this would be enough... but I would obviously be wrong.  Given that I have a Web App project, not a web deployment, I don't think there is any way to exclude dependencies for publishing the Web App.  Though, if you know how - please share :)

    I found this: http://blogs.msdn.com/b/webdevtools/archive/2010/04/22/web-deployment-excluding-files-and-folders-via-the-web-application-s-project-file.aspx

    So I tried adding <ExcludeFilesFromDeployment> here:

    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
        <DebugType>pdbonly</DebugType>
        <Optimize>true</Optimize>
        <OutputPath>bin\</OutputPath>
        <ExcludeFilesFromDeployment>log4net.dll</ExcludeFilesFromDeployment>
        <DefineConstants>TRACE</DefineConstants>
        <ErrorReport>prompt</ErrorReport>
        <WarningLevel>4</WarningLevel>
        <PlatformTarget>AnyCPU</PlatformTarget>
        <FilesToIncludeForPublish>OnlyFilesToRunTheApp</FilesToIncludeForPublish>
        <PackageAsSingleFile>false</PackageAsSingleFile>
      </PropertyGroup>

    But... that didn't work either...

    I also tried clicking 'Show All Files' in Solution Explorer, Including 'log4net.dll' (because it is not in the project by default), and then setting 'Copy Local' to False... still no dice.

    In the 'Packade/Publish Web' tab in the project properties, 'Items to deploy' is set to 'Only files needed to run this application'.  Given that log4net.dll wasn't even included in the project, I don't quite understand why Visual Studio would decide to copy it when publishing the Web App.

    Saturday, May 21, 2011 1:43 PM