【问题标题】:Running MRTK2 project gives " Failed to resolve System.Reflection.BindingFlags"运行 MRTK2 项目给出“无法解析 System.Reflection.BindingFlags”
【发布时间】:2019-06-18 20:48:25
【问题描述】:

我正在尝试将我的项目从 Unity 2017 LTS 移植到 2018 LTS 和 MRTK2。在我尝试在 HoloLens 1 模拟器上运行该项目之前,一切都很顺利。

我收到以下错误:

1>  System.Exception: Failed to resolve System.Reflection.BindingFlags
1>     at Unity.ModuleContext.Retarget(TypeReference type, GenericContext context)
1>     at Unity.ModuleContext.Retarget(MethodReference method, GenericContext context)
1>     at Unity.FixReferencesStep.Visit(MethodDefinition method, GenericContext context)
1>     at Unity.FixReferencesStep.Visit(TypeDefinition type)
1>     at Unity.TypeDefinitionDispatcher.DispatchType(TypeDefinition type)
1>     at Unity.TypeDefinitionDispatcher.DispatchType(TypeDefinition type)
1>     at Unity.TypeDefinitionDispatcher..ctor(ModuleDefinition module, ITypeDefinitionVisitor visitor)
1>     at Unity.FixReferencesStep.ProcessModule()
1>     at Unity.ModuleStep.Execute()
1>     at Unity.FixReferencesStep.Execute()
1>     at Unity.Step.Execute(OperationContext operationContext, IStepContext previousStepContext)
1>     at Unity.Operation.Execute()
1>     at Unity.Program.Main(String[] args)

搜索这个错误什么也没给我,我没有更改 Unity 构建的项目。我在Debugx86 中运行它。我正在通过普通的 Unity Build 窗口进行构建。

使用Minimum Platform Version 10.0.17134.0Target SDK Version 10.0.18362.0

新的空 Unity 项目也会出现这种情况,构建示例也会出现此错误。

【问题讨论】:

  • dotNET 版本更新了吗?
  • 在 Unity 中?我在.Net 4.x Equivalent Scripting Backend .NETApi Compatibility Level Api Compatibility Level .Net 4.x 上有Scripting Runtime Version
  • @AndreyChistyakov 我刚刚测试过,这也发生在一个全新的项目中。只有 MRTK 2 的空 Unity 项目,构建示例也会出现此错误。

标签: unity3d hololens mrtk


【解决方案1】:

我遇到了类似的问题,为了解决这个问题,我改用了 il​​2cpp 后端。

【讨论】:

  • 这行得通,但我需要在 .net 后端停留一段时间。
【解决方案2】:

意识到这可能不仅仅是我,我提交了an issue in the MRTK github。事实证明这是 Visual Studio 中的一个错误,他们正在与 Microsoft 一起解决它。

There's two ways to solve it,将 Windows 版本 15063 作为最低版本或更改 yourpoject.csproj。

如果您不想更改最低版本,请执行以下步骤:

  1. 在文本编辑器中打开你的项目.csproj

  2. 找到<Target Name="BeforeResolveReferences" Condition="'$(BuildingProject)' == 'true'">这一行

  3. 替换为:

    <UsingTask TaskName="FixProjectJson" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
        <ParameterGroup />
        <Task>
          <Using Namespace="System" />
          <Using Namespace="System.IO" />
          <Code Type="Fragment" Language="cs">
            <![CDATA[File.WriteAllText("project.lock.json", File.ReadAllText("project.lock.json").Replace("ref/netstandard1.5/System.Reflection.TypeExtensions.dll", "ref/netstandard1.3/System.Reflection.TypeExtensions.dll"));]]>
          </Code>
        </Task>
      </UsingTask>
      <Target Name="BeforeResolveReferences" Condition="'$(BuildingProject)' == 'true'">
    
  4. 找到&lt;Message Importance="high" Text="Running AssemblyConverter..." /&gt;这一行

  5. 替换为:

    <Message Importance="high" Text="Running AssemblyConverter..." />
    <FixProjectJson />
    

完成此操作后,我的项目终于编译完成,我能够在 HoloLens 2 模拟器中运行它。

【讨论】:

    猜你喜欢
    • 2020-08-31
    • 2021-06-09
    • 2011-03-13
    • 2020-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-09-28
    相关资源
    最近更新 更多