Reputation: 10755
I'm working on a project and decided to go with StructureMap as the IoC, but whenever we try to load the project (MVC 3 by the way) we get this error:
Could not load file or assembly 'StructureMap, Version=2.5.3.0, Culture=neutral, PublicKeyToken=e60ad81abae3c223' or one of its dependencies. The system cannot find the file specified.
In Global.asax I have this code to initialize StructureMap
ObjectFactory.Initialize(
x =>
{
x.ForRequestedType<IUnitOfWorkFactory>()
.TheDefaultIsConcreteType<EFUnitOfWorkFactory>()
.CacheBy(InstanceScope.HttpContext);
x.ForRequestedType(typeof(IRepository<>))
.CacheBy(InstanceScope.HttpContext)
.TheDefaultIsConcreteType(typeof(GenericRepository<>));
});
And have StructureMap in a lib folder I added to the main MVC application. Even when removing all references that I can find I still get this error.
For the record this is the lib folder in the MVC3 structure
And I add reference to the StructureMap.dll (which oddly enough is version 2.6.1 but the error says version 2.5.3.0
] Forgot to mention that I have a custom Controller Factory for StructueMap. Here's the code for the controller factory:
public class StructureMapControllerFactory : DefaultControllerFactory
{
protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
{
try
{
return (controllerType == null) ? null : ObjectFactory.GetInstance(controllerType) as Controller;
}
catch (StructureMapException)
{
System.Diagnostics.Debug.WriteLine(ObjectFactory.WhatDoIHave());
throw;
}
}
}
And here's how I use it in the Global.asax.cs
ControllerBuilder.Current.SetControllerFactory(new StructureMapControllerFactory());
EDIT: I installed StructureMap with NuGet and still get the same error, though NuGet installed a different version (2.6 instead of 2.5) but still get the 2.5 error. So I'm going to offer a bounty to anyone who can help me resolve this issue
EDIT 2 I uninstalled then re-installed Visual Studio and Entity Framework, when I try to add POCO's I get this error
Anyone know how to resolve this?
EDIT 3: I uninstalled the CTP using the technique located here, I uninstalled the CTP and version 4.1 then followed the instructions located and the link I provided and when I followed the instructions I get this error message . This is has reached critical mass and my employer is getting rather upset with me because I cant seem to resolve the error message above. Anyone got any answers for me?
EDIT 4: Got it working locally with IIS 7.5 Express, now need to get it working on the live server. Funny thing is I'm using StructureMap 2.6.2 but the error (for some reason) is looking for 2.5.3. I've searched and searched trying to to find a reference to StructureMap 2.5.3.
EDIT 5: Works perfect locally but same error on live site. I work remotely and we use SVN for source control and the other developer works remotely but it's like my code never makes it to production, and of course I don't have access to the live site
Upvotes: 4
Views: 5637
Reputation: 604
Go to the Solution Explorer, right-click on your solution, choose Configuration Manager and check that all of the projects are being built.
Upvotes: 0
Reputation: 26690
As @Darin mentioned I think you have another DLL referencing the older version.
I would suggest to download Reflector or ILSpy and open the DLLs in your project and see which one is referencing the incorrect version of StructureMap.
Upvotes: 0
Reputation: 4411
I've always seen similar errors when I have a reference to a DLL or project that depends on an older version of a DLL than the one I'm referencing. The older assembly is included in that DLL's manifest, so loading it can throw errors if the exact (older) version can't be found, depending on how it's referenced.
It's hard to know which of your references depend on StructureMap, particularly an older version. Can you update your question to include a screenshot of your references (not just the lib folder)? Or better yet, the part of the .csproj file that shows the references and if they require a specific version? I would be relentlessly combing this section in any referenced projects.
And, consistent with what others here have said, I would remove the lib structure from your solution and install packages through NuGet where possible.
UPDATE: If you can't track down the reference that's pointing to a hard version of StructureMap, try doing an assembly version redirect, described here: http://msdn.microsoft.com/en-us/library/7wd6ex19(v=VS.100).aspx
Upvotes: 3
Reputation: 15316
Are the DLLs making it into your build output folder? The version number may be a red herring. For example, the AutoMock DLL may have been built against the other version, but if it's not strong-named, it'll all work just fine unless it can't find the StructureMap.DLL at all. At that point it will complain, and for completeness it will mention the ideal version number it expects to see.
I've seen problems like this arise when DLLs are included as solution files, in addition to being referenced. Things get copied to the build target when they shouldn't, and don't get copied when they should.
So make sure that:
EITHER one single instance of the DLL as a solution file in one single project is marked as "content" or "copy to output directory"
OR you have your references marked as "copy local"
BUT NOT both, or neither.
Upvotes: 1
Reputation: 88
Sounds like your project is getting compiled in the Client Profile framework. Check properties on the project the Target Framework dropdown, then ask MS why they made Client Profile the default in vs2010 :)
Upvotes: 2