#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2010
    Location
    Brisbane, Australia
    Posts
    20
    Rep Power
    0

    [Solved] C# WPF AppDomain Error


    I'm trying to get an Application class I have developed for .NET 3.5 to work with .NET 4.0 Beta 2. I have created a new default WPF project in both Visual Studio 2008 and 2010 beta 2, and have the following is the base class definition for both App.xaml.cs files.

    csharp Code:
    public partial class App : Application
    {
    	public App()
    	{
    		AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
    	}
     
    	private Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
    	{
    		return null;
    	}
    }


    The problem is that the CurrentDomain_AssemblyResolve method is being called in .NET 4.0, but isn't in .NET 3.5. The resource being requested is called "resources". But as far to my knowledge, the method should never be called, as it should have already been resolved. If you remove the code then it works as normal, and the "resources" resource is loaded as it should be.

    I have also noticed several other bugs with code similar to this in some of my other .NET 3.5 applications. Most notably with console applications. The issue does not seem to be documented anywhere, so I was wondering whether anybody knows why this is happening.
    Last edited by shivercube; January 26th, 2010 at 06:02 PM. Reason: Changed title
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2010
    Location
    Brisbane, Australia
    Posts
    20
    Rep Power
    0
    Does nobody know the answer to this?

    It seems that if you remove resources all together, then the error dissapears. But this still doesn't make sense because if you remove the handler, the resources will get resolved normally. I think this may have something to do with the assembly information language settings of the project, but still, this does not make any sense!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2010
    Location
    Brisbane, Australia
    Posts
    20
    Rep Power
    0
    I have finally managed to find a solution from Microsoft Connect.

    Originally Posted by CommonGenius.com
    The problem is not that AssemblyResolve is being called for assemblies that already exist. The problem is that WPF is looking for a resources assembly when it shouldn't be. You can test this by removing the string literal from your handler and using e.Name instead. In that case, no popup is shown. It is the lookup of the string itself, which it expects to be in a satellite assembly, which is causing the problem.

    In .NET 4.0, the default for resource lookup appears to have been changed to look for a satellite assembly first. This is substantiated by the fact that adding a NeutralResourcesLanguage attribute to the assembly, specifying UltimateResourceFallbackLocation.MainAssembly (which is supposed to be the default, according to http://msdn.microsoft.com/en-us/libr...n(VS.100).aspx), eliminates the problem.
    I still do not understand what the problem is, but adding the following line to AssemblyInfo.cs solves it.

    Code:
    [assembly: NeutralResourcesLanguageAttribute("en-US", UltimateResourceFallbackLocation.MainAssembly)]

IMN logo majestic logo threadwatch logo seochat tools logo