autofac / Autofac.Mvc

ASP.NET MVC integration for Autofac

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Get a can not load assembly "System.Web.Mvc, Version=5.1.0.0" error when i put project in a directory name contain "#"

lin2code opened this issue · comments

I'm using Autofac.Mvc 4.0.0.0 and my ASP.NET MVC version is 5.2.3.0. I create a project on desktop, using Autofac it's work. when i copy this project to my project folder(which contain "#") it's get this error.
First I thought this a config/nuget version/framework version/refrence problem. Then i try them all, still get this error. And the project build success but this error appear when the project run.
Finally i found out this error only appear when i put the project in to the specific folder which name contain "#", then i realize it's maybe a Autofac bug. And why i get a error like this, it's nothing relate to a directory issue. Guess it just load 5.1.0.0 version when it try load assembly error.

At first glance this sounds a lot more like a .NET assembly loader issue than something to do specifically with Autofac, but there's not enough information here to determine.

What is the full exception with stack trace? Do you have steps to reproduce the issue or a repro checked in somewhere we can see? Did this work before adding Autofac?

It appears this was also cross posted to StackOverflow, which means we'll need to follow up in two places.

I'm creating a mvc website development template. This is the project MVCWebSite
I put project in "#Test" like this
qq 20161025211905
Then get a exception
exceptioin

If i remove "#" it's work.

qq 20161025212753
qq 20161025212849

If add the "#" back, and comment Autofac register code, it's work again.
qq 20161025211905
qq 20161025213248
qq 20161025213306
qq 20161025213320

The question on StakOverflow is posted by me.

Unfortunately, I'm unable to reproduce the issue.

What I did:

  1. Download the zip of your repo and put it at C:\dev\test\MVCWebSite.
  2. Open C:\dev\test\MVCWebSite\MVCWebSite.sln in Visual Studio 2015.
  3. Update DemoController so it doesn't try to call a database because I don't have your MySQL instances.
  4. Build and start the app - get the home page.
  5. Close Visual Studio 2015.
  6. Rename C:\dev\test\MVCWebSite to ``C:\dev#test\MVCWebSite`.
  7. Open C:\dev\#test\MVCWebSite\MVCWebSite.sln in Visual Studio 2015.
  8. Build and start the app - get the home page.

Something I noticed that's odd about your error screen shot is that the paths for your app don't line up. For example, I see the error occurs in D:\GitHub\MVCWebsite\MVCWebSite\MVCWebSite\Global.asax.cs but the binding failure shows the application itself is in D:\#Test\MVCWebSite\MVCWebSite.

The paths don't line up

In other errors including binding errors the source file is generally in the application. For example, here's a clip of the error I see due to not having your databases:

Path points to app code

This is a strong indicator that the problem isn't with Autofac so much as something you're doing - perhaps pre-compiling the base application and trying to refer to it as an assembly? Perhaps something in the way you're referencing code from a different location? The app is acting as though the binding redirects are potentially in D:\GitHub\MVCWebsite\MVCWebSite\MVCWebSite\web.config but not in D:\#Test\MVCWebSite\MVCWebSite\web.config or something similar.

Given I can't reproduce it and this is very much a binding redirect problem since Autofac does not explicitly load assemblies (e.g., you won't find Autofac doing any Assembly.Load or Assembly.LoadFrom stuff - any on-the-fly assembly loading is occurring due to the .NET runtime), I'm going to conclude there's really nothing we can do here - it's a question for .NET runtime folks that is potentially machine or configuration specific to your setup.

If you are able to come up with a much smaller, much simpler reproduction (no "DAL," no "BLL," unless those things are very specific to reproducing the issue) and are able to reproduce it yourself on other machines, we can try re-opening and figuring it out. In the meantime, I'd look at what's happening in your app to cause the paths to the source files to be messed up.

The odd file path maybe a cache problem, I copy it from D:\GitHub\MVCWebsite\MVCWebSite then open run directly get the odd screen shot, so I remove all obj folders of this project and rebuilt it then get a exception like this.
exception
Anyway it doesn't affect my work now, thanks a lot. I'll test it on other machine and continue figure it out, if found out anything may cause this will let you know.

Hi, i just reproduce it on another machine. And I know why you can't reproduce it. The reason is it's only appear when the "#" is the first char after drive letter eg D:\#some\thing or C:\#some\thing. Hope this will help you.

Finally, I confirm it's a assemblyBinding bug.

    1. Create a new solution in D:\Test with a mvc project Testp and a class library Testc.
    1. Add Nuget pack NewtonSoft.Json version 9.0.0.0 to Testp, add NewtonSoft.Json version 8.0.0.0 to Testc.
    1. Using NewtonSoft.Json in Testc, then using Testc in Testp to call NewtonSoft.Json's method.

First run it will get an exception and warn you add assemblyBinding to web.config, when you added it, it's run success. Then change directory to D:\#Test , this exception jump out.
So, turn out it's Microsoft's bug. I should report it to MS team instead of you, sorry for the inconvenience.