none
App_Code Assembly error

    Question

  • I have a WCF service created and it has Service.cs and IService.cs classes in App_Code folder and reference some dll. When i host the website in my dev server, it gives me some wierd error. Can someone suggest me what can be done to fix this. Framework in dev server is 2.0. I did my application in VS 2010.

    Server Error in '/XYZ' Application.

    Could not load file or assembly 'App_Code' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.BadImageFormatException: Could not load file or assembly 'App_Code' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Assembly Load Trace: The following information can be helpful to determine why the assembly 'App_Code' could not be loaded.

    WRN: Assembly binding logging is turned OFF.
    To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
    Note: There is some performance penalty associated with assembly bind failure logging.
    To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
    

    Stack Trace:

    [BadImageFormatException: Could not load file or assembly 'App_Code' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.]
      System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) +0
      System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection) +43
      System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +127
      System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +142
      System.Reflection.Assembly.Load(String assemblyString) +28
      System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +46
    
    [ConfigurationErrorsException: Could not load file or assembly 'App_Code' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.]
      System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +613
      System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +203
      System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai) +105
      System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +178
      System.Web.Compilation.WebDirectoryBatchCompiler..ctor(VirtualDirectory vdir) +163
      System.Web.Compilation.BuildManager.BatchCompileWebDirectoryInternal(VirtualDirectory vdir, Boolean ignoreErrors) +53
      System.Web.Compilation.BuildManager.BatchCompileWebDirectory(VirtualDirectory vdir, VirtualPath virtualDir, Boolean ignoreErrors) +175
      System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath) +86
      System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile) +261
      System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile) +101
      System.Web.Compilation.BuildManager.GetVPathBuildResult(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile) +83
      System.Web.Compilation.BuildManager.GetCompiledCustomString(String virtualPath) +27
      System.ServiceModel.HostingManager.GetCompiledCustomString(String normalizedVirtualPath) +134
      System.ServiceModel.HostingManager.CreateService(String normalizedVirtualPath) +23
      System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath) +42
      System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +479
    
    [ServiceActivationException: The service '/TermsPrivacyPolicy/Service.svc' cannot be activated due to an exception during compilation. The exception message is: Could not load file or assembly 'App_Code' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded..]
      System.ServiceModel.AsyncResult.End(IAsyncResult result) +11592858
      System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +194
      System.ServiceModel.Activation.HostedHttpRequestAsyncResult.ExecuteSynchronous(HttpApplication context, Boolean flowContext) +176
      System.ServiceModel.Activation.HttpHandler.ProcessRequest(HttpContext context) +23
      System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
      System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
    

    Tuesday, October 19, 2010 8:43 PM

Answers

  • Possibly the project uses .Net 4.0 and the web server does not support it.

    Try to target your project to .Net 3.5 (in the project properties) or install .net 4 on the server:

    %windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -i


    http://webservices20.blogspot.com/
    WCF Security, Interoperability And Performance Blog
    • Proposed as answer by Yaron NavehMVP Tuesday, October 19, 2010 10:29 PM
    • Marked as answer by kranthi1283 Wednesday, October 20, 2010 3:13 PM
    Tuesday, October 19, 2010 9:45 PM

All replies

  • Possibly the project uses .Net 4.0 and the web server does not support it.

    Try to target your project to .Net 3.5 (in the project properties) or install .net 4 on the server:

    %windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -i


    http://webservices20.blogspot.com/
    WCF Security, Interoperability And Performance Blog
    • Proposed as answer by Yaron NavehMVP Tuesday, October 19, 2010 10:29 PM
    • Marked as answer by kranthi1283 Wednesday, October 20, 2010 3:13 PM
    Tuesday, October 19, 2010 9:45 PM
  • Thanks Yaron,That works.

    But now i get a different error. I'm hosting this in IIS under a website using a classic application pool(v2.0).

    I added a customhostfactory by seeing somewhere.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.ServiceModel.Activation;
    using System.ServiceModel;
    namespace RestfulServices
    {
        /// <summary>
        /// Summary description for CustomHostFactory
        /// </summary>
        public class CustomHostFactory : ServiceHostFactory
        {
            protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
            {
                Uri webServiceAddress = new Uri("http://wdev.xxx.com/Services/xyz/Service.svc");
                ServiceHost webServiceHost = new ServiceHost(serviceType, webServiceAddress);
                return webServiceHost;
            }
        }
    }

     

    I also added this to web.config file

    <system.serviceModel>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true">
          <baseAddressPrefixFilters>
            <add prefix="http://wdev.xxx.com/Services/xyz/Service.svc" />
          </baseAddressPrefixFilters>
        </serviceHostingEnvironment>
        <services>
          <service name="RestfulServices">
            <endpoint address="" binding="wsHttpBinding" contract="RestfulServices.IServiceContract" />
          </service>
        </services>
        </system.serviceModel>

     

    But still i get this error.

    Server Error in '/XYZ' Application.

    This collection already contains an address with scheme http.  There can be at most one address per scheme in this collection.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.InvalidOperationException: This collection already contains an address with scheme http.  There can be at most one address per scheme in this collection.

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Stack Trace:

    [InvalidOperationException: This collection already contains an address with scheme http. There can be at most one address per scheme in this collection. ]
      System.ServiceModel.HostingManager.FilterBaseAddressList(Uri[] baseAddresses, Uri[] prefixFilters) +4070296
      System.ServiceModel.HostingManager.CreateService(String normalizedVirtualPath) +11686697
      System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath) +42
      System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +479
    
    [ServiceActivationException: The service '/XYZ/Service.svc' cannot be activated due to an exception during compilation. The exception message is: This collection already contains an address with scheme http. There can be at most one address per scheme in this collection. .]
      System.ServiceModel.AsyncResult.End(IAsyncResult result) +11592858
      System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +194
      System.ServiceModel.Activation.HostedHttpRequestAsyncResult.ExecuteSynchronous(HttpApplication context, Boolean flowContext) +176
      System.ServiceModel.Activation.HttpHandler.ProcessRequest(HttpContext context) +23
      System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
      System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
    

    Tuesday, October 19, 2010 9:59 PM
  • Try to remove this:

    <add prefix="http://wdev.xxx.com/Services/xyz/Service.svc" />

    the iis already has an address this site is on.


    http://webservices20.blogspot.com/
    WCF Security, Interoperability And Performance Blog
    Tuesday, October 19, 2010 10:18 PM
  • Hey Yaron,

    Thanks for the reply.

    This didn't resolve the issue...Is there anything i need to try like adding something to the handlers or mappings etc...

    Tuesday, October 19, 2010 11:55 PM
  • I got past this error.....but i see some request error

    Request Error


    The server encountered an error processing the request. See server logs for more details.

     

    This past error was gone after i removed the customHostFactory I created and added

    Factory = "System.ServiceModel.Activation.WebServiceHostFactory" but i got this request error....

     

    The complete web.config file i've now is

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
       
     
        <system.web>
        <compilation debug="true">
        
         
        </compilation>
      
      </system.web>
       
       
        <system.serviceModel>
      
        <serviceHostingEnvironment aspNetCompatibilityEnabled="false">
          <baseAddressPrefixFilters>
            <clear/>
            <add prefix="http://wdev.xyz.com/Services/xxx/" />
          </baseAddressPrefixFilters>
        </serviceHostingEnvironment>
      
      </system.serviceModel>

     
     
     
       
        <system.webServer>
            <modules>
                <remove name="EkUrlAliasModule" />
                <remove name="MyDigestAuthenticationModule" />
                <remove name="ServiceModel" />
                <add name="ServiceModel" type="System.ServiceModel.Activation.HttpModule, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" preCondition="managedHandler" />
            </modules>
            <handlers>
               
                <remove name="StaticFile" />
                <remove name="ekdav" />
                <remove name="ek*" />
                <add name="svc-Integrated" path="*.svc" verb="*" type="System.ServiceModel.Activation.HttpHandler, System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" preCondition="integratedMode" />
                <add name="svc-ISAPI-2.0" path="*.svc" verb="*" modules="IsapiModule" scriptProcessor="%Windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" resourceType="Unspecified" preCondition="classicMode,runtimeVersionv2.0,bitness32" />
                <add name="svc-ISAPI-2.0-64" path="*.svc" verb="*" modules="IsapiModule" scriptProcessor="%Windir%\Microsoft.NET\Framework64\v2.0.50727\aspnet_isapi.dll" resourceType="Unspecified" preCondition="classicMode,runtimeVersionv2.0,bitness64" />
                <add name="StaticFile" path="*" verb="*" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" resourceType="Either" requireAccess="Read" />
            </handlers>
            <directoryBrowse enabled="true" />
         
        </system.webServer>
       
    </configuration>

     

     

    If i remove the line <add prefix="http://wdev.xyz.com/xxx/" />, that would give me the address http scheme error. So, I think i need this.

    The same service would work in my local and give the xml output when i navigate to http://localhost/RestfulWS/Service.svc/PP

    but when i navigate to http://wdev.xyz.com/Services/xxx/Service.svc/PP in my server that would give request error and i can't find any error logs in my event viewer related to this issue....

     

    can someone suggest me what i should be doing.

     

    Thanks

    Wednesday, October 20, 2010 3:06 PM