为什么我会收到此错误?错误 CS0103:名称“EnhancedStackTrace”在当前上下文中不存在

问题描述 投票:0回答:1

我是 C# 和 cpp 的初学者,当我尝试从 FiveM 启动器开源代码 FiveM 启动器开源代码构建 FiveM 启动器时,我在执行 fxd 构建后收到此错误。

"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]

这是 InternalManager.cs 第 575 行到第 634 行代码的一部分,我在其中收到 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);
            }
        }

并且 EnhancedStackTrace 也在文件 MonoComponentHost.cpp 中使用,并且使用它的这部分代码是从第 267 行到第 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;
    }
}

我尝试通过询问 cfx.re 社区的一些人来修复问题,但这并没有多大帮助!我也在网上查了一下,唯一找到的是微软针对他的错误错误CS0103的错误指南,但也是无奈啊!而其他遇到此错误的人对我来说并没有真正的帮助......所以现在我请求你们帮助我,因为我看不出还有什么地方可以找到任何答案和快速答案!是的,我已经遵循了小文档中的所有流程。

c# build compiler-errors fivem
1个回答
0
投票

为什么我会收到此错误?错误 CS0103:名称“EnhancedStackTrace”在当前上下文中不存在

您收到此错误是因为编译器/Visual Studio 无法在程序代码中或任何引用的程序集 (dll) 中找到名为

EnhancedStackTrace
的类型。

如果我假设该存储库的维护者将其保持在工作状态,那么我建议您完成开发人员指南中的步骤,并确保执行每个步骤。如果您跳过任何一个,或者其中任何一个在运行时出现问题,那么这可能意味着某些必要的程序集未下载/构建/安装,这将导致您看到的错误。

此外,C# 代码中的

EnhancedStackTrace
和 C++ 代码中的
EnhancedStackTrace
可能(而且很可能是)两个不同的类型定义,只是共享一个名称,例如
integer
string

© www.soinside.com 2019 - 2024. All rights reserved.