Skip to content

Commit c429ec0

Browse files
[NUnitLite] remove Assembly.CodeBase usage (#9859)
Context: #9846 Running `tests/Mono.Android-Tests` on NativeAOT crashes with: E NUnit : Error: System.NotSupportedException: NotSupported_CodeBase (TaskId:30) E NUnit : at System.Reflection.Runtime.Assemblies.RuntimeAssemblyInfo.get_CodeBase() + 0x34 (TaskId:30) E NUnit : at NUnit.Framework.Internal.AssemblyHelper.GetAssemblyPath(Assembly) + 0x10 (TaskId:30) E NUnit : at NUnit.Framework.Internal.NUnitLiteTestAssemblyBuilder.Build(Assembly, IDictionary) + 0x8c (TaskId:30) E NUnit : at NUnit.Framework.Internal.NUnitLiteTestAssemblyRunner.Load(Assembly, IDictionary) + 0x28 (TaskId:30) E NUnit : at Xamarin.Android.UnitTests.NUnit.NUnitTestRunner.Run(IList`1) + 0x1ac (TaskId:30) E NUnit : at Xamarin.Android.UnitTests.TestInstrumentation`1.RunTests(Bundle&) + 0xc8 (TaskId:30) E NUnit : at Xamarin.Android.UnitTests.TestInstrumentation`1.OnStart() + 0x48 (TaskId:30) It appears we can just remove all usage of `Assembly.CodeBase` from NUnitLite to get past this error.
1 parent c1e0d10 commit c429ec0

File tree

1 file changed

+0
-40
lines changed

1 file changed

+0
-40
lines changed

src-ThirdParty/NUnitLite/Internal/AssemblyHelper.cs

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,6 @@ public static string GetAssemblyPath(Type type)
5252
/// <returns>The path.</returns>
5353
public static string GetAssemblyPath(Assembly assembly)
5454
{
55-
string codeBase = assembly.CodeBase;
56-
57-
if (IsFileUri(codeBase))
58-
return GetAssemblyPathFromCodeBase(codeBase);
59-
6055
return assembly.Location;
6156
}
6257
#endif
@@ -96,40 +91,5 @@ public static AssemblyName GetAssemblyName(Assembly assembly)
9691
}
9792

9893
#endregion
99-
100-
#region Helper Methods
101-
102-
#if !NETCF
103-
private static bool IsFileUri(string uri)
104-
{
105-
return uri.ToLower().StartsWith(Uri.UriSchemeFile);
106-
}
107-
108-
// Public for testing purposes
109-
public static string GetAssemblyPathFromCodeBase(string codeBase)
110-
{
111-
// Skip over the file:// part
112-
int start = Uri.UriSchemeFile.Length + Uri.SchemeDelimiter.Length;
113-
114-
bool isWindows = System.IO.Path.DirectorySeparatorChar == '\\';
115-
116-
if (codeBase[start] == '/') // third slash means a local path
117-
{
118-
// Handle Windows Drive specifications
119-
if (isWindows && codeBase[start + 2] == ':')
120-
++start;
121-
// else leave the last slash so path is absolute
122-
}
123-
else // It's either a Windows Drive spec or a share
124-
{
125-
if (!isWindows || codeBase[start + 1] != ':')
126-
start -= 2; // Back up to include two slashes
127-
}
128-
129-
return codeBase.Substring(start);
130-
}
131-
#endif
132-
133-
#endregion
13494
}
13595
}

0 commit comments

Comments
 (0)