1

Closed

QueryableAttribute reports assembly load error in Dev11 unit test project

description

Repro steps:
  1. Create MVC4 Web API project and add web api controller
  2. Install OData package from latest myget feed: http://www.myget.org/F/aspnetwebstacknightly/
  3. Apply [Queryable] to get action
  4. Create unit test project
  5. Add project reference to previous one and add OData package from myget feed
  6. Add test code:
    [TestMethod]
    public void TestMethod1()
    {
        var config = new HttpConfiguration();
        config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
        WebApiConfig.Register(config);
        var server = new HttpServer(config);
    
        HttpClient client = new HttpClient(server);
        var response = client.GetAsync("http://localhost/api/Blah").Result;
    
        Console.WriteLine(response.Content.ReadAsStringAsync().Result);
    }
  7. Run it and it reports error:
    System.IO.FileLoadException occurred
    HResult=-2146234304
    Message=Could not load file or assembly 'Microsoft.Data.Edm, Version=5.0.1.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)
    Source=System.Web.Http.OData
    FileName=Microsoft.Data.Edm, Version=5.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
    FusionLog==== Pre-bind state information ===
    LOG: User = REDMOND\hongyes
    LOG: DisplayName = Microsoft.Data.Edm, Version=5.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
    (Fully-specified)
    LOG: Appbase = file:///c:/users/hongyes/documents/visual studio 2012/Projects/MvcApplication1/UnitTestProject1/bin/Debug
    LOG: Initial PrivatePath = NULL

Calling assembly : System.Web.Http.OData, Version=0.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.

LOG: This bind starts in default load context.
LOG: Using application configuration file: c:\users\hongyes\documents\visual studio 2012\Projects\MvcApplication1\UnitTestProject1\bin\Debug\UnitTestProject1.dll.config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Microsoft.Data.Edm, Version=5.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: Attempting download of new URL file:///c:/users/hongyes/documents/visual studio 2012/Projects/MvcApplication1/UnitTestProject1/bin/Debug/Microsoft.Data.Edm.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Build Number
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

StackTrace:
   at System.Web.Http.QueryableAttribute.OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
   at System.Web.Http.Filters.ActionFilterAttribute.CallOnActionExecuted(HttpActionContext actionContext, HttpResponseMessage response, Exception exception)
InnerException:

file attachments

Closed Oct 5, 2012 at 12:09 AM by HongmeiG
Given this is a VS issue, we can't fix this in our layer. Please use RaghuRam's suggestion to work around it.

comments

raghuramn wrote Sep 10, 2012 at 9:21 PM

Looks like a bug with VS2012. Assembly binding redirects are not used if the solution doesn’t have a testsettings file. More here,

http://social.msdn.microsoft.com/Forums/en-US/vsunittest/thread/234926d1-42c0-4ebb-af39-1626e72f6c39

I have verified that the tests run after adding the testsettings file.