2

I'm trying to deploy my C# ASP.Net app to my hosting site. The problem is I have 2 C++ dlls that the app uses, but with shared hosting they can't be in the bin folder. They've been referenced in the project fom a folder called 'bin_native'. The app runs on my machine with using the probing privatePath in the runtime section of the web.config and Assembly directives at the top of my Default.aspx file. But it won't run on the server like that. It can't find the dlls when parsing the default.aspx when the site loads, with an error at the 2 Assembly directives at the top of that file.

So I'm trying to add references to the dlls in the system.webserver section of the web.config. Support for the site said if I can do that maybe the app can use a separate bin folder that is located in the parent directory of my sites wwwroot folder (where the ASP.Net bin folder is). That way the app can find the dlls.

But I can't get the system.webserver section correct without errors. When I test on my machine I get the following error:

Server Error in '/' Application.

Could not load file or assembly 'find_duplicates, Version=0.0.0.0, Culture=neutral, PublicKeyToken=e02ee5289fcc8248' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

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.IO.FileLoadException: Could not load file or assembly 'find_duplicates, Version=0.0.0.0, Culture=neutral, PublicKeyToken=e02ee5289fcc8248' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Here are the changes in my project I've made so far:

Default.aspx:

<%@ Assembly Name="find_duplicates" %>
<%@ Assembly Name="trim_combos" %>

Web.config:

 <system.webServer>

    <modules runAllManagedModulesForAllRequests="true">

     <add name="find_duplicates" type="find_dups.find_duplicates, find_duplicates,Version=0.0.0.0, Culture=neutral, PublicKeyToken=e02ee5289fcc8248"  />

      <add name="trim_combos" type="trim_coms.trim_combos, trim_combos, Version=0.0.0.0, Culture=neutral, PublicKeyToken=e02ee5289fcc8248"  />

     </modules>

    <validation validateIntegratedModeConfiguration="false" />

  </system.webServer>

 <runtime>  

    <dependentAssembly>

       <assemblyIdentity name="find_dups.find_duplicates.find_duplicates" publicKeyToken="e02ee5289fcc8248" culture="neutral" />

    </dependentAssembly>

    <dependentAssembly>

        <assemblyIdentity name="trim_coms.trim_combos.trim_combos" publicKeyToken="e02ee5289fcc8248" culture="neutral" />

    </dependentAssembly> 



   <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

        <probing privatePath="bin_native"/>

   </assemblyBinding>

</runtime>

My dlls are defined in the header files as:

find_duplicates dll

namespace   find_dups
class       find_duplicates

trim_combos   dll

namespace   trim_coms
class       trim_combos

I'm on Windows 7 64 bit running IIS in Integrated Pipeline mode. That's why I'm using the system.webserver section instead of the the system.web section in the web.config.

Any help with this would be greatly appreciated. Thanks in advance.

te7
  • 601
  • 1
  • 6
  • 23
  • Could you try one of the following: Either remove the Version, Culture and PublicKeyToken from the section Or in your section, add a (for both DLLs) You could also turn on assembly binding log (fuslog) and see exactly where the bind is failing: http://stackoverflow.com/a/1527249/190476 – Sudhanshu Mishra Dec 08 '14 at 12:09
  • I tried removing the extra items from the modules section but it gave me a runtime error "Could not load type" when the page loads. I tried bindingRedirect with no luck. How do I find the dll version correctly? I tried the runtime version 4.0.30319 listed in the properties of the referenced dlls in the project. Is this the correct version? Or do I need to use Powershell to find the correct version? The problem with the system using an older dlls instead the ones in the project is that the old dlls don't have a namespace and a class. But the new ones do. Can I reference the dlls without these? – te7 Dec 08 '14 at 18:17
  • I used Powershell to get the dll versions. For my project dll when I use [System.Reflection.AssemblyName]::GetAssemblyName("find_duplicates.dll").Version I get 0.0.0.0. But when I use [System.Reflection.Assembly]::LoadFrom("find_duplicates.dll").GetName().Version I get 4.0.30319. What's the meaning of this? Plus it said it's not in the GAC. Should I add it? – te7 Dec 08 '14 at 22:05
  • I'm trying the modules section now without the extra info. It now is: where the type is "namespace.class". But now I get the runtime error when the page loads of "Could not load type". I used Powershell to get the version info on the older dlls and the newer dlls. The versions were the same. But the older versions didn't have a namespace and class. Could this be the source of the error? If the runtime is using the older dlls then it can't find the type because there is none. Where do I go from here? – te7 Dec 08 '14 at 23:52
  • For now I commented out the system.webserver section in the web.config and the app runs good on my machine. When I publish to my shared hosting site the page loads and all of the options work except the 2 that use the dlls. It gets the error "Can't find dlls". I'm using the probing privePath in the runtime section of the web.config to find the dlls in the bin_native folder and that works on my machine, but not on the hosting site. I wonder why. The app finds a folder named Files in the root folder to find input text files and output html files. Why won't using the bin_native folder work? – te7 Dec 09 '14 at 00:21
  • the two versions you see are the assembly version (0.0.0.0) and the target .NET framework version (4.0.30319). If you add an assembly to GAC, you don't need to specify where to load it from as assembly probing would look in GAC – Sudhanshu Mishra Dec 09 '14 at 06:50
  • But how would that work on a shared hosting server? Can they add a dll to their GAC on the server? – te7 Dec 09 '14 at 10:05
  • Sure, I don't know the particular policies of your provider, but adding an assembly to GAC is pretty straightforward. For C++ DLLs, you'll need to embed them in an assembly first: http://msdn.microsoft.com/en-us/library/thzbdxx7.aspx then add the assembly to GAC – Sudhanshu Mishra Dec 09 '14 at 10:57
  • I added the dlls to the GAC on my machine. Still same errors. The dlls weren't built as managed in Visual Studio C++. Do they need to be for system.webserver to see the namespace and class of the dlls? – te7 Dec 09 '14 at 16:59
  • Do the dlls need to be built with the /CLR option to allow access to the namespace and class by the web config? – te7 Dec 09 '14 at 19:31

1 Answers1

1

I got it to work. My dlls are not managed (they're native modules) so it couldn't load the types for them, even though they had a class and a namespace. Apparently for native modules you just use the add name, with nothing else, as follows:

<system.webServer>

    <globalModules>

      <add name="find_duplicates"/>

    </globalModules>

  </system.webServer>
te7
  • 601
  • 1
  • 6
  • 23