Skip to content

Commit ac9379b

Browse files
author
Stewart Miles
committed
Handle exceptions thrown by Unity.Cecil on asset rename
When the VersionHandler activates a package it potentially renames DLLs to the canonical name causing the DLL to be reimported. In some cases this can cause Unity.Cecil (as far I can tell they use this to rewrite DLLs) to throw exceptions while processing the DLL which are totally harmless as they DLL is imported and processed again when AssetDatabase.Refresh() is executed. BUG=34123612 Change-Id: I20e993aa0de8ff8b1075258d042ccf076b945ddf
1 parent b215087 commit ac9379b

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

source/VersionHandler/src/VersionHandler.cs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -401,15 +401,23 @@ public bool RenameAsset(string newFilename) {
401401
return false;
402402
}
403403
}
404-
string error = AssetDatabase.RenameAsset(
405-
filename, filenameComponents.basenameNoExtension);
406-
if (!String.IsNullOrEmpty(error)) {
407-
UnityEngine.Debug.LogError(
408-
"Failed to rename asset " + filename + " to " +
409-
newFilename + " (" + error + ")");
410-
return false;
404+
try {
405+
string error = AssetDatabase.RenameAsset(
406+
filename, filenameComponents.basenameNoExtension);
407+
if (!String.IsNullOrEmpty(error)) {
408+
UnityEngine.Debug.LogError(
409+
"Failed to rename asset " + filename + " to " +
410+
newFilename + " (" + error + ")");
411+
return false;
412+
}
413+
AssetDatabase.ImportAsset(newFilename);
414+
} catch (Exception) {
415+
// Unity 5.3 and below can end up throw all sorts of
416+
// exceptions here when attempting to reload renamed
417+
// assemblies. Since these are completely harmless as
418+
// everything will be reloaded and exceptions will be
419+
// reported upon AssetDatabase.Refresh(), ignore them.
411420
}
412-
AssetDatabase.ImportAsset(newFilename);
413421
filename = newFilename;
414422
UpdateAssetLabels();
415423
return true;

0 commit comments

Comments
 (0)