Failed to load file or assembly 'StructureMap, Version = 2.5.3.0

I am working on a project and decided to go with StructureMap as an IoC, but whenever we try to load a project (MVC 3 by the way), we get this error:

Failed to load file or assembly 'StructureMap, Version = 2.5.3.0, Culture = neutral, PublicKeyToken = e60ad81abae3c223' or one of its dependencies. The system cannot find the specified file.

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 I have StructureMap in the lib folder that I added to the main MVC application. Even when deleting all the links that I can find, I still get this error.

For the record, this is the lib folder in the MVC3 structure

enter image description here

And I add a link to 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 Factory user controller for StructueMap. Here is the factory controller code:

 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 this is how I use it in the Global.asax.cs file

 ControllerBuilder.Current.SetControllerFactory(new StructureMapControllerFactory()); 

EDIT: I installed StructureMap with NuGet and still get the same error, although NuGet installed a different version (2.6 instead of 2.5), but still get a 2.5 error. Therefore, I am going to offer generosity to everyone who can help me solve this problem.

EDIT 2 I uninstalled and then reinstalled Visual Studio and Entity Framework, when I try to add POCO, I get this error enter image description here

Does anyone know how to solve this?

EDIT 3: I removed CTP using the technique located here , I removed CTP and version 4.1 then follow the instructions and the link provided, and when I follow the instructions, I get this error message enter image description here . This has reached a critical mass, and my employer is rather upset because of me because I do not seem to allow the error message above. Has anyone received answers to my questions?

EDIT 4:. It works locally with IIS 7.5 Express, now you need to make it work on a real server. It's funny that I'm using StructureMap 2.6.2, but the error (for some reason) is looking for 2.5.3. I searched and searched for an attempt to find a link to StructureMap 2.5.3.

EDIT 5: Works perfect, but with the same error on a live site. I work remotely and we use SVN to manage the source code, and another developer works remotely, but he, like my code, never makes it for production, and, of course, I do not have access to the current site.

+4
source share
5 answers

I always saw similar errors when I have a link to a DLL or a project that depends on an older version of the DLL than the one I'm referring to. An older assembly is included in this DLL manifest, so loading may cause errors if the exact (older) version cannot be found , depending on how it is referenced.

It’s not difficult to know which of your links depends on StructureMap, especially the old version. Can you update your question by including a screenshot of your links (and not just the lib folder)? Or even better, the part of the .csproj file that shows links, and if they require a specific version? I would tirelessly comb this section in any referenced projects.

And, according to what others have said, I would remove the lib structure from your solution and install packages through NuGet, where possible.

UPDATE: If you cannot track the link pointing to the hard version of StructureMap, try redirecting the assembly version described here: http://msdn.microsoft.com/en-us/library/7wd6ex19(v=VS.100).aspx

+3
source

It looks like your project is compiling as part of a client profile. Check the project properties in the Target Framework drop-down list, then ask MS why they made the default client profile in vs2010 :)

+2
source

Are DLLs in your build output folder? The version number may be a red herring. For example, the AutoMock DLL can be built against a different version, but if it does not have a strong name, everything will work fine if it cannot find StructureMap.DLL at all . He will complain at this point, and for completeness he will mention the ideal version number that he expects to see.

I saw such problems when DLLs are included as solution files, in addition to links. Things will be copied to the build target when they shouldn't, and not copied when they should.

Therefore, make sure that:

EITHER one instance of the DLL as a solution file in one project is marked as "content" or "copy to output directory"

OR you have links marked as "copy local"

BUT BUT both, or not one.

+1
source

As @Darin mentioned, I think you have another DLL referencing an older version.

I would suggest downloading Reflector or ILSpy and opening the DLL in your project and see which one is referencing the wrong version of StructureMap.

0
source

Go to Solution Explorer, right-click your solution, select Configuration Manager and make sure all projects are built.

0
source

All Articles