I am a beginner in C# and cpp, and When I'm trying to build the FiveM launcher from the the FiveM launcher OpenSource code FiveM launcher OpenSource code, I'm getting this error after doing fxd build.
"C:\Users\Utilisateur\Desktop\dev\fivem\launcher\fivem\code\build\five\CitizenMP.sln" (default target) (1) ->
"C:\Users\Utilisateur\Desktop\dev\fivem\launcher\fivem\code\build\five\CitiMono.csproj.metaproj" (default target) (76) ->
"C:\Users\Utilisateur\Desktop\dev\fivem\launcher\fivem\code\build\five\CitiMono.csproj" (default target) (105) ->
(CoreCompile target) ->
C:\Users\Utilisateur\Desktop\dev\fivem\launcher\fivem\code\client\clrcore\InternalManager.cs(620,13): error CS0103: The name 'EnhancedStackTrace' does not exist in the current context [C:\Users\Utilisateur\Desktop\dev\fivem\launcher\fivem\code\build\five\CitiMono.csproj]
And this is part of the code of the InternalManager.cs line 575 to line 634 where I get the error for the EnhancedStackTrace.
[SecuritySafeCritical]
private void PrintError(string where, Exception what)
{
ScriptHost.SubmitBoundaryEnd(null, 0);
var stackTrace = new StackTrace(what, true);
#if IS_FXSERVER
var stackFrames = stackTrace.GetFrames();
#else
IEnumerable<StackFrame> stackFrames;
// HACK: workaround to iterate inner traces ourselves.
// TODO: remove this once we've updated libraries
var fieldCapturedTraces = typeof(StackTrace).GetField("captured_traces", BindingFlags.NonPublic | BindingFlags.Instance);
if (fieldCapturedTraces != null)
{
var captured_traces = (StackTrace[])fieldCapturedTraces.GetValue(stackTrace);
// client's mscorlib is missing this piece of code, copied from https://github.com/mono/mono/blob/ef848cfa83ea16b8afbd5b933968b1838df19505/mcs/class/corlib/System.Diagnostics/StackTrace.cs#L181
var accum = new List<StackFrame>();
foreach (var t in captured_traces ?? Array.Empty<StackTrace>())
{
for (int i = 0; i < t.FrameCount; i++)
accum.Add(t.GetFrame(i));
}
accum.AddRange(stackTrace.GetFrames());
stackFrames = accum;
}
else
stackFrames = stackTrace.GetFrames();
#endif
var frames = stackFrames
.Select(a => new
{
Frame = a,
Method = a.GetMethod(),
Type = a.GetMethod()?.DeclaringType
})
.Where(a => a.Method != null && (!a.Type.Assembly.GetName().Name.Contains("mscorlib") && !a.Type.Assembly.GetName().Name.Contains("CitizenFX.Core") && !a.Type.Assembly.GetName().Name.StartsWith("System")))
.Select(a => new
{
name = EnhancedStackTrace.GetMethodDisplayString(a.Method).ToString(),
sourcefile = a.Frame.GetFileName() ?? "",
line = a.Frame.GetFileLineNumber(),
file = $"@{m_resourceName}/{a.Type?.Assembly.GetName().Name ?? "UNK"}.dll"
});
var serializedFrames = MsgPackSerializer.Serialize(frames);
var formattedStackTrace = FormatStackTrace(serializedFrames);
if (formattedStackTrace != null)
{
Debug.WriteLine($"^1SCRIPT ERROR in {where}: {what.GetType().FullName}: {what.Message}^7");
Debug.WriteLine("{0}", formattedStackTrace);
}
}
And the EnhancedStackTrace is also being used in the file MonoComponentHost.cpp and this part of the code where it is being used it's from line 267 to line 327.
static void InitMono()
{
// initializes the mono runtime
fx::mono::MonoComponentHostShared::Initialize();
mono_thread_attach(mono_get_root_domain());
g_rootDomain = mono_get_root_domain();
mono_add_internal_call("CitizenFX.Core.GameInterface::PrintLog", reinterpret_cast<void*>(GI_PrintLogCall));
mono_add_internal_call("CitizenFX.Core.GameInterface::fwFree", reinterpret_cast<void*>(fwFree));
#ifndef IS_FXSERVER
mono_add_internal_call("CitizenFX.Core.GameInterface::TickInDomain", reinterpret_cast<void*>(GI_TickInDomain));
#endif
mono_add_internal_call("CitizenFX.Core.GameInterface::GetMemoryUsage", reinterpret_cast<void*>(GI_GetMemoryUsage));
mono_add_internal_call("CitizenFX.Core.GameInterface::WalkStackBoundary", reinterpret_cast<void*>(GI_WalkStackBoundary));
mono_add_internal_call("CitizenFX.Core.GameInterface::SnapshotStackBoundary", reinterpret_cast<void*>(GI_SnapshotStackBoundary));
std::string platformPath = MakeRelativeNarrowPath("citizen/clr2/lib/mono/4.5/CitizenFX.Core.dll");
auto scriptManagerAssembly = mono_domain_assembly_open(g_rootDomain, platformPath.c_str());
if (!scriptManagerAssembly)
{
FatalError("Could not load CitizenFX.Core.dll.\n");
}
auto scriptManagerImage = mono_assembly_get_image(scriptManagerAssembly);
bool methodSearchSuccess = true;
MonoMethodDesc* description;
#define method_search(name, method) description = mono_method_desc_new(name, 1); \
method = mono_method_desc_search_in_image(description, scriptManagerImage); \
mono_method_desc_free(description); \
methodSearchSuccess = methodSearchSuccess && method != NULL
MonoMethod* rtInitMethod;
method_search("CitizenFX.Core.RuntimeManager:Initialize", rtInitMethod);
method_search("CitizenFX.Core.RuntimeManager:GetImplementedClasses", g_getImplementsMethod);
method_search("CitizenFX.Core.RuntimeManager:CreateObjectInstance", g_createObjectMethod);
method_search("System.Diagnostics.EnhancedStackTrace:GetMethodDisplayString", g_getMethodDisplayStringMethod);
#if !defined(IS_FXSERVER) || defined(_WIN32)
method_search("CitizenFX.Core.InternalManager:TickGlobal", g_tickMethod);
#endif
if (!methodSearchSuccess)
{
FatalError("Couldn't find one or more CitizenFX.Core methods.\n");
}
MonoObject* exc = nullptr;
mono_runtime_invoke(rtInitMethod, nullptr, nullptr, &exc);
if (exc)
{
fx::mono::MonoComponentHostShared::PrintException(exc);
return;
}
}
I've tried fixing by asking for some people from the cfx.re community but it wasn't really helpful. I also checked on internet and the only thing that I found is the error guide from Microsoft for his error error CS0103, but it was helpless. And the others that is getting this errors isn't really helpful for me. And yes I've followed all the process from the little documentation.
You are getting this error because the compiler/visual studio cannot locate a type named
EnhancedStackTracein your program code or within any referenced assembly (dll).If I assume that the maintainer of that repo keeps it in a working state, then I would suggest going through the steps in the Developer Guide and make sure you execute each of them. If you skipped any, or if any of them had a problem when running, then that could mean that some necessary assembly was not downloaded/built/installed which would cause the error you are seeing.
Also, the
EnhancedStackTracein the C# code and theEnhancedStackTracein the C++ code could be (and very likely are) two different type definitions that just share a name, likeintegerorstring.