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

Mono.ArgumentNullOrEmptyException When trying to write embedded symbols assembly to stream #920

Open
Tacodiva opened this issue Jul 24, 2023 · 0 comments

Comments

@Tacodiva
Copy link

I want to write an AssemblyDefinition with symbols embedded to a stream. I am doing:

definition.Write(byteStream, new() {
    WriteSymbols = true
});

But this throws an exception:

Mono.ArgumentNullOrEmptyException: Argument null or empty (Parameter 'fileName')
   at Mono.Cecil.Mixin.CheckFileName(String fileName)
   at Mono.Cecil.Cil.EmbeddedPortablePdbWriterProvider.GetSymbolWriter(ModuleDefinition module, String fileName)
   at Mono.Cecil.Cil.DefaultSymbolWriterProvider.GetSymbolWriter(ModuleDefinition module, String fileName)
   at Mono.Cecil.ModuleWriter.GetSymbolWriter(ModuleDefinition module, String fq_name, ISymbolWriterProvider symbol_writer_provider, WriterParameters parameters)
   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(Stream stream, WriterParameters parameters)
   at Mono.Cecil.AssemblyDefinition.Write(Stream stream, WriterParameters parameters)
   ...

I have not tested this, but I believe the call to CheckFileName in EmbeddedPortablePdbWriterProvider.GetSymbolWriter is not necessary, as I don't think the file name is used by EmbeddedPortablePdbWriter.

public ISymbolWriter GetSymbolWriter (ModuleDefinition module, string fileName)
{
Mixin.CheckModule (module);
Mixin.CheckFileName (fileName);
var stream = new MemoryStream ();
var pdb_writer = (PortablePdbWriter) new PortablePdbWriterProvider ().GetSymbolWriter (module, stream);
return new EmbeddedPortablePdbWriter (stream, pdb_writer);
}

Because of this check, it seems to be impossible to write embedded symbols without writing into a file.

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

1 participant