Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mod fails to compile for unresolved FNA during pdb generation #785

Closed
sgkoishi opened this issue Feb 3, 2020 · 4 comments
Closed

Mod fails to compile for unresolved FNA during pdb generation #785

sgkoishi opened this issue Feb 3, 2020 · 4 comments
Assignees

Comments

@sgkoishi
Copy link
Contributor

sgkoishi commented Feb 3, 2020

Description

When I compile the mod in CI with includePDB = true, the game was unable to locate the FNA during writing PDB symbol.
The source code of the mod does not locate in the Mod Source folder.
Similar to #672

Log File

Compiling XXX.XNA.dll
Compilation finished with 0 errors and 3 warnings
Compiling XXX.FNA.dll
Compilation finished with 0 errors and 3 warnings
Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'FNA, Version=17.3.0.0, Culture=neutral, PublicKeyToken=null'
   at Mono.Cecil.BaseAssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters)
   at Mono.Cecil.DefaultAssemblyResolver.Resolve(AssemblyNameReference name)
   at Mono.Cecil.MetadataResolver.Resolve(TypeReference type)
   at Mono.Cecil.TypeReference.Resolve()
   at Mono.Cecil.Mixin.CheckedResolve(TypeReference self)
   at Mono.Cecil.MetadataBuilder.GetConstantType(TypeReference constant_type, Object constant)
   at Mono.Cecil.MetadataBuilder.AddConstant(IConstantProvider owner, TypeReference type)
   at Mono.Cecil.MetadataBuilder.AddParameter(UInt16 sequence, ParameterDefinition parameter, ParamTable table)
   at Mono.Cecil.MetadataBuilder.AddParameters(MethodDefinition method)
   at Mono.Cecil.MetadataBuilder.AddMethod(MethodDefinition method)
   at Mono.Cecil.MetadataBuilder.AddMethods(TypeDefinition type)
   at Mono.Cecil.MetadataBuilder.AddType(TypeDefinition type)
   at Mono.Cecil.MetadataBuilder.AddTypes()
   at Mono.Cecil.MetadataBuilder.BuildTypes()
   at Mono.Cecil.MetadataBuilder.BuildModule()
   at Mono.Cecil.MetadataBuilder.BuildMetadata()
   at Mono.Cecil.ModuleWriter.<>c.<BuildMetadata>b__2_0(MetadataBuilder builder, MetadataReader _)
   at Mono.Cecil.ModuleDefinition.Read[TItem,TRet](TItem item, Func`3 read)
   at Mono.Cecil.ModuleWriter.BuildMetadata(ModuleDefinition module, MetadataBuilder metadata)
   at Mono.Cecil.ModuleWriter.Write(ModuleDefinition module, Disposable`1 stream, WriterParameters parameters)
   at Mono.Cecil.ModuleWriter.WriteModule(ModuleDefinition module, Disposable`1 stream, WriterParameters parameters)       at Mono.Cecil.ModuleDefinition.Write(String fileName, WriterParameters parameters)
   at Terraria.ModLoader.Core.ModCompile.BuildModForPlatform(BuildingMod mod, List`1& refMods, Boolean xna)
   at Terraria.ModLoader.Core.ModCompile.Build(BuildingMod mod)
   at Terraria.ModLoader.Core.ModCompile.BuildModCommandLine(String modFolder)

Expected behavior

Compile should not fail.

Actual behavior

FNA was not found in all given search path, so AssemblyResolutionException was thrown.

Additional Information

using (var asmResolver = new DefaultAssemblyResolver()) {
asmResolver.AddSearchDirectory(Path.GetDirectoryName(dllPath));
asmResolver.AddSearchDirectory(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
var asm = AssemblyDefinition.ReadAssembly(dllPath, new ReaderParameters { InMemory = true, ReadSymbols = mod.properties.includePDB, AssemblyResolver = asmResolver });
VerifyModAssembly(mod.Name, asm);
if (!mod.properties.includePDB)
return;
// when reading and writing a module with cecil, the debug sequence points need regenerating, even if the methods are not changed
// write out the pdb file using cecil because doing it at runtime is difficult
var tempDllPath = Path.Combine(tempDir, dllName); //use the temp dir to avoid overwriting a precompiled dll
// force the native pdb writer when possible, to support stack traces on older .NET frameworks
asm.Write(tempDllPath, new WriterParameters {
WriteSymbols = true,
SymbolWriterProvider = FrameworkVersion.Framework == Framework.NetFramework ? new NativePdbWriterProvider() : null
});

Only the compile_temp and game executable path was added, ModCompile was not.

@JavidPack
Copy link
Collaborator

By CI do you mean continuous integration? if so, you'll need to show how you are setting that up, since it seems to me to be an issue with that.

@sgkoishi
Copy link
Contributor Author

sgkoishi commented Feb 4, 2020

By CI do you mean continuous integration? if so, you'll need to show how you are setting that up, since it seems to me to be an issue with that.

Pretty much it's just a simple call Process.Start(Path.Combine(GAME_PATH, "tModLoaderServer.exe"), "-build XXX -unsafe") - I've reproduce it locally using cmd.
Attaching with dnSpy locate the problem to the asm.Write - the game can not find FNA.dll in either game folder or compile_temp folder (it's in ModCompile folder).

asm.Write(tempDllPath, new WriterParameters {
WriteSymbols = true,
SymbolWriterProvider = FrameworkVersion.Framework == Framework.NetFramework ? new NativePdbWriterProvider() : null
});

This problem doesn't appear after I set includePDB = false (as line 498)

if (!mod.properties.includePDB)
return;

The CI part is here - Action
I'm not sure if I miss anything, but at least it works correctly when includePDB = false

@Chicken-Bones
Copy link
Member

Chicken-Bones commented Feb 4, 2020 via email

@sgkoishi
Copy link
Contributor Author

sgkoishi commented Feb 4, 2020

tML_issue785.zip
Here's the minimal version.

build.txt:

displayName = tML_issue785
author = SGKoishi
version = 1.0
includePDB = true

code:

using Terraria.ModLoader;
using Microsoft.Xna.Framework.Graphics;

namespace tML_issue785
{
    public class tML_issue785 : Mod
    {
        private void method(SpriteEffects sf = SpriteEffects.None)
        {
            
        }
    }
}

@Chicken-Bones Chicken-Bones self-assigned this Feb 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants