diff --git a/csharp-api/REFrameworkNET/ManagedObject.cpp b/csharp-api/REFrameworkNET/ManagedObject.cpp index e71e88aa0..30ce79b94 100644 --- a/csharp-api/REFrameworkNET/ManagedObject.cpp +++ b/csharp-api/REFrameworkNET/ManagedObject.cpp @@ -134,7 +134,15 @@ namespace REFrameworkNET { break; } - const auto offset = field_type->IsValueType() ? field_type->GetField("_firstChar")->GetOffsetFromFieldPtr() : field_type->GetField("_firstChar")->GetOffsetFromBase(); + const auto firstCharField = field_type->GetField("_firstChar"); + uint32_t offset = 0; + + if (firstCharField != nullptr) { + offset = field_type->IsValueType() ? firstCharField->GetOffsetFromFieldPtr() : firstCharField->GetOffsetFromBase(); + } else { + const auto fieldOffset = *(uint32_t*)(*(uintptr_t*)strObject - sizeof(void*)); + offset = fieldOffset + 4; + } wchar_t* chars = (wchar_t*)((uintptr_t)strObject + offset); result = gcnew System::String(chars); diff --git a/csharp-api/REFrameworkNET/Method.cpp b/csharp-api/REFrameworkNET/Method.cpp index a91b7e012..f46c309b4 100644 --- a/csharp-api/REFrameworkNET/Method.cpp +++ b/csharp-api/REFrameworkNET/Method.cpp @@ -134,7 +134,15 @@ bool Method::HandleInvokeMember_Internal(System::Object^ obj, System::String^ me // Maybe don't create the GC version and just use the native one? auto strObject = gcnew REFrameworkNET::ManagedObject((::REFrameworkManagedObjectHandle)tempResult->QWord); auto strType = strObject->GetTypeDefinition(); - const auto offset = strType->GetField("_firstChar")->GetOffsetFromBase(); + const auto firstCharField = strType->GetField("_firstChar"); + uint32_t offset = 0; + + if (firstCharField != nullptr) { + offset = strType->GetField("_firstChar")->GetOffsetFromBase(); + } else { + const auto fieldOffset = *(uint32_t*)(*(uintptr_t*)tempResult->QWord - sizeof(void*)); + offset = fieldOffset + 4; + } wchar_t* chars = (wchar_t*)((uintptr_t)strObject->Ptr() + offset); result = gcnew System::String(chars);