Hello Guest

Author Topic: ReflectionTypeLoadException  (Read 6020 times)

VGT

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 17
    • View Profile
ReflectionTypeLoadException
« on: May 22, 2012, 11:31:44 pm »
When building animations, I have come across this error:

ReflectionTypeLoadException: The classes in the module cannot be loaded.
System.Reflection.Assembly.GetTypes ()
tk2dSpriteCollectionBuilder.RefreshExistingAssets (.tk2dSpriteCollectionData spriteCollectionData) (at Assets/TK2DROOT/tk2d/Editor/Sprites/tk2dSpriteCollectionBuilder.cs:1124)
tk2dSpriteCollectionBuilder.Rebuild (.tk2dSpriteCollection gen) (at Assets/TK2DROOT/tk2d/Editor/Sprites/tk2dSpriteCollectionBuilder.cs:1101)
tk2dSpriteCollectionEditorPopup.DrawToolbar () (at Assets/TK2DROOT/tk2d/Editor/Sprites/SpriteCollectionEditor/tk2dSpriteCollectionEditorPopup.cs:410)
tk2dSpriteCollectionEditorPopup.OnGUI () (at Assets/TK2DROOT/tk2d/Editor/Sprites/SpriteCollectionEditor/tk2dSpriteCollectionEditorPopup.cs:670)
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture)

I found the only thing this does is that it doesn't attach the material(s) of the atlas to the data prefab.

I tried re-importing the 2DToolkit files (excluding the demo folder) and this didn't seem to fix it.  I have a feeling something might be wrong in my project settings but I'm not sure what.

VGT

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: ReflectionTypeLoadException
« Reply #1 on: May 22, 2012, 11:47:07 pm »
I also noticed that none of my sprite collections will show up when I create animations when this error occurs.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: ReflectionTypeLoadException
« Reply #2 on: May 23, 2012, 12:07:01 am »
Do you use any other middleware in Unity?

This looks like one of the assemblies loaded doesn't like the reflection APIs called on it. You can fix it by replacing that function with the one below, basically wrapping that entire GetTypes, etc. block within a try... catch block. We only need the game assembly here.

tk2dSpriteCollectionBuilder.cs
Code: [Select]
static void RefreshExistingAssets(tk2dSpriteCollectionData spriteCollectionData)
{
foreach (var assembly in System.AppDomain.CurrentDomain.GetAssemblies())
{
try
{
System.Type[] types = assembly.GetTypes();
foreach (var type in types)
{
if (type.GetInterface("tk2dRuntime.ISpriteCollectionForceBuild") != null)
{
Object[] objects = Resources.FindObjectsOfTypeAll(type);
foreach (var o in objects)
{
if (tk2dEditorUtility.IsPrefab(o))
continue;

tk2dRuntime.ISpriteCollectionForceBuild isc = o as tk2dRuntime.ISpriteCollectionForceBuild;
if (isc.UsesSpriteCollection(spriteCollectionData))
isc.ForceBuild();
}
}
}
}
catch { }
}
}

VGT

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: ReflectionTypeLoadException
« Reply #3 on: May 23, 2012, 12:18:04 am »
We have assemblies from other developers in the project so that is entirley possible.  Thank you for the fix.