views:

101

answers:

0

I have updated an application to Target .Net 4.0. Part of this application uses CSharpCodeProvider at runtime to compile source code files to assemblies and use them within the application. The complier provider options are set to "CompilerVersion", "v4.0". When executing the compiled code which references a 4.0 external dll (added as reference to the CodeDomProvider) that has resource strings embedded within it, the following error exception occurs.

System.IO.FileNotFoundException: Could not find file 'JG.Rules.resources'.
at System.Reflection.RuntimeAssembly.InternalGetSatelliteAssembly(String name, CultureInfo culture, Version version, Boolean throwOnFileNotFound, StackCrawlMark& stackMark)    
at System.Resources.ManifestBasedResourceGroveler.GetSatelliteAssembly(CultureInfo lookForCulture, StackCrawlMark& stackMark)    
at System.Resources.ManifestBasedResourceGroveler.GrovelForResourceSet(CultureInfo culture, Dictionary`2 localResourceSets, Boolean tryParents, Boolean createIfNotExists, StackCrawlMark& stackMark)    
at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo requestedCulture, Boolean createIfNotExists, Boolean tryParents, StackCrawlMark& stackMark)    
at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents)    
at System.Resources.ResourceManager.GetString(String name, CultureInfo culture)    
at JG.Rules.RuleResources.get_Value_X_must_be_Equal_to_Y() in

The assembly dll JG.Rules works fine from unit tests, so something has changed with the move from 3.5 to 4.0 with respect the CSharpCodeProvider and the referenced dlls. Has anybody come across or know of a solution? Googling has not turned up much info on this but some links that are of interest, similar errors but not from using CSharpCodeProvider.

http://entlib.codeplex.com/workitem/27927

I think i may have identified the problem, note that JG.Rules is in a sub folder of the Application Folder {app}/user. In my app I have an assembly resolve event handler for the CurrentAppDomain which I use to resolve the assemblies in {app}/user. In MSDN it states msdn.microsoft.com/en-us/library/system.appdomain.assemblyresolve.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."

I assume the definition of a resource assembly an any assembly that has a Resources file. So my guess is its failing to resolve JG.Rules.resources because I do not match against it. I dont know if we now have to explicitly resolve .resources to the containing assemblies? I tried returning the assembly JG.Rules.dll when the handler is called on JG.Rules.resources but it failed as before. If this functionality is changed in 4.0, how do I resolve JG.Rules.resources?

Returning null to AssemblyResolve does not work. Placing the dll in the {appfolder} and changing the reference fails also. Placing the dll in {appfolder} and {appfolder}/user and changing the CodeDomProvider.ReferencedAssemblies to use {appfolder}/user/JG.Rules.dll will work. In this scenario the CLR binder must fallback and bind to the dll in the {appfolder}. This is not an ideal solution, please help with this problem.