<Compile Condition="'$(FeatureICastable)' == 'true'" Include="$(BclSourcesRoot)\System\Runtime\CompilerServices\ICastable.cs" />
<Compile Include="$(BclSourcesRoot)\System\Runtime\CompilerServices\ConditionalWeakTable.cs" />
<Compile Include="$(BclSourcesRoot)\System\Runtime\CompilerServices\AsyncMethodBuilder.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Runtime\CompilerServices\TaskAwaiter.cs" />
</ItemGroup>
<ItemGroup>
<Compile Include="$(BclSourcesRoot)\System\Runtime\MemoryFailPoint.cs" />
<Compile Condition="'$(FeatureClassicCominterop)' == 'true'" Include="$(BclSourcesRoot)\Microsoft\Win32\OAVariantLib.cs" />
</ItemGroup>
<ItemGroup>
- <Compile Include="$(BclSourcesRoot)\System\Resources\__FastResourceComparer.cs" />
<Compile Include="$(BclSourcesRoot)\System\Resources\FileBasedResourceGroveler.cs" />
<Compile Include="$(BclSourcesRoot)\System\Resources\IResourceGroveler.cs" />
<Compile Include="$(BclSourcesRoot)\System\Resources\ManifestBasedResourceGroveler.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Reflection\TypeInfo.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\ResolveEventArgs.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\ResolveEventHandler.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)System\Resources\FastResourceComparer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Resources\IResourceReader.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Resources\MissingManifestResourceException.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Resources\MissingSatelliteAssemblyException.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\StringFreezingAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\StrongBox.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\SuppressIldasmAttribute.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\TaskAwaiter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\TupleElementNamesAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\TypeForwardedFromAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\TypeForwardedToAttribute.cs" />
//
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-using System;
using System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
-using System.Security;
+using System.Diagnostics.Tracing;
using System.Threading;
using System.Threading.Tasks;
-using System.Diagnostics.Tracing;
+#if !CORECLR
+using Internal.Threading.Tasks.Tracing;
+#endif
// NOTE: For performance reasons, initialization is not verified. If a developer
// incorrectly initializes a task awaiter, which should only be done by the compiler,
// If TaskWait* ETW events are enabled, trace a beginning event for this await
// and set up an ending event to be traced when the asynchronous await completes.
- if (TplEtwProvider.Log.IsEnabled() || Task.s_asyncDebuggingEnabled)
+ if (
+#if CORECLR
+ TplEtwProvider.Log.IsEnabled() || Task.s_asyncDebuggingEnabled
+#else
+ TaskTrace.Enabled
+#endif
+ )
{
continuation = OutputWaitEtwEvents(task, continuation);
}
task.SetContinuationForAwait(continuation, continueOnCapturedContext, flowExecutionContext);
}
+#if CORECLR
/// <summary>Schedules the continuation onto the <see cref="System.Threading.Tasks.Task"/> associated with this <see cref="TaskAwaiter"/>.</summary>
/// <param name="task">The task being awaited.</param>
/// <param name="continuation">The action to invoke when the await operation completes.</param>
task.UnsafeSetContinuationForAwait(stateMachineBox, continueOnCapturedContext);
}
}
-
+#endif
/// <summary>
/// Outputs a WaitBegin ETW event, and augments the continuation action to output a WaitEnd ETW event.
/// </summary>
{
Debug.Assert(task != null, "Need a task to wait on");
Debug.Assert(continuation != null, "Need a continuation to invoke when the wait completes");
-
+#if CORECLR
if (Task.s_asyncDebuggingEnabled)
{
Task.AddToActiveTasks(task);
task.Id, TplEtwProvider.TaskWaitBehavior.Asynchronous,
(continuationTask != null ? continuationTask.Id : 0));
}
+#else
+ Debug.Assert(TaskTrace.Enabled, "Should only be used when ETW tracing is enabled");
+
+ // ETW event for Task Wait Begin
+ var currentTaskAtBegin = Task.InternalCurrent;
+ TaskTrace.TaskWaitBegin_Asynchronous(
+ (currentTaskAtBegin != null ? currentTaskAtBegin.m_taskScheduler.Id : TaskScheduler.Default.Id),
+ (currentTaskAtBegin != null ? currentTaskAtBegin.Id : 0),
+ task.Id);
+#endif
// Create a continuation action that outputs the end event and then invokes the user
// provided delegate. This incurs the allocations for the closure/delegate, but only if the event
// is enabled, and in doing so it allows us to pass the awaited task's information into the end event
// in a purely pay-for-play manner (the alternatively would be to increase the size of TaskAwaiter
// just for this ETW purpose, not pay-for-play, since GetResult would need to know whether a real yield occurred).
+#if CORECLR
return AsyncMethodBuilderCore.CreateContinuationWrapper(continuation, (innerContinuation,innerTask) =>
{
if (Task.s_asyncDebuggingEnabled)
EventSource.SetCurrentThreadActivityId(prevActivityId);
}
}, task);
+#else
+ return () =>
+ {
+ // ETW event for Task Wait End.
+ if (TaskTrace.Enabled)
+ {
+ var currentTaskAtEnd = Task.InternalCurrent;
+ TaskTrace.TaskWaitEnd(
+ (currentTaskAtEnd != null ? currentTaskAtEnd.m_taskScheduler.Id : TaskScheduler.Default.Id),
+ (currentTaskAtEnd != null ? currentTaskAtEnd.Id : 0),
+ task.Id);
+ }
+
+ // Invoke the original continuation provided to OnCompleted.
+ continuation();
+ };
+#endif
}
}
// Its layout must remain the same.
/// <summary>The task being awaited.</summary>
- internal readonly Task m_task;
+ internal readonly Task m_task;
/// <summary>Whether to attempt marshaling back to the original context.</summary>
- internal readonly bool m_continueOnCapturedContext;
+ internal readonly bool m_continueOnCapturedContext;
/// <summary>Initializes the <see cref="ConfiguredTaskAwaiter"/>.</summary>
/// <param name="task">The <see cref="System.Threading.Tasks.Task"/> to await.</param>
throw new ArgumentNullException(nameof(encoding));
}
if (!input.CanRead)
+ {
throw new ArgumentException(SR.Argument_StreamNotReadable);
+ }
+
_stream = input;
_decoder = encoding.GetDecoder();
_maxCharsSize = encoding.GetMaxCharCount(MaxCharBytesSize);
int minBufferSize = encoding.GetMaxByteCount(1); // max bytes per one char
if (minBufferSize < 16)
+ {
minBufferSize = 16;
+ }
+
_buffer = new byte[minBufferSize];
// _charBuffer and _charBytes will be left null.
}
}
- public virtual void Close()
- {
- Dispose(true);
- }
-
protected virtual void Dispose(bool disposing)
{
if (disposing)
Stream copyOfStream = _stream;
_stream = null;
if (copyOfStream != null && !_leaveOpen)
+ {
copyOfStream.Close();
+ }
}
_stream = null;
_buffer = null;
Dispose(true);
}
+ /// <remarks>
+ /// Override Dispose(bool) instead of Close(). This API exists for compatibility purposes.
+ /// </remarks>
+ public virtual void Close()
+ {
+ Dispose(true);
+ }
+
public virtual int PeekChar()
{
- if (_stream == null) throw Error.GetFileNotOpen();
+ if (_stream == null)
+ {
+ throw Error.GetFileNotOpen();
+ }
if (!_stream.CanSeek)
+ {
return -1;
+ }
+
long origPos = _stream.Position;
int ch = Read();
_stream.Position = origPos;
public virtual byte ReadByte()
{
// Inlined to avoid some method call overhead with FillBuffer.
- if (_stream == null) throw Error.GetFileNotOpen();
+ if (_stream == null)
+ {
+ throw Error.GetFileNotOpen();
+ }
int b = _stream.ReadByte();
if (b == -1)
+ {
throw Error.GetEndOfFile();
+ }
+
return (byte)b;
}
{
if (_isMemoryStream)
{
- if (_stream == null) throw Error.GetFileNotOpen();
+ if (_stream == null)
+ {
+ throw Error.GetFileNotOpen();
+ }
+
// read directly from MemoryStream buffer
MemoryStream mStream = _stream as MemoryStream;
Debug.Assert(mStream != null, "_stream as MemoryStream != null");
public virtual string ReadString()
{
if (_stream == null)
+ {
throw Error.GetFileNotOpen();
+ }
int currPos = 0;
int n;
charsRead = _decoder.GetChars(_charBytes, 0, n, _charBuffer, 0);
if (currPos == 0 && n == stringLength)
+ {
return new string(_charBuffer, 0, charsRead);
+ }
if (sb == null)
+ {
sb = StringBuilderCache.Acquire(stringLength); // Actual string length in chars may be smaller.
+ }
+
sb.Append(_charBuffer, 0, charsRead);
currPos += n;
} while (currPos < stringLength);
{
throw new ArgumentException(SR.Argument_InvalidOffLen);
}
-
if (_stream == null)
+ {
throw Error.GetFileNotOpen();
+ }
// SafeCritical: index and count have already been verified to be a valid range for the buffer
return InternalReadChars(new Span<char>(buffer, index, count));
public virtual int Read(Span<char> buffer)
{
if (_stream == null)
+ {
throw Error.GetFileNotOpen();
+ }
return InternalReadChars(buffer);
}
if (_2BytesPerChar)
numBytes <<= 1;
if (numBytes > MaxCharBytesSize)
+ {
numBytes = MaxCharBytesSize;
+ }
int position = 0;
byte[] byteBuffer = null;
}
Debug.Assert(byteBuffer != null, "expected byteBuffer to be non-null");
-
checked
{
if (position < 0 || numBytes < 0 || position > byteBuffer.Length - numBytes)
long posSav = posSav = 0;
if (_stream.CanSeek)
+ {
posSav = _stream.Position;
+ }
if (_charBytes == null)
{
- _charBytes = new byte[MaxCharBytesSize];
+ _charBytes = new byte[MaxCharBytesSize]; //REVIEW: We need at most 2 bytes/char here?
}
if (_singleChar == null)
{
int r = _stream.ReadByte();
_charBytes[0] = (byte)r;
if (r == -1)
+ {
numBytes = 0;
+ }
if (numBytes == 2)
{
r = _stream.ReadByte();
_charBytes[1] = (byte)r;
if (r == -1)
+ {
numBytes = 1;
+ }
}
if (numBytes == 0)
// Handle surrogate char
if (_stream.CanSeek)
+ {
_stream.Seek((posSav - _stream.Position), SeekOrigin.Current);
+ }
// else - we can't do much here
throw;
if (count == 0)
{
- return Array.Empty<Char>();
+ return Array.Empty<char>();
}
// SafeCritical: we own the chars buffer, and therefore can guarantee that the index and count are valid
public virtual int Read(byte[] buffer, int index, int count)
{
if (buffer == null)
+ {
throw new ArgumentNullException(nameof(buffer), SR.ArgumentNull_Buffer);
+ }
if (index < 0)
+ {
throw new ArgumentOutOfRangeException(nameof(index), SR.ArgumentOutOfRange_NeedNonNegNum);
+ }
if (count < 0)
+ {
throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
+ }
if (buffer.Length - index < count)
+ {
throw new ArgumentException(SR.Argument_InvalidOffLen);
+ }
+ if (_stream == null)
+ {
+ throw Error.GetFileNotOpen();
+ }
- if (_stream == null) throw Error.GetFileNotOpen();
return _stream.Read(buffer, index, count);
}
public virtual int Read(Span<byte> buffer)
{
if (_stream == null)
+ {
throw Error.GetFileNotOpen();
+ }
return _stream.Read(buffer);
}
public virtual byte[] ReadBytes(int count)
{
- if (count < 0) throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
- if (_stream == null) throw Error.GetFileNotOpen();
+ if (count < 0)
+ {
+ throw new ArgumentOutOfRangeException(nameof(count), SR.ArgumentOutOfRange_NeedNonNegNum);
+ }
+ if (_stream == null)
+ {
+ throw new ObjectDisposedException(null, SR.ObjectDisposed_FileClosed);
+ }
if (count == 0)
{
- return Array.Empty<Byte>();
+ return Array.Empty<byte>();
}
byte[] result = new byte[count];
-
int numRead = 0;
do
{
int n = _stream.Read(result, numRead, count);
if (n == 0)
+ {
break;
+ }
+
numRead += n;
count -= n;
} while (count > 0);
{
throw new ArgumentOutOfRangeException(nameof(numBytes), SR.ArgumentOutOfRange_BinaryReaderFillBuffer);
}
+
int bytesRead = 0;
int n = 0;
- if (_stream == null) throw Error.GetFileNotOpen();
+ if (_stream == null)
+ {
+ throw Error.GetFileNotOpen();
+ }
// Need to find a good threshold for calling ReadByte() repeatedly
// vs. calling Read(byte[], int, int) for both buffered & unbuffered
{
n = _stream.ReadByte();
if (n == -1)
+ {
throw Error.GetEndOfFile();
+ }
+
_buffer[0] = (byte)n;
return;
}
} while (bytesRead < numBytes);
}
- internal protected int Read7BitEncodedInt()
+ protected internal int Read7BitEncodedInt()
{
// Read out an Int32 7 bits at a time. The high bit
// of the byte when on means to continue reading more bytes.
// Check for a corrupted stream. Read a max of 5 bytes.
// In a future version, add a DataFormatException.
if (shift == 5 * 7) // 5 bytes max per Int32, shift += 7
+ {
throw new FormatException(SR.Format_Bad7BitInt32);
+ }
// ReadByte handles end of stream cases for us.
b = ReadByte();
// If you modify any of these fields, you must also update the
// AssemblyBaseObject structure in object.h
//
- private String _Name; // Name
+ private string _Name; // Name
private byte[] _PublicKey;
private byte[] _PublicKeyToken;
private CultureInfo _CultureInfo;
- private String _CodeBase; // Potential location to get the file
+ private string _CodeBase; // Potential location to get the file
private Version _Version;
private StrongNameKeyPair _StrongNameKeyPair;
// Set and get the name of the assembly. If this is a weak Name
// then it optionally contains a site. For strong assembly names,
// the name partitions up the strong name's namespace
- public String Name
+ public string Name
{
get { return _Name; }
set { _Name = value; }
}
}
- public String CultureName
+ public string CultureName
{
get
{
}
}
- public String CodeBase
+ public string CodeBase
{
get { return _CodeBase; }
set { _CodeBase = value; }
}
- public String EscapedCodeBase
+ public string EscapedCodeBase
{
get
{
// Make a copy of this assembly name.
- public Object Clone()
+ public object Clone()
{
AssemblyName name = new AssemblyName();
name.Init(_Name,
* if the file contains an assembly manifest. This method causes
* the file to be opened and closed.
*/
- public static AssemblyName GetAssemblyName(String assemblyFile)
+ public static AssemblyName GetAssemblyName(string assemblyFile)
{
if (assemblyFile == null)
throw new ArgumentNullException(nameof(assemblyFile));
set { _StrongNameKeyPair = value; }
}
- public String FullName
+ public string FullName
{
get
{
}
// Returns the stringized version of the assembly name.
- public override String ToString()
+ public override string ToString()
{
- String s = FullName;
+ string s = FullName;
if (s == null)
return base.ToString();
else
throw new PlatformNotSupportedException();
}
- public void OnDeserialization(Object sender)
+ public void OnDeserialization(object sender)
{
throw new PlatformNotSupportedException();
}
- public AssemblyName(String assemblyName)
+ public AssemblyName(string assemblyName)
{
if (assemblyName == null)
throw new ArgumentNullException(nameof(assemblyName));
return ProcessorArchitecture.None;
}
- internal void Init(String name,
+ internal void Init(string name,
byte[] publicKey,
byte[] publicKeyToken,
Version version,
CultureInfo cultureInfo,
AssemblyHashAlgorithm hashAlgorithm,
AssemblyVersionCompatibility versionCompatibility,
- String codeBase,
+ string codeBase,
AssemblyNameFlags flags,
StrongNameKeyPair keyPair) // Null if ref, matching Assembly if def
{
// This call opens and closes the file, but does not add the
// assembly to the domain.
[MethodImplAttribute(MethodImplOptions.InternalCall)]
- internal static extern AssemblyName nGetFileInformation(String s);
+ internal static extern AssemblyName nGetFileInformation(string s);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private extern byte[] nGetPublicKeyToken();
- internal static String EscapeCodeBase(String codebase)
+ internal static string EscapeCodeBase(string codebase)
{
if (codebase == null)
return string.Empty;
c_MaxUnicodeCharsReallocate * c_MaxUTF_8BytesPerUnicodeChar);
// This is the only exception that built in UriParser can throw after a Uri ctor.
- // Should not happen unless the app tries to feed an invalid Unicode String
+ // Should not happen unless the app tries to feed an invalid Unicode string
if (numberOfBytes == 0)
throw new FormatException(SR.Arg_FormatException);
ResourceSet rs = null;
// Don't use Assembly manifest, but grovel on disk for a file.
-
// Create new ResourceSet, if a file exists on disk for it.
String tempFileName = _mediator.GetResourceFileName(culture);
fileName = FindResourceFile(culture, tempFileName);
}
// Perf optimization - Don't use Reflection for most cases with
- // our .resources files. This makes our code run faster and we can
+ // our .resources files. This makes our code run faster and we can avoid
// creating a ResourceReader via Reflection. This would incur
// a security check (since the link-time check on the constructor that
// takes a String is turned into a full demand with a stack walk)
}
}
-
public sealed class ResourceReader : IResourceReader
{
// A reasonable default buffer size for reading from files, especially
{
throw new FormatException(SR.Format(SR.BadImageFormat_ResourcesDataInvalidOffset, dataPos));
}
-
ResourceTypeCode junk;
if (_version == 1)
return LoadObjectV1(dataPos);
if (typeCode == ResourceTypeCode.String) // ignore Null
s = _store.ReadString();
}
-
return s;
}
throw new NotSupportedException(SR.NotSupported_ResourceObjectSerialization);
}
-
-
// Reads in the header information for a .resources file. Verifies some
// of the assumptions about this resource set, and builds the class table
// for the default resource file format.
return _typeTable[typeIndex];
}
-
public void GetResourceData(string resourceName, out string resourceType, out byte[] resourceData)
{
if (resourceName == null)
}
}
-
-
internal sealed class ResourceEnumerator : IDictionaryEnumerator
{
private const int ENUM_DONE = Int32.MinValue;