MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / LoadImage

Method LoadImage

Source/Engine/Scripting/Runtime/Mono.cpp:1136–1201  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1134}
1135
1136bool MAssembly::LoadImage(const String& assemblyPath, const StringView& nativePath)
1137{
1138 // Load assembly file data
1139 Array<byte> data;
1140 File::ReadAllBytes(assemblyPath, data);
1141
1142 // Init Mono image
1143 MonoImageOpenStatus status;
1144 const auto name = assemblyPath.ToStringAnsi();
1145 const auto assemblyImage = mono_image_open_from_data_with_name(reinterpret_cast<char*>(data.Get()), data.Count(), true, &status, false, name.Get());
1146 if (status != MONO_IMAGE_OK || assemblyImage == nullptr)
1147 {
1148 Log::CLRInnerException(TEXT("Mono assembly image is invalid at ") + assemblyPath);
1149 return true;
1150 }
1151
1152 // Setup assembly
1153 const auto assembly = mono_assembly_load_from_full(assemblyImage, name.Substring(0, name.Length() - 3).Get(), &status, false);
1154 mono_image_close(assemblyImage);
1155 if (status != MONO_IMAGE_OK || assembly == nullptr)
1156 {
1157 Log::CLRInnerException(TEXT("Mono assembly image is corrupted at ") + assemblyPath);
1158 return true;
1159 }
1160
1161#if MONO_DEBUG_ENABLE
1162 // Try to load debug symbols (use portable PDB format)
1163 const auto pdbPath = String(StringUtils::GetPathWithoutExtension(assemblyPath)) + TEXT(".pdb");
1164 if (FileSystem::FileExists(pdbPath))
1165 {
1166 // Load .pdb file
1167 File::ReadAllBytes(pdbPath, _debugData);
1168
1169 // Attach debugging symbols to image
1170 if (_debugData.HasItems())
1171 {
1172 mono_debug_open_image_from_memory(assemblyImage, _debugData.Get(), _debugData.Count());
1173 }
1174 }
1175
1176 // TODO: load pdbs for custom third-party libs referenced by game assemblies for debugging
1177#if 0
1178 // Hack to load debug information for Newtonsoft.Json (enable it to debug C# code of json lib)
1179 if (assemblyPath.EndsWith(TEXT("FlaxEngine.CSharp.dll")))
1180 {
1181 static Array<byte> NewtonsoftJsonDebugData;
1182 File::ReadAllBytes(String(StringUtils::GetDirectoryName(assemblyPath)) / TEXT("Newtonsoft.Json.pdb"), NewtonsoftJsonDebugData);
1183 if (NewtonsoftJsonDebugData.HasItems())
1184 {
1185 StringAnsi tmp(String(StringUtils::GetDirectoryName(assemblyPath)) / TEXT("Newtonsoft.Json.dll"));
1186 MonoAssembly* a = mono_assembly_open(tmp.Get(), &status);
1187 if (a)
1188 {
1189 mono_debug_open_image_from_memory(mono_assembly_get_image(a), NewtonsoftJsonDebugData.Get(), NewtonsoftJsonDebugData.Count());
1190 }
1191 }
1192 }
1193#endif

Callers

nothing calls this directly

Calls 9

CLRInnerExceptionClass · 0.85
SubstringMethod · 0.80
StringFunction · 0.50
ToStringAnsiMethod · 0.45
GetMethod · 0.45
CountMethod · 0.45
LengthMethod · 0.45
HasItemsMethod · 0.45
EndsWithMethod · 0.45

Tested by

no test coverage detected