Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
4.89/5 (2 votes)
Hello,

I'm implementing an AppDomain.AssemblyResolve (http://msdn.microsoft.com/en-us/library/system.appdomain.assemblyresolve.aspx[^]) eventhandler.

Everything works fine, I just return the Assembly when I can, otherwise just null like the documentation suggests. The event is called every time before .NET attempts to resolve the Assembly by itself.

Normally a AssemblyName.FullName is provided with the ResolveEventArgs This is easy to work with since each Assembly has an AssemblyName. Apart from names, the ResolveEventArgs sometimes also give a .resources file within an Assembly.

This behaviour is mentioned in the documentation:
Beginning with the .NET Framework 4, the ResolveEventHandler event is raised for all assemblies, including resource assemblies.

Not a problem, but what should I return when a .resources file is requested? Just the Assembly which contains the requested .resources file?
In my current infrastructure it's not hard to add, I just wonder if it's the right thing to do. Right now I just return null.

Thanks in advance
Posted
Updated 19-Sep-13 6:09am
v2
Comments
Sergey Alexandrovich Kryukov 19-Sep-13 12:35pm    
Actually, .resources file is not requested, but an assembly is requested, and only if the "standard" resolution has failed.
—SA
wpte 19-Sep-13 15:15pm    
Since .NET 4.0 the event is allways called before .NET tries to resolve the Assembly by itself using the GAC or local libraries in the same directory as the executable.

url: http://msdn.microsoft.com/en-us/library/system.appdomain.assemblyresolve(v=vs.100).aspx
"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."

I was talking about embedded resources. I get requests in the event with a format like: "namespace.resourcename.resources" not the usual format from AssemblyName.FullName

Now it's not that hard to find the accompanying Assembly which contains the embedded resource. As Collin Kleine suggests, returning an Assembly which contains the resource might be a good idea. I will check this tomorrow
Sergey Alexandrovich Kryukov 19-Sep-13 15:45pm    
I'm talking about embedded, too. But all events are invoked only when it fails in a default resolution.
I think returning of the Assembly which contains the resource is not just a good idea, but a requirement. Otherwise it won't be found at all. However, I don't know your scenario, what you are trying to achieve. If all your resource assemblies are found anyway, you should don't have to worry. Resource-only assemblies are relatively rare. Usually they are only the the satellites.
—SA
wpte 19-Sep-13 15:50pm    
Allright. There's no way to check the correct version however. The only way to match the correct assembly is by matching strings. Bit unfortunate to be honest.

Still I'm convinced the event is called before .NET uses it's own resolver. I also get requests for System.something Assemblies which clearly need to be found in the GAC.

Also sorry for all the double posts, some code project maintenance was messing it up :(
Sergey Alexandrovich Kryukov 19-Sep-13 16:29pm    
No problem. I tried to model the situation and now not quite sure. Are you trying to resolve the assembly bound statically, or via Assembly.Load/LoadFrom?
—SA

1 solution

As you mentioned, it is not actually about .resources files, it is about embedded resources within a certain assembly, known as satellite assemblies.

Quote:
Beginning with the .NET Framework 4, the AssemblyResolve event is raised for satellite assemblies.

Source: http://msdn.microsoft.com/en-us/library/ff527268.aspx[^]

Quote:
satellite assembly

A .NET Framework assembly containing resources specific to a given language. Using satellite assemblies, you can place the resources for different languages in different assemblies, and the correct assembly is loaded into memory only if the user elects to view the application in that language.

Source: http://msdn.microsoft.com/en-GB/library/c83eyewf%28v=vs.80%29.aspx[^]

You will need to return the assembly containing the resource, as this short sentence tells you:
Quote:
The ResolveEventHandler for this event can attempt to locate the assembly containing the resource and return it.

Source: http://msdn.microsoft.com/en-us/library/system.appdomain.resourceresolve.aspx[^]

Hopes this help.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900