Tim Butterfield
Tim Butterfield

Reputation: 587

MVCSiteMapProvider - System.Windows load issue

I'm trying to upgrade to the latest version of the MVCSiteMapProvider and having issues. Some context, I can't use Nuget so have cloned using git, built in release mode locally and copied the relevant assemblies to my project depedencies folder, adding references to MvcSiteMapProvider.dll, Microsoft.Web.Infrastructure.dll and to WebActivatorEx.dll.

Because it's a working app, I can't, as the text files with the source suggests, just copy the unity folders/file across. I have though wired up the container as follows (roughly):

public class UnityRegistrar
{
    public UnityRegistrar()
    {

      container = new UnityContainer();
      container.AddNewExtension<MvcSiteMapProviderContainerExtension>();
    }
}

Where the extension class is based on https://github.com/maartenba/MvcSiteMapProvider/tree/master/src/MvcSiteMapProvider/CodeAsConfiguration/Unity/DI/Unity/ContainerExtensions

Various type maps are registered in Unity and the following code is the last thing to execute.

MvcSiteMapProvider.SiteMaps.Loader = container.Resolve<ISiteMapLoader>();

The net result is that I get the following type load exception: Could not load file or assembly 'System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its dependencies. The system cannot find the file specified.

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.FileNotFoundException:

Could not load file or assembly 'System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its dependencies. The system cannot find the file specified.

None of the three dll's referenced depend on this assembly, so I'm unsure as to what I've done wrong. Needless to say a vanilla project with references added via nuget without IoC configured through Unity works. Removing the MvcSiteMapProvider start up/IoC code from my app doesn't however, so not sure what I've done wrong here.

Any thoughts on why it's asking for System.Windows.dll?

EDIT

More detail on error : [FileNotFoundException: Could not load file or assembly 'System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its dependencies. The system cannot find the file specified.] System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type) +0 System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext) +371 System.ModuleHandle.ResolveTypeHandle(Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext) +19 System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments) +319 System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg) +203 System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent) +1179 System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeAssembly assembly, RuntimeType caType) +146 WebActivatorEx.AssemblyExtensions.GetActivationAttributes(Assembly assembly) +113 WebActivatorEx.ActivationManager.RunActivationMethods(Boolean designerMode) +290 WebActivatorEx.ActivationManager.RunPreStartMethods(Boolean designerMode) +47 WebActivatorEx.ActivationManager.Run() +70

[InvalidOperationException: The pre-application start initialization method Run on type WebActivatorEx.ActivationManager threw an exception with the following error message: Could not load file or assembly 'System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its dependencies. The system cannot find the file specified..] System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection1 methods, Func1 setHostingEnvironmentCultures) +12600191 System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods) +12599912 System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded) +280 System.Web.Compilation.BuildManager.ExecutePreAppStart() +172 System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +1151

[HttpException (0x80004005): The pre-application start initialization method Run on type WebActivatorEx.ActivationManager threw an exception with the following error message: Could not load file or assembly 'System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its dependencies. The system cannot find the file specified..] System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +12599232 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +159 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +12438981

It's related to the use of WebActivatorEx. If I remove the reference, and clean up the bin dir, it doesn't blow up. I don't use WebActivator to and PostApplicationStartMethod to construct my container. I've a method in global.asax which boostraps my container.

Not sure why WebActivatorEx is asking for System.Windows given it's not a dependency.

Upvotes: 0

Views: 1083

Answers (3)

Tim Butterfield
Tim Butterfield

Reputation: 587

The root of my problem with System.Windows load exception was due to assemblies lying around in the bin dir that didn't belong there. In some one's wisdom, they included a post build task to copy all dependencies to the bin, including those not referenced by the project. Hence why there were System.Windows.*.dll in the bin dir of a web project.

Upvotes: 1

NightOwl888
NightOwl888

Reputation: 56849

built in release mode locally

Based on the link provided by @maartenba, I suspect this is where your problem lies, because you need to have the compiler switches and framework version setup correctly for all of the dependencies to work right. Not to mention, they need to match what you have in your project exactly.

First of all, make sure you run your build off of the master branch.

If you run the build.bat file, passing it the version and package version switches you will be able to build all of the versions the same way they are built for the NuGet packages. Then you can be sure all of the dependencies are set up correctly for your .NET framework version.

(From the same directory as the MvcSiteMapProvider.sln file)
(NOTE: Use the current version on NuGet Gallery, this version is only current at the time of this writing)

MvcSiteMapProvider>build.bat -pv:4.4.9 -v:4.4.9

Note that this fires off a powershell script, so you may need to run this command to setup powershell correctly. See this article for more details.

After you run the build, you will be able to access both the raw DLL files and the .nupkg files (if you want to install them locally via NuGet) in the \release folder. The DLLs can be found at

(From the same directory as the MvcSiteMapProvider.sln file)
\release\mvcsitemapprovider.mvc[X].core\lib\net[YY]\MvcSiteMapProvider.dll

Replace the X with your MVC version and the YY with your .NET framework version (example use 40 for 4.0, or 45 for 4.5).

The .nupkg files are at the root of the \release directory and are named using the same conventions used on NuGet gallery.

On a side note, if you "cannot use NuGet" because you cannot access the Internet from your dev or build machine, do note that it is possible to access the .nupkg file from a local directory by going into "Settings" from the main NuGet GUI window and then adding a "package source" mapping to your own file system. If you mean you "cannot use NuGet" because you are afraid of breaking your DI configuration, note that the Unity "modules only" packages are designed for this very purpose - they only give you a module to integrate with your existing DI configuration, while leaving your main wiring code intact. You just need to add a few lines to your existing configuration to get the wheels turning - see the readme file for Unity. Of course, you may have another reason for not using NuGet, but just wanted to be sure you (and the community) were aware of these points.

Upvotes: 0

maartenba
maartenba

Reputation: 3384

Do you have a full stack trace of where the exception occurs? Can you try analyzing fusion logs? http://msdn.microsoft.com/en-us/library/e74a18c4(v=vs.110).aspx

Upvotes: 0

Related Questions