提交 e4981ac8 编写于 作者: J Jared Parsons

Merge pull request #9504 from TyOverby/allow-cancelation

allow cancelation exceptions through the PE stream diagnostic filter
...@@ -2976,5 +2976,24 @@ public static void Main() ...@@ -2976,5 +2976,24 @@ public static void Main()
// error CS8104: An error occurred while writing the Portable Executable file. // error CS8104: An error occurred while writing the Portable Executable file.
Diagnostic(ErrorCode.ERR_PeWritingFailure).WithArguments("I/O error occurred.").WithLocation(1, 1)); Diagnostic(ErrorCode.ERR_PeWritingFailure).WithArguments("I/O error occurred.").WithLocation(1, 1));
} }
[Fact]
[WorkItem(9308, "https://github.com/dotnet/roslyn/issues/9308")]
public void FailingEmitterAllowsCancelationExceptionsThrough()
{
string source = @"
public class X
{
public static void Main()
{
}
}";
var compilation = CreateCompilationWithMscorlib(source);
var broken = new BrokenStream();
broken.BreakHow = 3;
Assert.Throws<OperationCanceledException>(() => compilation.Emit(broken));
}
} }
} }
...@@ -96,7 +96,7 @@ internal sealed class PeWriter ...@@ -96,7 +96,7 @@ internal sealed class PeWriter
return peWriter.WritePeToStream(mdWriter, getPeStream, getPortablePdbStreamOpt, nativePdbWriterOpt); return peWriter.WritePeToStream(mdWriter, getPeStream, getPortablePdbStreamOpt, nativePdbWriterOpt);
} }
catch (Exception ex) when (!(ex is PdbWritingException || ex is ResourceException || ex is PermissionSetFileReadException)) catch (Exception ex) when (!(ex is PdbWritingException || ex is ResourceException || ex is PermissionSetFileReadException || ex is OperationCanceledException))
{ {
throw new PeWritingException(ex); throw new PeWritingException(ex);
} }
......
...@@ -68,7 +68,13 @@ public override void SetLength(long value) ...@@ -68,7 +68,13 @@ public override void SetLength(long value)
public override void Write(byte[] buffer, int offset, int count) public override void Write(byte[] buffer, int offset, int count)
{ {
if (BreakHow == 0) if (BreakHow == 0)
{
throw new IOException(); throw new IOException();
}
if (BreakHow == 3)
{
throw new OperationCanceledException();
}
} }
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册