Skip to content

Commit

Permalink
Use Strings.resx file for the exception messages (dotnet#40402)
Browse files Browse the repository at this point in the history
* Use Strings.resx file for the exception messages within  System.Windows.Extensions

* Use Strings resx file for the exception messages within System.Threading

* Use Strings resx file for the exception messages within System.Security.Cryptography.Xml

* Use Strings resx file for the exception messages within System.Runtime.WindowsRuntime

* Use Strings resx file for the exception messages within System.Reflection.Metadata

* Use Strings resx file for the exception messages within System.Private.Xml

* Use Strings resx file for the exception messages within System.Private.DataContractSerialization

* Use Strings resx file for the exception messages within System.Numerics.Tensors

* Use Strings resx file for the exception messages within System.IO.Packaging

* Use Strings resx file for the exception messages within System.IO.FileSystem

* Use Strings resx file for the exception messages within System.Drawing.Common

* Use Strings resx file for the exception messages within System.DirectoryServices

* Use Strings resx file for the exception messages within System.Diagnostics.DiagnosticSource

* Use Strings resx file for the exception messages within System.Composition.Hosting

* Update ExportDescriptorPromise.cs

* Fix build
  • Loading branch information
Marusyk authored and stephentoub committed Nov 13, 2019
1 parent 784cb6b commit 1518fdc
Show file tree
Hide file tree
Showing 37 changed files with 344 additions and 94 deletions.
5 changes: 4 additions & 1 deletion src/System.Composition.Hosting/src/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,7 @@
<data name="Diagnostic_InternalExceptionMessage" xml:space="preserve">
<value>Internal error occurred. Additional information: '{0}'.</value>
</data>
</root>
<data name="Update_already_executed" xml:space="preserve">
<value>The update has already executed.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void Execute(CompositionContract contract)
{
// Opportunism - we'll miss recursive calls to Execute(), but this will catch some problems
// and the _updateFinished flag is required for other purposes anyway.
if (_updateFinished) throw new InvalidOperationException("The update has already executed.");
if (_updateFinished) throw new InvalidOperationException(SR.Update_already_executed);

CompositionDependency initial;
if (TryResolveOptionalDependency("initial request", contract, true, out initial))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@
<data name="ActivityIdFormatInvalid" xml:space="preserve">
<value>"Value must be a valid ActivityIdFormat value"</value>
</data>
<data name="ActivityNotRunning" xml:space="preserve">
<value>Trying to set an Activity that is not running</value>
</data>
<data name="ActivityNotStarted" xml:space="preserve">
<value>"Can not stop an Activity that was not started"</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ private static bool ValidateSetCurrent(Activity? activity)
bool canSet = activity == null || (activity.Id != null && !activity.IsFinished);
if (!canSet)
{
NotifyError(new InvalidOperationException("Trying to set an Activity that is not running"));
NotifyError(new InvalidOperationException(SR.ActivityNotRunning));
}

return canSet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public int IndexOf(ActiveDirectorySiteLink link)
public void Insert(int index, ActiveDirectorySiteLink link)
{
if (link == null)
throw new ArgumentNullException("value");
throw new ArgumentNullException(nameof(link));

if (!link.existing)
throw new InvalidOperationException(SR.Format(SR.SiteLinkNotCommitted, link.Name));
Expand Down
47 changes: 46 additions & 1 deletion src/System.Drawing.Common/src/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -410,4 +410,49 @@
<data name="EntryPointNotFoundExceptionMessage" xml:space="preserve">
<value>Unable to find an entry point named '{0}' in DLL '{1}'.</value>
</data>
</root>
<data name="AvailableOnlyOnWMF" xml:space="preserve">
<value>{0} only available on WMF files.</value>
</data>
<data name="CannotCreateGraphics" xml:space="preserve">
<value>Cannot create Graphics from an indexed bitmap.</value>
</data>
<data name="CouldNotOpenDisplay" xml:space="preserve">
<value>Could not open display (X-Server required. Check your DISPLAY environment variable)</value>
</data>
<data name="CouldntFindSpecifiedFile" xml:space="preserve">
<value>Couldn't find specified file.</value>
</data>
<data name="IconInstanceWasDisposed" xml:space="preserve">
<value>Icon instance was disposed.</value>
</data>
<data name="InvalidGraphicsUnit" xml:space="preserve">
<value>Invalid GraphicsUnit</value>
</data>
<data name="InvalidThumbnailSize" xml:space="preserve">
<value>Invalid thumbnail size</value>
</data>
<data name="NoCodecAvailableForFormat" xml:space="preserve">
<value>No codec available for format:{0}</value>
</data>
<data name="NotImplementedUnderX11" xml:space="preserve">
<value>Operation not implemented under X11</value>
</data>
<data name="NoValidIconImageFound" xml:space="preserve">
<value>No valid icon image found</value>
</data>
<data name="NullOrEmptyPath" xml:space="preserve">
<value>Null or empty path.</value>
</data>
<data name="NumberOfPointsAndTypesMustBeSame" xml:space="preserve">
<value>Invalid parameter passed. Number of points and types must be same.</value>
</data>
<data name="ObjectDisposed" xml:space="preserve">
<value>Object has been disposed.</value>
</data>
<data name="ValueLessThenZero" xml:space="preserve">
<value>The value of the {0} property is less than zero.</value>
</data>
<data name="ValueNotOneOfValues" xml:space="preserve">
<value>The value of the {0} property is not one of the {1} values</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public GraphicsPath(Point[] pts, byte[] types, FillMode fillMode)
if (pts == null)
throw new ArgumentNullException(nameof(pts));
if (pts.Length != types.Length)
throw new ArgumentException("Invalid parameter passed. Number of points and types must be same.");
throw new ArgumentException(SR.NumberOfPointsAndTypesMustBeSame);

int status = Gdip.GdipCreatePath2I(pts, types, pts.Length, fillMode, out _nativePath);
Gdip.CheckStatus(status);
Expand All @@ -89,7 +89,7 @@ public GraphicsPath(PointF[] pts, byte[] types, FillMode fillMode)
if (pts == null)
throw new ArgumentNullException(nameof(pts));
if (pts.Length != types.Length)
throw new ArgumentException("Invalid parameter passed. Number of points and types must be same.");
throw new ArgumentException(SR.NumberOfPointsAndTypesMustBeSame);

int status = Gdip.GdipCreatePath2(pts, types, pts.Length, fillMode, out _nativePath);
Gdip.CheckStatus(status);
Expand Down Expand Up @@ -141,7 +141,7 @@ public FillMode FillMode
set
{
if ((value < FillMode.Alternate) || (value > FillMode.Winding))
throw new InvalidEnumArgumentException("FillMode", (int)value, typeof(FillMode));
throw new InvalidEnumArgumentException(nameof(FillMode), (int)value, typeof(FillMode));

int status = Gdip.GdipSetPathFillMode(_nativePath, value);
Gdip.CheckStatus(status);
Expand Down
6 changes: 3 additions & 3 deletions src/System.Drawing.Common/src/System/Drawing/Font.Unix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ internal void unitConversion(GraphicsUnit fromUnit, GraphicsUnit toUnit, float n
inchs = nSrc / 72f;
break;
default:
throw new ArgumentException("Invalid GraphicsUnit");
throw new ArgumentException(SR.InvalidGraphicsUnit);
}

switch (toUnit)
Expand All @@ -121,7 +121,7 @@ internal void unitConversion(GraphicsUnit fromUnit, GraphicsUnit toUnit, float n
nTrg = inchs * 72;
break;
default:
throw new ArgumentException("Invalid GraphicsUnit");
throw new ArgumentException(SR.InvalidGraphicsUnit);
}
}

Expand Down Expand Up @@ -211,7 +211,7 @@ public static Font FromHfont(IntPtr hfont)
public IntPtr ToHfont()
{
if (_nativeFont == IntPtr.Zero)
throw new ArgumentException("Object has been disposed.");
throw new ArgumentException(SR.ObjectDisposed);

return _nativeFont;
}
Expand Down
6 changes: 3 additions & 3 deletions src/System.Drawing.Common/src/System/Drawing/Graphics.Unix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ private void CopyFromScreenX11(int sourceX, int sourceY, int destinationX, int d
int AllPlanes = ~0, nitems = 0, pixel;

if (copyPixelOperation != CopyPixelOperation.SourceCopy)
throw new NotImplementedException("Operation not implemented under X11");
throw new NotImplementedException(SR.NotImplementedUnderX11);

if (Gdip.Display == IntPtr.Zero)
{
Expand Down Expand Up @@ -458,7 +458,7 @@ public static Graphics FromHwnd(IntPtr hwnd)
{
Gdip.Display = LibX11Functions.XOpenDisplay(IntPtr.Zero);
if (Gdip.Display == IntPtr.Zero)
throw new NotSupportedException("Could not open display (X-Server required. Check your DISPLAY environment variable)");
throw new NotSupportedException(SR.CouldNotOpenDisplay);
}
if (hwnd == IntPtr.Zero)
{
Expand All @@ -483,7 +483,7 @@ public static Graphics FromImage(Image image)
throw new ArgumentNullException(nameof(image));

if ((image.PixelFormat & PixelFormat.Indexed) != 0)
throw new ArgumentException("Cannot create Graphics from an indexed bitmap.", nameof(image));
throw new ArgumentException(SR.CannotCreateGraphics, nameof(image));

int status = Gdip.GdipGetImageGraphicsContext(image.nativeImage, out graphics);
Gdip.CheckStatus(status);
Expand Down
8 changes: 4 additions & 4 deletions src/System.Drawing.Common/src/System/Drawing/Icon.Unix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public Icon(Icon original, Size size)
}

if (id == ushort.MaxValue)
throw new ArgumentException("Icon", "No valid icon image found");
throw new ArgumentException(SR.NoValidIconImageFound, "Icon");

iconSize.Height = iconDir.idEntries[id].height;
iconSize.Width = iconDir.idEntries[id].width;
Expand Down Expand Up @@ -313,9 +313,9 @@ public static Icon ExtractAssociatedIcon(string filePath)
if (filePath == null)
throw new ArgumentNullException(nameof(filePath));
if (string.IsNullOrEmpty(filePath))
throw new ArgumentException("Null or empty path.", "path");
throw new ArgumentException(SR.NullOrEmptyPath, "path");
if (!File.Exists(filePath))
throw new FileNotFoundException("Couldn't find specified file.", filePath);
throw new FileNotFoundException(SR.CouldntFindSpecifiedFile, filePath);

return SystemIcons.WinLogo;
}
Expand Down Expand Up @@ -635,7 +635,7 @@ internal Bitmap GetInternalBitmap()
public Bitmap ToBitmap()
{
if (disposed)
throw new ObjectDisposedException("Icon instance was disposed.");
throw new ObjectDisposedException(SR.IconInstanceWasDisposed);

// note: we can't return the original image because
// (a) we have no control over the bitmap instance we return (i.e. it could be disposed)
Expand Down
4 changes: 2 additions & 2 deletions src/System.Drawing.Common/src/System/Drawing/Image.Unix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public PropertyItem GetPropertyItem(int propid)
public Image GetThumbnailImage(int thumbWidth, int thumbHeight, Image.GetThumbnailImageAbort callback, IntPtr callbackData)
{
if ((thumbWidth <= 0) || (thumbHeight <= 0))
throw new OutOfMemoryException("Invalid thumbnail size");
throw new OutOfMemoryException(SR.InvalidThumbnailSize);

Image ThumbNail = new Bitmap(thumbWidth, thumbHeight);

Expand Down Expand Up @@ -224,7 +224,7 @@ public void Save(Stream stream, ImageFormat format)
ImageCodecInfo encoder = FindEncoderForFormat(format);

if (encoder == null)
throw new ArgumentException("No codec available for format:" + format.Guid);
throw new ArgumentException(SR.Format(SR.NoCodecAvailableForFormat, format.Guid));

Save(stream, encoder, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public MetaHeader WmfHeader
{
if (IsWmf())
return new MetaHeader(header.wmf_header);
throw new ArgumentException("WmfHeader only available on WMF files.");
throw new ArgumentException(SR.Format(SR.AvailableOnlyOnWMF, nameof(WmfHeader)));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public short Copies
set
{
if (value < 0)
throw new ArgumentException("The value of the Copies property is less than zero.");
throw new ArgumentException(SR.Format(SR.ValueLessThenZero, nameof(Copies)));

copies = value;
}
Expand Down Expand Up @@ -139,7 +139,7 @@ public int FromPage
set
{
if (value < 0)
throw new ArgumentException("The value of the FromPage property is less than zero");
throw new ArgumentException(SR.Format(SR.ValueLessThenZero, nameof(FromPage)));

from_page = value;
}
Expand Down Expand Up @@ -182,7 +182,7 @@ public int MaximumPage
{
// This not documented but behaves like MinimumPage
if (value < 0)
throw new ArgumentException("The value of the MaximumPage property is less than zero");
throw new ArgumentException(SR.Format(SR.ValueLessThenZero, nameof(MaximumPage)));

maximum_page = value;
}
Expand All @@ -194,7 +194,7 @@ public int MinimumPage
set
{
if (value < 0)
throw new ArgumentException("The value of the MaximumPage property is less than zero");
throw new ArgumentException(SR.Format(SR.ValueLessThenZero, nameof(MinimumPage)));

minimum_page = value;
}
Expand Down Expand Up @@ -264,7 +264,7 @@ public PrintRange PrintRange
{
if (value != PrintRange.AllPages && value != PrintRange.Selection &&
value != PrintRange.SomePages)
throw new InvalidEnumArgumentException("The value of the PrintRange property is not one of the PrintRange values");
throw new InvalidEnumArgumentException(SR.Format(SR.ValueNotOneOfValues, nameof(PrintRange), nameof(PrintRange)));

print_range = value;
}
Expand All @@ -287,7 +287,7 @@ public int ToPage
set
{
if (value < 0)
throw new ArgumentException("The value of the ToPage property is less than zero");
throw new ArgumentException(SR.Format(SR.ValueLessThenZero, nameof(ToPage)));

to_page = value;
}
Expand Down
3 changes: 1 addition & 2 deletions src/System.IO.FileSystem/src/System/IO/DirectoryInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ internal DirectoryInfo(string originalPath, string fullPath = null, string fileN

private void Init(string originalPath, string fullPath = null, string fileName = null, bool isNormalized = false)
{
// Want to throw the original argument name
OriginalPath = originalPath ?? throw new ArgumentNullException("path");
OriginalPath = originalPath ?? throw new ArgumentNullException(nameof(originalPath));

fullPath = fullPath ?? originalPath;
fullPath = isNormalized ? fullPath : Path.GetFullPath(fullPath);
Expand Down
5 changes: 4 additions & 1 deletion src/System.IO.Packaging/src/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -372,4 +372,7 @@
<data name="UriShouldBeAbsolute" xml:space="preserve">
<value>Must have absolute URI.</value>
</data>
</root>
<data name="FileContainsCorruptedData" xml:space="preserve">
<value>File contains corrupted data.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ internal ZipPackage(Stream s, FileMode packageFileMode, FileAccess packageFileAc
}
catch (InvalidDataException)
{
throw new FileFormatException("File contains corrupted data.");
throw new FileFormatException(SR.FileContainsCorruptedData);
}
catch
{
Expand Down
Loading

0 comments on commit 1518fdc

Please sign in to comment.