samedi 24 mars 2018

ReflectionTypeLoadException when trying to load types from system assemblies

This is not a problem that I am experiencing on my own dev machine or have ever been able to reproduce, but I've been getting a lot of crash logs with this problem from end-users, and I have no idea what's causing it.

The problem is that, for a small percentage of users, when my application calls Assembly.GetTypes() on some System assemblies (always System assemblies built-in to .NET, but different assemblies for different users), it crashes with a ReflectionTypeLoadException with a seemingly-garbled message:

System.Reflection.ReflectionTypeLoadException: Ре ÑƒÐ´Ð°ÐµÑ‚Ñ Ñ  загрузить один или более запрошенных типов. ÐžÐ±Ñ€Ð°Ñ‚Ð¸Ñ‚ÐµÑ ÑŒ к Ñ Ð²Ð¾Ð¹Ñ Ñ‚Ð²Ñƒ LoaderExceptions Ð´Ð»Ñ  Ð¿Ð¾Ð»ÑƒÑ‡ÐµÐ½Ð¸Ñ  дополнительных Ñ Ð²ÐµÐ´ÐµÐ½Ð¸Ð¹.
    в System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
    в System.Reflection.Assembly.GetTypes()
    [my code]

Printing out the LoaderExceptions property always points to a System assembly as the culprit, but does not provide any additional useful information. (And again, the specific assembly seems to change from user to user.) Here's an example of the output I get when printing out all the loader exceptions retrieved from a single ReflectionTypeLoadException:

Ре ÑƒÐ´Ð°Ð»Ð¾Ñ ÑŒ загрузить файл или Ñ Ð±Ð¾Ñ€ÐºÑƒ "System.Web.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" либо одну из их Ð·Ð°Ð²Ð¸Ñ Ð¸Ð¼Ð¾Ñ Ñ‚ÐµÐ¹. Ре ÑƒÐ´Ð°ÐµÑ‚Ñ Ñ  найти указанный файл.
Ре ÑƒÐ´Ð°Ð»Ð¾Ñ ÑŒ загрузить файл или Ñ Ð±Ð¾Ñ€ÐºÑƒ "System.Web.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" либо одну из их Ð·Ð°Ð²Ð¸Ñ Ð¸Ð¼Ð¾Ñ Ñ‚ÐµÐ¹. Ре ÑƒÐ´Ð°ÐµÑ‚Ñ Ñ  найти указанный файл.
Ре ÑƒÐ´Ð°Ð»Ð¾Ñ ÑŒ загрузить файл или Ñ Ð±Ð¾Ñ€ÐºÑƒ "System.Web.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" либо одну из их Ð·Ð°Ð²Ð¸Ñ Ð¸Ð¼Ð¾Ñ Ñ‚ÐµÐ¹. Ре ÑƒÐ´Ð°ÐµÑ‚Ñ Ñ  найти указанный файл.
Ре ÑƒÐ´Ð°Ð»Ð¾Ñ ÑŒ загрузить файл или Ñ Ð±Ð¾Ñ€ÐºÑƒ "System.Web.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" либо одну из их Ð·Ð°Ð²Ð¸Ñ Ð¸Ð¼Ð¾Ñ Ñ‚ÐµÐ¹. Ре ÑƒÐ´Ð°ÐµÑ‚Ñ Ñ  найти указанный файл.
Ре ÑƒÐ´Ð°Ð»Ð¾Ñ ÑŒ загрузить файл или Ñ Ð±Ð¾Ñ€ÐºÑƒ "System.Web.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" либо одну из их Ð·Ð°Ð²Ð¸Ñ Ð¸Ð¼Ð¾Ñ Ñ‚ÐµÐ¹. Ре ÑƒÐ´Ð°ÐµÑ‚Ñ Ñ  найти указанный файл.

Again, the text is strangely garbled. Any idea what's going on? Any idea how to debug this?

Here's the code from my program that calls Assembly.GetTypes():

        foreach(Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
        {
            Type[] types;
            try
            {
                types = assembly.GetTypes();
            }
            catch(ReflectionTypeLoadException ex)
            {
                Logger.LogError("Error getting types from assembly: " + assembly.FullName);
                Logger.LogError("LoaderExceptions:");
                foreach(Exception ex2 in ex.LoaderExceptions)
                    Logger.LogError("\t" + ex2.Message);
                throw;
            }

            // Do stuff with the loaded types...
        }





Aucun commentaire:

Enregistrer un commentaire