3

I wrote a custom AssemblyResolve method to handle assembly in a folder other than exe file. But once it shows missing "Microsoft.Practices.EnterpriseLibrary.Common.resources". While I have Microsoft.Practices.EnterpriseLibrary.Common.dll, I don't have Microsoft.Practices.EnterpriseLibrary.Common.resources.dll. How do i manually load Microsoft.Practices.EnterpriseLibrary.Common.resources?

protected Assembly ConfigResolveEventHandler(object sender, ResolveEventArgs args)
        {
            //This handler is called only when the common language runtime tries to bind to the assembly and fails.

            //Retrieve the list of referenced assemblies in an array of AssemblyName.
            string strTempAssmbPath = "";
            Assembly asm = this.GetType().Assembly;

            var uri = new Uri(Path.GetDirectoryName(asm.CodeBase));


            Assembly objExecutingAssemblies = Assembly.GetExecutingAssembly();
            AssemblyName[] arrReferencedAssmbNames = objExecutingAssemblies.GetReferencedAssemblies();

            //Loop through the array of referenced assembly names.
            if (arrReferencedAssmbNames.Any(strAssmbName => strAssmbName.Name == args.Name))
            {
                strTempAssmbPath = Path.Combine(uri.LocalPath, args.Name) + ".dll";
            }
            //Load the assembly from the specified path.                    
            Assembly myAssembly = Assembly.LoadFrom(strTempAssmbPath);

            //Return the loaded assembly.
            return myAssembly;  
        }
1
  • I'm running into the same problem, but I'm not convinced it's actually a dll that exists. There are resources attached to the Microsoft.Practices.EnterpriseLibrary.Common.dll library, and maybe for whatever reason those can't be accessed. Looking at it in .NET Reflector, it lists the references, and Microsoft.Practices.EnterpriseLibrary.Common.resources.dll is not listed. Have you had any luck with this yet? Commented Apr 27, 2011 at 22:00

2 Answers 2

3

Issue has been discussed on Microsoft Connect.

Proposed solution: Add the following line to AssemblyInfo.cs:

[assembly: NeutralResourcesLanguageAttribute("en-US", UltimateResourceFallbackLocation.MainAssembly)]
Sign up to request clarification or add additional context in comments.

Comments

2

We ran into this same problem with an AssemblyResolve event handler. Oddly, we only saw the issue on Windows XP machines. Our application is localized to many languages, so we were hesitant to use the NeutralResourcesLanguageAttribute. Our application was compiled for .NET v3.5, but was still being affected by the AssemblyResolve change documented for .NET v4.0:

Important Beginning with the .NET Framework 4, the ResolveEventHandler event is raised for all assemblies, including resource assemblies. In earlier versions, the event was not raised for resource assemblies. If the operating system is localized, the handler might be called multiple times: once for each culture in the fallback chain.

The way we resolved this was to check e.Name and see if it was looking for *.Resources.dll. If that file was not found in the AppDomain or known folder, we would remove ".Resources" and look for *.dll. If that file exists, we load and return that assembly. This resolved the problem for us.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.