Could not load file or assembly error on server

18,042

Solution 1

Got fixed by adding following references in web.confg file

  1. Microsoft.Owin
  2. Microsoft.Owin.Security.OAuth
  3. Microsoft.Owin.Security
  4. Microsoft.Owin.Security.Cookies

Solution 2

I didn't update web.config file on the server after adding SignalR. Here is what missing:

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
      <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
      <bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
    </dependentAssembly>
  </assemblyBinding>
</runtime>

Solution 3

As it works fine on your local machine there are couple of possible cases, at first check Microsoft.Owin references as there is a case when it is missing on the production environment. https://www.nuget.org/packages/Microsoft.Owin/2.1.0 You can check it at "dependencies" section, make sure Owin library exists and referenced

Then check GAC on both dev and ST machines (it can work fine on dev if you have required version of assembly in GAC on dev but don't have on ST)

For redirection, make sure that you have correct xml namespace

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
         <dependentAssembly>
            <assemblyIdentity name="myAssembly"
                              publicKeyToken="32ab4ba45e0a69a1"
                              culture="neutral" />
            <bindingRedirect oldVersion="1.0.0.0"
                             newVersion="2.0.0.0"/>
         </dependentAssembly>
</assemblyBinding>

that wraps your dependant elements

If after that you still have no success in finding the reason you can try the tool fuslogvw.exe that ships with Visual Studio to get more information about the binding failures.

Share:
18,042

Related videos on Youtube

user615611
Author by

user615611

Updated on September 16, 2022

Comments

  • user615611
    user615611 over 1 year

    I am getting the following error when I deploy my code to our ST server. Same code works fine on my machine and on Dev server but through this error on ST server when we try to access one of the pages in application.

    The error is:

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

    Here is what I have in web.config

    <dependentAssembly>
            <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="Microsoft.Owin.Security.OAuth" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="Microsoft.Owin.Security.Cookies" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
          </dependentAssembly>