summaryrefslogtreecommitdiff
path: root/src/mscorlib/src/System/Resources
diff options
context:
space:
mode:
Diffstat (limited to 'src/mscorlib/src/System/Resources')
-rw-r--r--src/mscorlib/src/System/Resources/FileBasedResourceGroveler.cs31
-rw-r--r--src/mscorlib/src/System/Resources/IResourceGroveler.cs5
-rw-r--r--src/mscorlib/src/System/Resources/LooselyLinkedResourceReference.cs10
-rw-r--r--src/mscorlib/src/System/Resources/ManifestBasedResourceGroveler.cs153
-rw-r--r--src/mscorlib/src/System/Resources/NeutralResourcesLanguageAttribute.cs4
-rw-r--r--src/mscorlib/src/System/Resources/ResourceFallbackManager.cs14
-rw-r--r--src/mscorlib/src/System/Resources/ResourceManager.cs306
-rw-r--r--src/mscorlib/src/System/Resources/ResourceReader.cs71
-rw-r--r--src/mscorlib/src/System/Resources/ResourceSet.cs21
-rw-r--r--src/mscorlib/src/System/Resources/RuntimeResourceSet.cs9
-rw-r--r--src/mscorlib/src/System/Resources/SatelliteContractVersionAttribute.cs2
-rw-r--r--src/mscorlib/src/System/Resources/__FastResourceComparer.cs14
12 files changed, 99 insertions, 541 deletions
diff --git a/src/mscorlib/src/System/Resources/FileBasedResourceGroveler.cs b/src/mscorlib/src/System/Resources/FileBasedResourceGroveler.cs
index efd949f565..76bf0008f9 100644
--- a/src/mscorlib/src/System/Resources/FileBasedResourceGroveler.cs
+++ b/src/mscorlib/src/System/Resources/FileBasedResourceGroveler.cs
@@ -23,6 +23,7 @@ namespace System.Resources {
using System.Runtime.Versioning;
using System.Text;
using System.Threading;
+ using System.Diagnostics;
using System.Diagnostics.Contracts;
internal class FileBasedResourceGroveler : IResourceGroveler
@@ -31,17 +32,16 @@ namespace System.Resources {
public FileBasedResourceGroveler(ResourceManager.ResourceManagerMediator mediator)
{
- Contract.Assert(mediator != null, "mediator shouldn't be null; check caller");
+ Debug.Assert(mediator != null, "mediator shouldn't be null; check caller");
_mediator = mediator;
}
// Consider modifying IResourceGroveler interface (hence this method signature) when we figure out
// serialization compat story for moving ResourceManager members to either file-based or
// manifest-based classes. Want to continue tightening the design to get rid of unused params.
- [System.Security.SecuritySafeCritical] // auto-generated
public ResourceSet GrovelForResourceSet(CultureInfo culture, Dictionary<String, ResourceSet> localResourceSets, bool tryParents, bool createIfNotExists, ref StackCrawlMark stackMark)
{
- Contract.Assert(culture != null, "culture shouldn't be null; check caller");
+ Debug.Assert(culture != null, "culture shouldn't be null; check caller");
String fileName = null;
ResourceSet rs = null;
@@ -79,24 +79,6 @@ namespace System.Resources {
}
}
-#if !FEATURE_CORECLR // PAL doesn't support eventing, and we don't compile event providers for coreclr
- public bool HasNeutralResources(CultureInfo culture, String defaultResName)
- {
- // Detect missing neutral locale resources.
- String defaultResPath = FindResourceFile(culture, defaultResName);
- if (defaultResPath == null || !File.Exists(defaultResPath))
- {
- String dir = _mediator.ModuleDir;
- if (defaultResPath != null)
- {
- dir = Path.GetDirectoryName(defaultResPath);
- }
- return false;
- }
- return true;
- }
-#endif
-
// Given a CultureInfo, it generates the path &; file name for
// the .resources file for that CultureInfo. This method will grovel
// the disk looking for the correct file name & path. Uses CultureInfo's
@@ -107,8 +89,8 @@ namespace System.Resources {
private String FindResourceFile(CultureInfo culture, String fileName)
{
- Contract.Assert(culture != null, "culture shouldn't be null; check caller");
- Contract.Assert(fileName != null, "fileName shouldn't be null; check caller");
+ Debug.Assert(culture != null, "culture shouldn't be null; check caller");
+ Debug.Assert(fileName != null, "fileName shouldn't be null; check caller");
// If we have a moduleDir, check there first. Get module fully
// qualified name, append path to that.
@@ -145,10 +127,9 @@ namespace System.Resources {
// Constructs a new ResourceSet for a given file name. The logic in
// here avoids a ReflectionPermission check for our RuntimeResourceSet
// for perf and working set reasons.
- [System.Security.SecurityCritical]
private ResourceSet CreateResourceSet(String file)
{
- Contract.Assert(file != null, "file shouldn't be null; check caller");
+ Debug.Assert(file != null, "file shouldn't be null; check caller");
if (_mediator.UserResourceSet == null)
{
diff --git a/src/mscorlib/src/System/Resources/IResourceGroveler.cs b/src/mscorlib/src/System/Resources/IResourceGroveler.cs
index 983fd1204c..77c5c95890 100644
--- a/src/mscorlib/src/System/Resources/IResourceGroveler.cs
+++ b/src/mscorlib/src/System/Resources/IResourceGroveler.cs
@@ -23,10 +23,5 @@ namespace System.Resources {
{
ResourceSet GrovelForResourceSet(CultureInfo culture, Dictionary<String, ResourceSet> localResourceSets, bool tryParents,
bool createIfNotExists, ref StackCrawlMark stackMark);
-
-#if !FEATURE_CORECLR // PAL doesn't support eventing, and we don't compile event providers for coreclr
-
- bool HasNeutralResources(CultureInfo culture, String defaultResName);
-#endif
}
}
diff --git a/src/mscorlib/src/System/Resources/LooselyLinkedResourceReference.cs b/src/mscorlib/src/System/Resources/LooselyLinkedResourceReference.cs
index 8235d608be..15a076bc5c 100644
--- a/src/mscorlib/src/System/Resources/LooselyLinkedResourceReference.cs
+++ b/src/mscorlib/src/System/Resources/LooselyLinkedResourceReference.cs
@@ -36,13 +36,13 @@ namespace System.Resources {
public LooselyLinkedResourceReference(String looselyLinkedResourceName, String typeName)
{
if (looselyLinkedResourceName == null)
- throw new ArgumentNullException("looselyLinkedResourceName");
+ throw new ArgumentNullException(nameof(looselyLinkedResourceName));
if (typeName == null)
- throw new ArgumentNullException("typeName");
+ throw new ArgumentNullException(nameof(typeName));
if (looselyLinkedResourceName.Length == 0)
- throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "looselyLinkedResourceName");
+ throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), nameof(looselyLinkedResourceName));
if (typeName.Length == 0)
- throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), "typeName");
+ throw new ArgumentException(Environment.GetResourceString("Argument_EmptyName"), nameof(typeName));
Contract.EndContractBlock();
_manifestResourceName = looselyLinkedResourceName;
@@ -60,7 +60,7 @@ namespace System.Resources {
public Object Resolve(Assembly assembly)
{
if (assembly == null)
- throw new ArgumentNullException("assembly");
+ throw new ArgumentNullException(nameof(assembly));
Contract.EndContractBlock();
Stream data = assembly.GetManifestResourceStream(_manifestResourceName);
diff --git a/src/mscorlib/src/System/Resources/ManifestBasedResourceGroveler.cs b/src/mscorlib/src/System/Resources/ManifestBasedResourceGroveler.cs
index 5fd0daad09..78e961a7f9 100644
--- a/src/mscorlib/src/System/Resources/ManifestBasedResourceGroveler.cs
+++ b/src/mscorlib/src/System/Resources/ManifestBasedResourceGroveler.cs
@@ -26,13 +26,10 @@ namespace System.Resources {
using System.Runtime.Versioning;
using System.Text;
using System.Threading;
+ using System.Diagnostics;
using System.Diagnostics.Contracts;
using Microsoft.Win32;
-#if !FEATURE_CORECLR
- using System.Diagnostics.Tracing;
-#endif
-
//
// Note: this type is integral to the construction of exception objects,
// and sometimes this has to be done in low memory situtations (OOM) or
@@ -55,12 +52,11 @@ namespace System.Resources {
_mediator = mediator;
}
- [System.Security.SecuritySafeCritical]
[MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable
public ResourceSet GrovelForResourceSet(CultureInfo culture, Dictionary<String, ResourceSet> localResourceSets, bool tryParents, bool createIfNotExists, ref StackCrawlMark stackMark)
{
- Contract.Assert(culture != null, "culture shouldn't be null; check caller");
- Contract.Assert(localResourceSets != null, "localResourceSets shouldn't be null; check caller");
+ Debug.Assert(culture != null, "culture shouldn't be null; check caller");
+ Debug.Assert(localResourceSets != null, "localResourceSets shouldn't be null; check caller");
ResourceSet rs = null;
Stream stream = null;
@@ -110,43 +106,15 @@ namespace System.Resources {
// want to add it twice.
lock (localResourceSets)
{
- if (localResourceSets.TryGetValue(culture.Name, out rs))
- {
-#if !FEATURE_CORECLR
- if (FrameworkEventSource.IsInitialized)
- {
- FrameworkEventSource.Log.ResourceManagerFoundResourceSetInCacheUnexpected(_mediator.BaseName, _mediator.MainAssembly, culture.Name);
- }
-#endif
- }
+ localResourceSets.TryGetValue(culture.Name, out rs);
}
stream = GetManifestResourceStream(satellite, fileName, ref stackMark);
}
-#if !FEATURE_CORECLR
- if (FrameworkEventSource.IsInitialized)
- {
- if (stream != null)
- {
- FrameworkEventSource.Log.ResourceManagerStreamFound(_mediator.BaseName, _mediator.MainAssembly, culture.Name, satellite, fileName);
- }
- else
- {
- FrameworkEventSource.Log.ResourceManagerStreamNotFound(_mediator.BaseName, _mediator.MainAssembly, culture.Name, satellite, fileName);
- }
- }
-#endif
-
// 4a. Found a stream; create a ResourceSet if possible
if (createIfNotExists && stream != null && rs == null)
{
-#if !FEATURE_CORECLR
- if (FrameworkEventSource.IsInitialized)
- {
- FrameworkEventSource.Log.ResourceManagerCreatingResourceSet(_mediator.BaseName, _mediator.MainAssembly, culture.Name, fileName);
- }
-#endif
rs = CreateResourceSet(stream, satellite);
}
else if (stream == null && tryParents)
@@ -159,36 +127,9 @@ namespace System.Resources {
}
}
-#if !FEATURE_CORECLR
- if (!createIfNotExists && stream != null && rs == null)
- {
- if (FrameworkEventSource.IsInitialized)
- {
- FrameworkEventSource.Log.ResourceManagerNotCreatingResourceSet(_mediator.BaseName, _mediator.MainAssembly, culture.Name);
- }
- }
-#endif
-
return rs;
}
-#if !FEATURE_CORECLR
- // Returns whether or not the main assembly contains a particular resource
- // file in it's assembly manifest. Used to verify that the neutral
- // Culture's .resources file is present in the main assembly
- public bool HasNeutralResources(CultureInfo culture, String defaultResName)
- {
- String resName = defaultResName;
- if (_mediator.LocationInfo != null && _mediator.LocationInfo.Namespace != null)
- resName = _mediator.LocationInfo.Namespace + Type.Delimiter + defaultResName;
- String[] resourceFiles = _mediator.MainAssembly.GetManifestResourceNames();
- foreach(String s in resourceFiles)
- if (s.Equals(resName))
- return true;
- return false;
- }
-#endif
-
private CultureInfo UltimateFallbackFixup(CultureInfo lookForCulture)
{
@@ -199,13 +140,6 @@ namespace System.Resources {
if (lookForCulture.Name == _mediator.NeutralResourcesCulture.Name &&
_mediator.FallbackLoc == UltimateResourceFallbackLocation.MainAssembly)
{
-#if !FEATURE_CORECLR
- if (FrameworkEventSource.IsInitialized)
- {
- FrameworkEventSource.Log.ResourceManagerNeutralResourcesSufficient(_mediator.BaseName, _mediator.MainAssembly, lookForCulture.Name);
- }
-#endif
-
returnCulture = CultureInfo.InvariantCulture;
}
else if (lookForCulture.HasInvariantCultureName && _mediator.FallbackLoc == UltimateResourceFallbackLocation.Satellite)
@@ -214,13 +148,11 @@ namespace System.Resources {
}
return returnCulture;
-
}
- [System.Security.SecurityCritical]
internal static CultureInfo GetNeutralResourcesLanguage(Assembly a, ref UltimateResourceFallbackLocation fallbackLocation)
{
- Contract.Assert(a != null, "assembly != null");
+ Debug.Assert(a != null, "assembly != null");
string cultureName = null;
short fallback = 0;
if (GetNeutralResourcesLanguageAttribute(((RuntimeAssembly)a).GetNativeHandle(),
@@ -232,11 +164,6 @@ namespace System.Resources {
fallbackLocation = (UltimateResourceFallbackLocation)fallback;
}
else {
-#if !FEATURE_CORECLR
- if (FrameworkEventSource.IsInitialized) {
- FrameworkEventSource.Log.ResourceManagerNeutralResourceAttributeMissing(a);
- }
-#endif
fallbackLocation = UltimateResourceFallbackLocation.MainAssembly;
return CultureInfo.InvariantCulture;
}
@@ -253,7 +180,7 @@ namespace System.Resources {
// fires, please fix the build process for the BCL directory.
if (a == typeof(Object).Assembly)
{
- Contract.Assert(false, System.CoreLib.Name+"'s NeutralResourcesLanguageAttribute is a malformed culture name! name: \"" + cultureName + "\" Exception: " + e);
+ Debug.Assert(false, System.CoreLib.Name+"'s NeutralResourcesLanguageAttribute is a malformed culture name! name: \"" + cultureName + "\" Exception: " + e);
return CultureInfo.InvariantCulture;
}
@@ -267,10 +194,9 @@ namespace System.Resources {
// Use the assembly to resolve assembly manifest resource references.
// Note that is can be null, but probably shouldn't be.
// This method could use some refactoring. One thing at a time.
- [System.Security.SecurityCritical]
internal ResourceSet CreateResourceSet(Stream store, Assembly assembly)
{
- Contract.Assert(store != null, "I need a Stream!");
+ Debug.Assert(store != null, "I need a Stream!");
// Check to see if this is a Stream the ResourceManager understands,
// and check for the correct resource reader type.
if (store.CanSeek && store.Length > 4)
@@ -350,7 +276,7 @@ namespace System.Resources {
Type resSetType;
if (_mediator.UserResourceSet == null)
{
- Contract.Assert(resSetTypeName != null, "We should have a ResourceSet type name from the custom resource file here.");
+ Debug.Assert(resSetTypeName != null, "We should have a ResourceSet type name from the custom resource file here.");
resSetType = Type.GetType(resSetTypeName, true, false);
}
else
@@ -413,7 +339,6 @@ namespace System.Resources {
}
}
- [System.Security.SecurityCritical]
private Stream GetManifestResourceStream(RuntimeAssembly satellite, String fileName, ref StackCrawlMark stackMark)
{
Contract.Requires(satellite != null, "satellite shouldn't be null; check caller");
@@ -437,7 +362,6 @@ namespace System.Resources {
// case-insensitive lookup rules. Yes, this is slow. The metadata
// dev lead refuses to make all assembly manifest resource lookups case-insensitive,
// even optionally case-insensitive.
- [System.Security.SecurityCritical]
[MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable
private Stream CaseInsensitiveManifestResourceStreamLookup(RuntimeAssembly satellite, String name)
{
@@ -475,48 +399,19 @@ namespace System.Resources {
}
}
-#if !FEATURE_CORECLR
- if (FrameworkEventSource.IsInitialized)
- {
- if (canonicalName != null)
- {
- FrameworkEventSource.Log.ResourceManagerCaseInsensitiveResourceStreamLookupSucceeded(_mediator.BaseName, _mediator.MainAssembly, satellite.GetSimpleName(), givenName);
- }
- else
- {
- FrameworkEventSource.Log.ResourceManagerCaseInsensitiveResourceStreamLookupFailed(_mediator.BaseName, _mediator.MainAssembly, satellite.GetSimpleName(), givenName);
- }
- }
-#endif
-
if (canonicalName == null)
{
return null;
}
+
// If we're looking in the main assembly AND if the main
// assembly was the person who created the ResourceManager,
// skip a security check for private manifest resources.
bool canSkipSecurityCheck = _mediator.MainAssembly == satellite && _mediator.CallingAssembly == _mediator.MainAssembly;
StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
- Stream s = satellite.GetManifestResourceStream(canonicalName, ref stackMark, canSkipSecurityCheck);
- // GetManifestResourceStream will return null if we don't have
- // permission to read this stream from the assembly. For example,
- // if the stream is private and we're trying to access it from another
- // assembly (ie, ResMgr in mscorlib accessing anything else), we
- // require Reflection TypeInformation permission to be able to read
- // this.
-#if !FEATURE_CORECLR
- if (s!=null) {
- if (FrameworkEventSource.IsInitialized)
- {
- FrameworkEventSource.Log.ResourceManagerManifestResourceAccessDenied(_mediator.BaseName, _mediator.MainAssembly, satellite.GetSimpleName(), canonicalName);
- }
- }
-#endif
- return s;
+ return satellite.GetManifestResourceStream(canonicalName, ref stackMark, canSkipSecurityCheck);
}
- [System.Security.SecurityCritical]
[MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable
private RuntimeAssembly GetSatelliteAssembly(CultureInfo lookForCulture, ref StackCrawlMark stackMark)
{
@@ -548,30 +443,16 @@ namespace System.Resources {
int hr = fle._HResult;
if (hr != Win32Native.MakeHRFromErrorCode(Win32Native.ERROR_ACCESS_DENIED))
{
- Contract.Assert(false, "[This assert catches satellite assembly build/deployment problems - report this message to your build lab & loc engineer]" + Environment.NewLine + "GetSatelliteAssembly failed for culture " + lookForCulture.Name + " and version " + (_mediator.SatelliteContractVersion == null ? _mediator.MainAssembly.GetVersion().ToString() : _mediator.SatelliteContractVersion.ToString()) + " of assembly " + _mediator.MainAssembly.GetSimpleName() + " with error code 0x" + hr.ToString("X", CultureInfo.InvariantCulture) + Environment.NewLine + "Exception: " + fle);
+ Debug.Assert(false, "[This assert catches satellite assembly build/deployment problems - report this message to your build lab & loc engineer]" + Environment.NewLine + "GetSatelliteAssembly failed for culture " + lookForCulture.Name + " and version " + (_mediator.SatelliteContractVersion == null ? _mediator.MainAssembly.GetVersion().ToString() : _mediator.SatelliteContractVersion.ToString()) + " of assembly " + _mediator.MainAssembly.GetSimpleName() + " with error code 0x" + hr.ToString("X", CultureInfo.InvariantCulture) + Environment.NewLine + "Exception: " + fle);
}
}
// Don't throw for zero-length satellite assemblies, for compat with v1
catch (BadImageFormatException bife)
{
- Contract.Assert(false, "[This assert catches satellite assembly build/deployment problems - report this message to your build lab & loc engineer]" + Environment.NewLine + "GetSatelliteAssembly failed for culture " + lookForCulture.Name + " and version " + (_mediator.SatelliteContractVersion == null ? _mediator.MainAssembly.GetVersion().ToString() : _mediator.SatelliteContractVersion.ToString()) + " of assembly " + _mediator.MainAssembly.GetSimpleName() + Environment.NewLine + "Exception: " + bife);
+ Debug.Assert(false, "[This assert catches satellite assembly build/deployment problems - report this message to your build lab & loc engineer]" + Environment.NewLine + "GetSatelliteAssembly failed for culture " + lookForCulture.Name + " and version " + (_mediator.SatelliteContractVersion == null ? _mediator.MainAssembly.GetVersion().ToString() : _mediator.SatelliteContractVersion.ToString()) + " of assembly " + _mediator.MainAssembly.GetSimpleName() + Environment.NewLine + "Exception: " + bife);
}
-#if !FEATURE_CORECLR
- if (FrameworkEventSource.IsInitialized)
- {
- if (satellite != null)
- {
- FrameworkEventSource.Log.ResourceManagerGetSatelliteAssemblySucceeded(_mediator.BaseName, _mediator.MainAssembly, lookForCulture.Name, satAssemblyName);
- }
- else
- {
- FrameworkEventSource.Log.ResourceManagerGetSatelliteAssemblyFailed(_mediator.BaseName, _mediator.MainAssembly, lookForCulture.Name, satAssemblyName);
- }
- }
-#endif
-
return satellite;
}
@@ -583,8 +464,8 @@ namespace System.Resources {
// and causes partially trusted localized apps to fail.
private bool CanUseDefaultResourceClasses(String readerTypeName, String resSetTypeName)
{
- Contract.Assert(readerTypeName != null, "readerTypeName shouldn't be null; check caller");
- Contract.Assert(resSetTypeName != null, "resSetTypeName shouldn't be null; check caller");
+ Debug.Assert(readerTypeName != null, "readerTypeName shouldn't be null; check caller");
+ Debug.Assert(resSetTypeName != null, "resSetTypeName shouldn't be null; check caller");
if (_mediator.UserResourceSet != null)
return false;
@@ -609,7 +490,6 @@ namespace System.Resources {
return true;
}
- [System.Security.SecurityCritical]
private String GetSatelliteAssemblyName()
{
String satAssemblyName = _mediator.MainAssembly.GetSimpleName();
@@ -617,7 +497,6 @@ namespace System.Resources {
return satAssemblyName;
}
- [System.Security.SecurityCritical]
private void HandleSatelliteMissing()
{
String satAssemName = _mediator.MainAssembly.GetSimpleName() + ".resources.dll";
@@ -646,14 +525,13 @@ namespace System.Resources {
throw new MissingSatelliteAssemblyException(Environment.GetResourceString("MissingSatelliteAssembly_Culture_Name", _mediator.NeutralResourcesCulture, satAssemName), missingCultureName);
}
- [System.Security.SecurityCritical] // auto-generated
private void HandleResourceStreamMissing(String fileName)
{
// Keep people from bothering me about resources problems
if (_mediator.MainAssembly == typeof(Object).Assembly && _mediator.BaseName.Equals(System.CoreLib.Name))
{
// This would break CultureInfo & all our exceptions.
- Contract.Assert(false, "Couldn't get " + System.CoreLib.Name+ResourceManager.ResFileExtension + " from "+System.CoreLib.Name+"'s assembly" + Environment.NewLine + Environment.NewLine + "Are you building the runtime on your machine? Chances are the BCL directory didn't build correctly. Type 'build -c' in the BCL directory. If you get build errors, look at buildd.log. If you then can't figure out what's wrong (and you aren't changing the assembly-related metadata code), ask a BCL dev.\n\nIf you did NOT build the runtime, you shouldn't be seeing this and you've found a bug.");
+ Debug.Assert(false, "Couldn't get " + System.CoreLib.Name+ResourceManager.ResFileExtension + " from "+System.CoreLib.Name+"'s assembly" + Environment.NewLine + Environment.NewLine + "Are you building the runtime on your machine? Chances are the BCL directory didn't build correctly. Type 'build -c' in the BCL directory. If you get build errors, look at buildd.log. If you then can't figure out what's wrong (and you aren't changing the assembly-related metadata code), ask a BCL dev.\n\nIf you did NOT build the runtime, you shouldn't be seeing this and you've found a bug.");
// We cannot continue further - simply FailFast.
string mesgFailFast = System.CoreLib.Name + ResourceManager.ResFileExtension + " couldn't be found! Large parts of the BCL won't work!";
@@ -669,7 +547,6 @@ namespace System.Resources {
}
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
- [System.Security.SecurityCritical] // Our security team doesn't yet allow safe-critical P/Invoke methods.
[System.Security.SuppressUnmanagedCodeSecurity]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool GetNeutralResourcesLanguageAttribute(RuntimeAssembly assemblyHandle, StringHandleOnStack cultureName, out short fallbackLocation);
diff --git a/src/mscorlib/src/System/Resources/NeutralResourcesLanguageAttribute.cs b/src/mscorlib/src/System/Resources/NeutralResourcesLanguageAttribute.cs
index 560cd5faa9..6517a56b6a 100644
--- a/src/mscorlib/src/System/Resources/NeutralResourcesLanguageAttribute.cs
+++ b/src/mscorlib/src/System/Resources/NeutralResourcesLanguageAttribute.cs
@@ -35,7 +35,7 @@ namespace System.Resources {
public NeutralResourcesLanguageAttribute(String cultureName)
{
if (cultureName == null)
- throw new ArgumentNullException("cultureName");
+ throw new ArgumentNullException(nameof(cultureName));
Contract.EndContractBlock();
_culture = cultureName;
@@ -45,7 +45,7 @@ namespace System.Resources {
public NeutralResourcesLanguageAttribute(String cultureName, UltimateResourceFallbackLocation location)
{
if (cultureName == null)
- throw new ArgumentNullException("cultureName");
+ throw new ArgumentNullException(nameof(cultureName));
if (!Enum.IsDefined(typeof(UltimateResourceFallbackLocation), location))
throw new ArgumentException(Environment.GetResourceString("Arg_InvalidNeutralResourcesLanguage_FallbackLoc", location));
Contract.EndContractBlock();
diff --git a/src/mscorlib/src/System/Resources/ResourceFallbackManager.cs b/src/mscorlib/src/System/Resources/ResourceFallbackManager.cs
index def7836e05..de50cccc33 100644
--- a/src/mscorlib/src/System/Resources/ResourceFallbackManager.cs
+++ b/src/mscorlib/src/System/Resources/ResourceFallbackManager.cs
@@ -17,9 +17,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
-#if FEATURE_CORECLR
-using System.Diagnostics.Contracts;
-#endif
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@@ -33,8 +30,6 @@ namespace System.Resources
private CultureInfo m_neutralResourcesCulture;
private bool m_useParents;
-// Added but disabled from desktop in .NET 4.0, stayed disabled in .NET 4.5
-#if FEATURE_CORECLR
// This is a cache of the thread, process, user, and OS-preferred fallback cultures.
// However, each thread may have a different value, and these may change during the
// lifetime of the process. So this cache must be verified each time we use it.
@@ -43,7 +38,6 @@ namespace System.Resources
// as well to avoid differences across threads.
[ThreadStatic]
private static CultureInfo[] cachedOsFallbackArray;
-#endif // FEATURE_CORECLR
internal ResourceFallbackManager(CultureInfo startingCulture, CultureInfo neutralResourcesCulture, bool useParents)
{
@@ -91,8 +85,6 @@ namespace System.Resources
yield break;
}
-// Added but disabled from desktop in .NET 4.0, stayed disabled in .NET 4.5
-#if FEATURE_CORECLR
// 2. user preferred cultures, omitting starting culture if tried already
// Compat note: For console apps, this API will return cultures like Arabic
// or Hebrew that are displayed right-to-left. These don't work with today's
@@ -118,7 +110,6 @@ namespace System.Resources
}
}
}
-#endif // FEATURE_CORECLR
// 3. invariant
// Don't return invariant twice though.
@@ -128,8 +119,6 @@ namespace System.Resources
yield return CultureInfo.InvariantCulture;
}
-// Added but disabled from desktop in .NET 4.0, stayed disabled in .NET 4.5
-#if FEATURE_CORECLR
private static CultureInfo[] LoadPreferredCultures()
{
// The list of preferred cultures includes thread, process, user, and OS
@@ -190,7 +179,6 @@ namespace System.Resources
// Note: May return null.
- [System.Security.SecuritySafeCritical] // auto-generated
private static String[] GetResourceFallbackArray()
{
// AppCompat note: We've added this feature for desktop V4 but we ripped it out
@@ -272,7 +260,5 @@ namespace System.Resources
return CultureInfo.nativeGetResourceFallbackArray();
#endif
}
-
-#endif // FEATURE_CORECLR
}
}
diff --git a/src/mscorlib/src/System/Resources/ResourceManager.cs b/src/mscorlib/src/System/Resources/ResourceManager.cs
index b088e7f492..15f6af7bcf 100644
--- a/src/mscorlib/src/System/Resources/ResourceManager.cs
+++ b/src/mscorlib/src/System/Resources/ResourceManager.cs
@@ -30,10 +30,8 @@ namespace System.Resources {
using Microsoft.Win32;
using System.Collections.Generic;
using System.Runtime.Versioning;
+ using System.Diagnostics;
using System.Diagnostics.Contracts;
-#if !FEATURE_CORECLR
- using System.Diagnostics.Tracing;
-#endif
#if FEATURE_APPX
//
@@ -45,21 +43,16 @@ namespace System.Resources {
// Also using interface or abstract class will not play nice with FriendAccessAllowed.
//
[FriendAccessAllowed]
- [SecurityCritical]
internal class WindowsRuntimeResourceManagerBase
{
- [SecurityCritical]
public virtual bool Initialize(string libpath, string reswFilename, out PRIExceptionInfo exceptionInfo){exceptionInfo = null; return false;}
- [SecurityCritical]
public virtual String GetString(String stringName, String startingCulture, String neutralResourcesCulture){return null;}
public virtual CultureInfo GlobalResourceContextBestFitCultureInfo {
- [SecurityCritical]
get { return null; }
}
- [SecurityCritical]
public virtual bool SetGlobalResourceContextDefaultCulture(CultureInfo ci) { return false; }
}
@@ -266,13 +259,6 @@ namespace System.Resources {
protected ResourceManager()
{
-#if !FEATURE_CORECLR
- // This constructor is not designed to be used under AppX and is not in the Win8 profile.
- // However designers may use them even if they are running under AppX since they are
- // not subject to the restrictions of the Win8 profile.
- Contract.Assert(!AppDomain.IsAppXModel() || AppDomain.IsAppXDesignMode());
-#endif
-
Init();
_lastUsedResourceCache = new CultureNameResourceSetPair();
@@ -292,18 +278,11 @@ namespace System.Resources {
//
private ResourceManager(String baseName, String resourceDir, Type usingResourceSet) {
if (null==baseName)
- throw new ArgumentNullException("baseName");
+ throw new ArgumentNullException(nameof(baseName));
if (null==resourceDir)
- throw new ArgumentNullException("resourceDir");
+ throw new ArgumentNullException(nameof(resourceDir));
Contract.EndContractBlock();
-#if !FEATURE_CORECLR
- // This constructor is not designed to be used under AppX and is not in the Win8 profile.
- // However designers may use them even if they are running under AppX since they are
- // not subject to the restrictions of the Win8 profile.
- Contract.Assert(!AppDomain.IsAppXModel() || AppDomain.IsAppXDesignMode());
-#endif
-
BaseNameField = baseName;
moduleDir = resourceDir;
@@ -317,30 +296,16 @@ namespace System.Resources {
ResourceManagerMediator mediator = new ResourceManagerMediator(this);
resourceGroveler = new FileBasedResourceGroveler(mediator);
-
-#if !FEATURE_CORECLR // PAL doesn't support eventing, and we don't compile event providers for coreclr
- if (FrameworkEventSource.IsInitialized && FrameworkEventSource.Log.IsEnabled()) {
- CultureInfo culture = CultureInfo.InvariantCulture;
- String defaultResName = GetResourceFileName(culture);
-
- if (resourceGroveler.HasNeutralResources(culture, defaultResName)) {
- FrameworkEventSource.Log.ResourceManagerNeutralResourcesFound(BaseNameField, MainAssembly, defaultResName);
- }
- else {
- FrameworkEventSource.Log.ResourceManagerNeutralResourcesNotFound(BaseNameField, MainAssembly, defaultResName);
- }
- }
-#endif
}
-
+
[MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable
public ResourceManager(String baseName, Assembly assembly)
{
if (null==baseName)
- throw new ArgumentNullException("baseName");
+ throw new ArgumentNullException(nameof(baseName));
if (null==assembly)
- throw new ArgumentNullException("assembly");
+ throw new ArgumentNullException(nameof(assembly));
Contract.EndContractBlock();
if (!(assembly is RuntimeAssembly))
@@ -368,18 +333,11 @@ namespace System.Resources {
public ResourceManager(String baseName, Assembly assembly, Type usingResourceSet)
{
if (null==baseName)
- throw new ArgumentNullException("baseName");
+ throw new ArgumentNullException(nameof(baseName));
if (null==assembly)
- throw new ArgumentNullException("assembly");
+ throw new ArgumentNullException(nameof(assembly));
Contract.EndContractBlock();
-#if !FEATURE_CORECLR
- // This constructor is not designed to be used under AppX and is not in the Win8 profile.
- // However designers may use them even if they are running under AppX since they are
- // not subject to the restrictions of the Win8 profile.
- Contract.Assert(!AppDomain.IsAppXModel() || AppDomain.IsAppXDesignMode());
-#endif
-
if (!(assembly is RuntimeAssembly))
throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeAssembly"));
@@ -387,7 +345,7 @@ namespace System.Resources {
BaseNameField = baseName;
if (usingResourceSet != null && (usingResourceSet != _minResourceSet) && !(usingResourceSet.IsSubclassOf(_minResourceSet)))
- throw new ArgumentException(Environment.GetResourceString("Arg_ResMgrNotResSet"), "usingResourceSet");
+ throw new ArgumentException(Environment.GetResourceString("Arg_ResMgrNotResSet"), nameof(usingResourceSet));
_userResourceSet = usingResourceSet;
CommonAssemblyInit();
@@ -404,7 +362,7 @@ namespace System.Resources {
public ResourceManager(Type resourceSource)
{
if (null==resourceSource)
- throw new ArgumentNullException("resourceSource");
+ throw new ArgumentNullException(nameof(resourceSource));
Contract.EndContractBlock();
if (!(resourceSource is RuntimeType))
@@ -434,7 +392,6 @@ namespace System.Resources {
this._lastUsedResourceCache = null;
}
- [System.Security.SecuritySafeCritical]
[OnDeserialized]
private void OnDeserialized(StreamingContext ctx)
{
@@ -479,7 +436,6 @@ namespace System.Resources {
// Trying to unify code as much as possible, even though having to do a
// security check in each constructor prevents it.
- [System.Security.SecuritySafeCritical]
private void CommonAssemblyInit()
{
if (_bUsingModernResourceManagement == false)
@@ -496,30 +452,6 @@ namespace System.Resources {
}
_neutralResourcesCulture = ManifestBasedResourceGroveler.GetNeutralResourcesLanguage(MainAssembly, ref _fallbackLoc);
-
-#if !FEATURE_CORECLR // PAL doesn't support eventing, and we don't compile event providers for coreclr
- if (_bUsingModernResourceManagement == false)
- {
- if (FrameworkEventSource.IsInitialized && FrameworkEventSource.Log.IsEnabled()) {
- CultureInfo culture = CultureInfo.InvariantCulture;
- String defaultResName = GetResourceFileName(culture);
-
- if (resourceGroveler.HasNeutralResources(culture, defaultResName)) {
- FrameworkEventSource.Log.ResourceManagerNeutralResourcesFound(BaseNameField, MainAssembly, defaultResName);
- }
- else {
- String outputResName = defaultResName;
- if (_locationInfo != null && _locationInfo.Namespace != null)
- outputResName = _locationInfo.Namespace + Type.Delimiter + defaultResName;
- FrameworkEventSource.Log.ResourceManagerNeutralResourcesNotFound(BaseNameField, MainAssembly, outputResName);
- }
- }
-
-#pragma warning disable 618
- ResourceSets = new Hashtable(); // for backward compatibility
-#pragma warning restore 618
- }
-#endif
}
// Gets the base name for the ResourceManager.
@@ -557,12 +489,6 @@ namespace System.Resources {
// creating a new ResourceManager isn't quite the correct behavior.
public virtual void ReleaseAllResources()
{
-#if !FEATURE_CORECLR
- if (FrameworkEventSource.IsInitialized)
- {
- FrameworkEventSource.Log.ResourceManagerReleasingResources(BaseNameField, MainAssembly);
- }
-#endif
Dictionary<String, ResourceSet> localResourceSets = _resourceSets;
// If any calls to Close throw, at least leave ourselves in a
@@ -573,27 +499,9 @@ namespace System.Resources {
lock(localResourceSets) {
IDictionaryEnumerator setEnum = localResourceSets.GetEnumerator();
-#if !FEATURE_CORECLR
- IDictionaryEnumerator setEnum2 = null;
-#pragma warning disable 618
- if (ResourceSets != null) {
- setEnum2 = ResourceSets.GetEnumerator();
- }
- ResourceSets = new Hashtable(); // for backwards compat
-#pragma warning restore 618
-#endif
-
while (setEnum.MoveNext()) {
((ResourceSet)setEnum.Value).Close();
}
-
-#if !FEATURE_CORECLR
- if (setEnum2 != null) {
- while (setEnum2.MoveNext()) {
- ((ResourceSet)setEnum2.Value).Close();
- }
- }
-#endif
}
}
@@ -677,11 +585,10 @@ namespace System.Resources {
// if it hasn't yet been loaded and if parent CultureInfos should be
// loaded as well for resource inheritance.
//
- [System.Security.SecuritySafeCritical] // auto-generated
[MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable
public virtual ResourceSet GetResourceSet(CultureInfo culture, bool createIfNotExists, bool tryParents) {
if (null==culture)
- throw new ArgumentNullException("culture");
+ throw new ArgumentNullException(nameof(culture));
Contract.EndContractBlock();
Dictionary<String,ResourceSet> localResourceSets = _resourceSets;
@@ -721,11 +628,10 @@ namespace System.Resources {
// for getting a resource set lives. Access to it is controlled by
// threadsafe methods such as GetResourceSet, GetString, & GetObject.
// This will take a minimal number of locks.
- [System.Security.SecuritySafeCritical] // auto-generated
[MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable
protected virtual ResourceSet InternalGetResourceSet(CultureInfo culture, bool createIfNotExists, bool tryParents)
{
- Contract.Assert(culture != null, "culture != null");
+ Debug.Assert(culture != null, "culture != null");
StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
return InternalGetResourceSet(culture,createIfNotExists,tryParents, ref stackMark);
@@ -735,7 +641,6 @@ namespace System.Resources {
// for getting a resource set lives. Access to it is controlled by
// threadsafe methods such as GetResourceSet, GetString, & GetObject.
// This will take a minimal number of locks.
- [System.Security.SecurityCritical]
private ResourceSet InternalGetResourceSet(CultureInfo requestedCulture, bool createIfNotExists, bool tryParents, ref StackCrawlMark stackMark)
{
Dictionary<String, ResourceSet> localResourceSets = _resourceSets;
@@ -743,11 +648,6 @@ namespace System.Resources {
CultureInfo foundCulture = null;
lock (localResourceSets) {
if (localResourceSets.TryGetValue(requestedCulture.Name, out rs)) {
-#if !FEATURE_CORECLR
- if (FrameworkEventSource.IsInitialized) {
- FrameworkEventSource.Log.ResourceManagerFoundResourceSetInCache(BaseNameField, MainAssembly, requestedCulture.Name);
- }
-#endif
return rs;
}
}
@@ -756,20 +656,8 @@ namespace System.Resources {
foreach (CultureInfo currentCultureInfo in mgr)
{
-#if !FEATURE_CORECLR
- if (FrameworkEventSource.IsInitialized)
- {
- FrameworkEventSource.Log.ResourceManagerLookingForResourceSet(BaseNameField, MainAssembly, currentCultureInfo.Name);
- }
-#endif
lock(localResourceSets) {
if (localResourceSets.TryGetValue(currentCultureInfo.Name, out rs)) {
-#if !FEATURE_CORECLR
- if (FrameworkEventSource.IsInitialized)
- {
- FrameworkEventSource.Log.ResourceManagerFoundResourceSetInCache(BaseNameField, MainAssembly, currentCultureInfo.Name);
- }
-#endif
// we need to update the cache if we fellback
if(requestedCulture != currentCultureInfo) foundCulture = currentCultureInfo;
break;
@@ -846,7 +734,7 @@ namespace System.Resources {
{
// Ensure that the assembly reference is not null
if (a == null) {
- throw new ArgumentNullException("a", Environment.GetResourceString("ArgumentNull_Assembly"));
+ throw new ArgumentNullException(nameof(a), Environment.GetResourceString("ArgumentNull_Assembly"));
}
Contract.EndContractBlock();
@@ -867,7 +755,7 @@ namespace System.Resources {
Object[] attrs = a.GetCustomAttributes(typeof(SatelliteContractVersionAttribute), false);
if (attrs.Length == 0)
return null;
- Contract.Assert(attrs.Length == 1, "Cannot have multiple instances of SatelliteContractVersionAttribute on an assembly!");
+ Debug.Assert(attrs.Length == 1, "Cannot have multiple instances of SatelliteContractVersionAttribute on an assembly!");
v = ((SatelliteContractVersionAttribute)attrs[0]).Version;
}
Version ver;
@@ -880,7 +768,7 @@ namespace System.Resources {
// If this assert fires, please fix the build process for the
// BCL directory.
if (a == typeof(Object).Assembly) {
- Contract.Assert(false, System.CoreLib.Name+"'s SatelliteContractVersionAttribute is a malformed version string!");
+ Debug.Assert(false, System.CoreLib.Name+"'s SatelliteContractVersionAttribute is a malformed version string!");
return null;
}
@@ -894,7 +782,6 @@ namespace System.Resources {
#endif
}
- [System.Security.SecuritySafeCritical] // auto-generated
protected static CultureInfo GetNeutralResourcesLanguage(Assembly a)
{
// This method should be obsolete - replace it with the one below.
@@ -909,7 +796,7 @@ namespace System.Resources {
String typeName2,
AssemblyName asmName2)
{
- Contract.Assert(asmTypeName1 != null, "asmTypeName1 was unexpectedly null");
+ Debug.Assert(asmTypeName1 != null, "asmTypeName1 was unexpectedly null");
// First, compare type names
int comma = asmTypeName1.IndexOf(',');
@@ -961,13 +848,11 @@ namespace System.Resources {
}
#if FEATURE_APPX
- [SecuritySafeCritical]
- // Throws WinRT hresults
private string GetStringFromPRI(String stringName, String startingCulture, String neutralResourcesCulture) {
- Contract.Assert(_bUsingModernResourceManagement);
- Contract.Assert(_WinRTResourceManager != null);
- Contract.Assert(_PRIonAppXInitialized);
- Contract.Assert(AppDomain.IsAppXModel());
+ Debug.Assert(_bUsingModernResourceManagement);
+ Debug.Assert(_WinRTResourceManager != null);
+ Debug.Assert(_PRIonAppXInitialized);
+ Debug.Assert(AppDomain.IsAppXModel());
if (stringName.Length == 0)
return null;
@@ -987,7 +872,6 @@ namespace System.Resources {
// Since we can't directly reference System.Runtime.WindowsRuntime from mscorlib, we have to get the type via reflection.
// It would be better if we could just implement WindowsRuntimeResourceManager in mscorlib, but we can't, because
// we can do very little with WinRT in mscorlib.
- [SecurityCritical]
internal static WindowsRuntimeResourceManagerBase GetWinRTResourceManager()
{
Type WinRTResourceManagerType = Type.GetType("System.Resources.WindowsRuntimeResourceManager, " + AssemblyRef.SystemRuntimeWindowsRuntime, true);
@@ -1000,7 +884,6 @@ namespace System.Resources {
#if FEATURE_APPX
[NonSerialized]
- [SecurityCritical]
private WindowsRuntimeResourceManagerBase _WinRTResourceManager; // Written only by SetAppXConfiguration
[NonSerialized]
@@ -1029,12 +912,10 @@ namespace System.Resources {
//
// b) For any other non-FX assembly, we will use the modern resource manager with the premise that app package
// contains the PRI resources.
- [SecuritySafeCritical]
private bool ShouldUseSatelliteAssemblyResourceLookupUnderAppX(RuntimeAssembly resourcesAssembly)
{
bool fUseSatelliteAssemblyResourceLookupUnderAppX = resourcesAssembly.IsFrameworkAssembly();
-
-#if FEATURE_CORECLR
+
if (!fUseSatelliteAssemblyResourceLookupUnderAppX)
{
// Check to see if the assembly is under PLATFORM_RESOURCE_ROOTS. If it is, then we should use satellite assembly lookup for it.
@@ -1055,23 +936,21 @@ namespace System.Resources {
}
}
}
-#endif // FEATURE_CORECLR
+
return fUseSatelliteAssemblyResourceLookupUnderAppX;
-
}
-
- [SecuritySafeCritical]
+
#endif // FEATURE_APPX
// Only call SetAppXConfiguration from ResourceManager constructors, and nowhere else.
// Throws MissingManifestResourceException and WinRT HResults
private void SetAppXConfiguration()
{
- Contract.Assert(_bUsingModernResourceManagement == false); // Only this function writes to this member
+ Debug.Assert(_bUsingModernResourceManagement == false); // Only this function writes to this member
#if FEATURE_APPX
- Contract.Assert(_WinRTResourceManager == null); // Only this function writes to this member
- Contract.Assert(_PRIonAppXInitialized == false); // Only this function writes to this member
- Contract.Assert(_PRIExceptionInfo == null); // Only this function writes to this member
+ Debug.Assert(_WinRTResourceManager == null); // Only this function writes to this member
+ Debug.Assert(_PRIonAppXInitialized == false); // Only this function writes to this member
+ Debug.Assert(_PRIExceptionInfo == null); // Only this function writes to this member
bool bUsingSatelliteAssembliesUnderAppX = false;
@@ -1225,7 +1104,7 @@ namespace System.Resources {
//
public virtual String GetString(String name, CultureInfo culture) {
if (null==name)
- throw new ArgumentNullException("name");
+ throw new ArgumentNullException(nameof(name));
Contract.EndContractBlock();
#if FEATURE_APPX
@@ -1267,13 +1146,7 @@ namespace System.Resources {
// This line behaves the same way as CultureInfo.CurrentUICulture would have in .NET 4
culture = Thread.CurrentThread.GetCurrentUICultureNoAppX();
}
-
-#if !FEATURE_CORECLR
- if (FrameworkEventSource.IsInitialized)
- {
- FrameworkEventSource.Log.ResourceManagerLookupStarted(BaseNameField, MainAssembly, culture.Name);
- }
-#endif
+
ResourceSet last = GetFirstResourceSet(culture);
if (last != null)
@@ -1311,13 +1184,6 @@ namespace System.Resources {
last = rs;
}
}
-
-#if !FEATURE_CORECLR
- if (FrameworkEventSource.IsInitialized)
- {
- FrameworkEventSource.Log.ResourceManagerLookupFailed(BaseNameField, MainAssembly, culture.Name);
- }
-#endif
}
return null;
@@ -1342,7 +1208,7 @@ namespace System.Resources {
private Object GetObject(String name, CultureInfo culture, bool wrapUnmanagedMemStream)
{
if (null==name)
- throw new ArgumentNullException("name");
+ throw new ArgumentNullException(nameof(name));
Contract.EndContractBlock();
#if FEATURE_APPX
@@ -1364,12 +1230,6 @@ namespace System.Resources {
culture = Thread.CurrentThread.GetCurrentUICultureNoAppX();
}
-#if !FEATURE_CORECLR
- if (FrameworkEventSource.IsInitialized)
- {
- FrameworkEventSource.Log.ResourceManagerLookupStarted(BaseNameField, MainAssembly, culture.Name);
- }
-#endif
ResourceSet last = GetFirstResourceSet(culture);
if (last != null)
{
@@ -1422,12 +1282,6 @@ namespace System.Resources {
}
}
-#if !FEATURE_CORECLR
- if (FrameworkEventSource.IsInitialized)
- {
- FrameworkEventSource.Log.ResourceManagerLookupFailed(BaseNameField, MainAssembly, culture.Name);
- }
-#endif
return null;
}
@@ -1448,7 +1302,6 @@ namespace System.Resources {
#if RESOURCE_SATELLITE_CONFIG
// Internal helper method - gives an end user the ability to prevent
// satellite assembly probes for certain cultures via a config file.
- [System.Security.SecurityCritical] // auto-generated
private bool TryLookingForSatellite(CultureInfo lookForCulture)
{
if (!_checkedConfigFile) {
@@ -1471,110 +1324,14 @@ namespace System.Resources {
// The config file told us what satellites might be installed.
int pos = Array.IndexOf(installedSatellites, lookForCulture.Name);
-#if !FEATURE_CORECLR
- if (FrameworkEventSource.IsInitialized && FrameworkEventSource.Log.IsEnabled()) {
- if (pos < 0) {
- FrameworkEventSource.Log.ResourceManagerCultureNotFoundInConfigFile(BaseNameField, MainAssembly, lookForCulture.Name);
- }
- else {
- FrameworkEventSource.Log.ResourceManagerCultureFoundInConfigFile(BaseNameField, MainAssembly, lookForCulture.Name);
- }
- }
-#endif
return pos >= 0;
}
// Note: There is one config file per appdomain. This is not
// per-process nor per-assembly.
- [System.Security.SecurityCritical] // auto-generated
private Hashtable GetSatelliteAssembliesFromConfig()
{
-#if FEATURE_FUSION
-
- String fileName = AppDomain.CurrentDomain.FusionStore.ConfigurationFileInternal;
- if (fileName == null) {
- return null;
- }
-
- // Don't do a security assert. We need to support semi-trusted
- // scenarios, but asserting here causes infinite resource lookups
- // while initializing security & looking up mscorlib's config file.
- // Use internal methods to bypass security checks.
-
- // If we're dealing with a local file name or a UNC path instead
- // of a URL, check to see if the file exists here for perf (avoids
- // throwing a FileNotFoundException).
- if (fileName.Length >= 2 &&
- ((fileName[1] == Path.VolumeSeparatorChar) || (fileName[0] == Path.DirectorySeparatorChar && fileName[1] == Path.DirectorySeparatorChar)) &&
- !File.InternalExists(fileName))
- return null;
-
- ConfigTreeParser parser = new ConfigTreeParser();
- String queryPath = "/configuration/satelliteassemblies";
- ConfigNode node = null;
- // Catch exceptions in case a web app doesn't have a config file.
- try {
- node = parser.Parse(fileName, queryPath, true);
- }
- catch(Exception) {}
-
- if (node == null) {
- return null;
- }
-
- // The application config file will contain sections like this:
- // <?xml version="1.0"?>
- // <configuration>
- // <satelliteassemblies>
- // <assembly name="mscorlib, Version=..., PublicKeyToken=...">
- // <culture>fr</culture>
- // </assembly>
- // <assembly name="UserAssembly, ...">
- // <culture>fr-FR</culture>
- // <culture>de-CH</culture>
- // </assembly>
- // <assembly name="UserAssembly2, ...">
- // </assembly>
- // </satelliteassemblies>
- // </configuration>
- Hashtable satelliteInfo = new Hashtable(StringComparer.OrdinalIgnoreCase);
- foreach(ConfigNode assemblyNode in node.Children) {
- if (!String.Equals(assemblyNode.Name, "assembly"))
- throw new ApplicationException(Environment.GetResourceString("XMLSyntax_InvalidSyntaxSatAssemTag", Path.GetFileName(fileName), assemblyNode.Name));
-
- if (assemblyNode.Attributes.Count == 0)
- throw new ApplicationException(Environment.GetResourceString("XMLSyntax_InvalidSyntaxSatAssemTagNoAttr", Path.GetFileName(fileName)));
-
- DictionaryEntry de = (DictionaryEntry) assemblyNode.Attributes[0];
- String assemblyName = (String) de.Value;
- if (!String.Equals(de.Key, "name") || String.IsNullOrEmpty(assemblyName) || assemblyNode.Attributes.Count > 1)
- throw new ApplicationException(Environment.GetResourceString("XMLSyntax_InvalidSyntaxSatAssemTagBadAttr", Path.GetFileName(fileName), de.Key, de.Value));
-
- ArrayList list = new ArrayList(5);
- foreach(ConfigNode child in assemblyNode.Children)
- if (child.Value != null)
- list.Add(child.Value);
-
- String[] satellites = new String[list.Count];
- for(int i=0; i<satellites.Length; i++) {
- String cultureName = (String)list[i];
- satellites[i] = cultureName;
-#if !FEATURE_CORECLR
- if (FrameworkEventSource.IsInitialized)
- {
- FrameworkEventSource.Log.ResourceManagerAddingCultureFromConfigFile(BaseNameField, MainAssembly, cultureName);
- }
-#endif
- }
-
- satelliteInfo.Add(assemblyName, satellites);
- }
-
- return satelliteInfo;
-#else
return null;
-#endif //FEATURE_FUSION
-
}
#endif // RESOURCE_SATELLITE_CONFIG
@@ -1586,7 +1343,7 @@ namespace System.Resources {
{
if (rm == null)
{
- throw new ArgumentNullException("rm");
+ throw new ArgumentNullException(nameof(rm));
}
_rm = rm;
}
@@ -1667,7 +1424,6 @@ namespace System.Resources {
#if RESOURCE_SATELLITE_CONFIG
- [System.Security.SecurityCritical] // auto-generated
internal bool TryLookingForSatellite(CultureInfo lookForCulture)
{
return _rm.TryLookingForSatellite(lookForCulture);
diff --git a/src/mscorlib/src/System/Resources/ResourceReader.cs b/src/mscorlib/src/System/Resources/ResourceReader.cs
index a269d5c5fe..89cfdb1b9f 100644
--- a/src/mscorlib/src/System/Resources/ResourceReader.cs
+++ b/src/mscorlib/src/System/Resources/ResourceReader.cs
@@ -31,6 +31,7 @@ namespace System.Resources {
using System.Globalization;
using System.Configuration.Assemblies;
using System.Runtime.Versioning;
+ using System.Diagnostics;
using System.Diagnostics.Contracts;
// Provides the default implementation of IResourceReader, reading
@@ -66,7 +67,7 @@ namespace System.Resources {
internal static bool CanCache(ResourceTypeCode value)
{
- Contract.Assert(value >= 0, "negative ResourceTypeCode. What?");
+ Debug.Assert(value >= 0, "negative ResourceTypeCode. What?");
return value <= ResourceTypeCode.LastPrimitive;
}
}
@@ -94,10 +95,8 @@ namespace System.Resources {
// of the assembly. The pointers here are pointers into that block of
// memory controlled by the OS's loader.
private int[] _nameHashes; // hash values for all names.
- [SecurityCritical]
private unsafe int* _nameHashesPtr; // In case we're using UnmanagedMemoryStream
private int[] _namePositions; // relative locations of names
- [SecurityCritical]
private unsafe int* _namePositionsPtr; // If we're using UnmanagedMemoryStream
private RuntimeType[] _typeTable; // Lazy array of Types for resource values.
private int[] _typeNamePositions; // To delay initialize type table
@@ -152,11 +151,6 @@ namespace System.Resources {
};
#endif // FEATURE_SERIALIZATION
- #if FEATURE_CORECLR
- [System.Security.SecurityCritical] // auto-generated
- #else
- [System.Security.SecuritySafeCritical]
- #endif
public ResourceReader(String fileName)
{
_resCache = new Dictionary<String, ResourceLocator>(FastResourceComparer.Default);
@@ -172,11 +166,10 @@ namespace System.Resources {
}
}
- [System.Security.SecurityCritical] // auto-generated_required
public ResourceReader(Stream stream)
{
if (stream==null)
- throw new ArgumentNullException("stream");
+ throw new ArgumentNullException(nameof(stream));
if (!stream.CanRead)
throw new ArgumentException(Environment.GetResourceString("Argument_StreamNotReadable"));
Contract.EndContractBlock();
@@ -194,7 +187,6 @@ namespace System.Resources {
// passing in the stream to read from and the RuntimeResourceSet's
// internal hash table (hash table of names with file offsets
// and values, coupled to this ResourceReader).
- [System.Security.SecurityCritical] // auto-generated
internal ResourceReader(Stream stream, Dictionary<String, ResourceLocator> resCache)
{
Contract.Requires(stream != null, "Need a stream!");
@@ -221,7 +213,6 @@ namespace System.Resources {
Close();
}
- [System.Security.SecuritySafeCritical] // auto-generated
private unsafe void Dispose(bool disposing)
{
if (_store != null) {
@@ -243,7 +234,6 @@ namespace System.Resources {
}
}
- [System.Security.SecurityCritical] // auto-generated
internal static unsafe int ReadUnalignedI4(int* p)
{
byte* buffer = (byte*)p;
@@ -264,11 +254,10 @@ namespace System.Resources {
_store.BaseStream.Seek(stringLength, SeekOrigin.Current);
}
- [System.Security.SecuritySafeCritical] // auto-generated
private unsafe int GetNameHash(int index)
{
- Contract.Assert(index >=0 && index < _numResources, "Bad index into hash array. index: "+index);
- Contract.Assert((_ums == null && _nameHashes != null && _nameHashesPtr == null) ||
+ Debug.Assert(index >=0 && index < _numResources, "Bad index into hash array. index: "+index);
+ Debug.Assert((_ums == null && _nameHashes != null && _nameHashesPtr == null) ||
(_ums != null && _nameHashes == null && _nameHashesPtr != null), "Internal state mangled.");
if (_ums == null)
return _nameHashes[index];
@@ -276,11 +265,10 @@ namespace System.Resources {
return ReadUnalignedI4(&_nameHashesPtr[index]);
}
- [System.Security.SecuritySafeCritical] // auto-generated
private unsafe int GetNamePosition(int index)
{
- Contract.Assert(index >=0 && index < _numResources, "Bad index into name position array. index: "+index);
- Contract.Assert((_ums == null && _namePositions != null && _namePositionsPtr == null) ||
+ Debug.Assert(index >=0 && index < _numResources, "Bad index into name position array. index: "+index);
+ Debug.Assert((_ums == null && _namePositions != null && _namePositionsPtr == null) ||
(_ums != null && _namePositions == null && _namePositionsPtr != null), "Internal state mangled.");
int r;
if (_ums == null)
@@ -316,7 +304,7 @@ namespace System.Resources {
// This does a binary search through the names.
internal int FindPosForResource(String name)
{
- Contract.Assert(_store != null, "ResourceReader is closed!");
+ Debug.Assert(_store != null, "ResourceReader is closed!");
int hash = FastResourceComparer.HashFunction(name);
BCLDebug.Log("RESMGRFILEFORMAT", "FindPosForResource for "+name+" hash: "+hash.ToString("x", CultureInfo.InvariantCulture));
// Binary search over the hashes. Use the _namePositions array to
@@ -395,10 +383,9 @@ namespace System.Resources {
// with the string you pass in.
// Whoever calls this method should make sure that they take a lock
// so no one else can cause us to seek in the stream.
- [System.Security.SecuritySafeCritical] // auto-generated
private unsafe bool CompareStringEqualsName(String name)
{
- Contract.Assert(_store != null, "ResourceReader is closed!");
+ Debug.Assert(_store != null, "ResourceReader is closed!");
int byteLen = _store.Read7BitEncodedInt();
if (byteLen < 0) {
throw new BadImageFormatException(Environment.GetResourceString("BadImageFormat_NegativeStringLength"));
@@ -433,10 +420,9 @@ namespace System.Resources {
// This is used in the enumerator. The enumerator iterates from 0 to n
// of our resources and this returns the resource name for a particular
// index. The parameter is NOT a virtual offset.
- [System.Security.SecurityCritical] // auto-generated
private unsafe String AllocateStringForNameIndex(int index, out int dataOffset)
{
- Contract.Assert(_store != null, "ResourceReader is closed!");
+ Debug.Assert(_store != null, "ResourceReader is closed!");
byte[] bytes;
int byteLen;
long nameVA = GetNamePosition(index);
@@ -500,7 +486,7 @@ namespace System.Resources {
// index. The parameter is NOT a virtual offset.
private Object GetValueForNameIndex(int index)
{
- Contract.Assert(_store != null, "ResourceReader is closed!");
+ Debug.Assert(_store != null, "ResourceReader is closed!");
long nameVA = GetNamePosition(index);
lock(this) {
_store.BaseStream.Seek(nameVA + _nameSectionOffset, SeekOrigin.Begin);
@@ -525,7 +511,7 @@ namespace System.Resources {
// no one can cause us to do a seek in here.
internal String LoadString(int pos)
{
- Contract.Assert(_store != null, "ResourceReader is closed!");
+ Debug.Assert(_store != null, "ResourceReader is closed!");
_store.BaseStream.Seek(_dataSectionOffset+pos, SeekOrigin.Begin);
String s = null;
int typeIndex = _store.Read7BitEncodedInt();
@@ -578,8 +564,8 @@ namespace System.Resources {
// no one can cause us to do a seek in here.
internal Object LoadObjectV1(int pos)
{
- Contract.Assert(_store != null, "ResourceReader is closed!");
- Contract.Assert(_version == 1, ".resources file was not a V1 .resources file!");
+ Debug.Assert(_store != null, "ResourceReader is closed!");
+ Debug.Assert(_version == 1, ".resources file was not a V1 .resources file!");
try {
// mega try-catch performs exceptionally bad on x64; factored out body into
@@ -595,7 +581,6 @@ namespace System.Resources {
}
#if FEATURE_SERIALIZATION
- [SecuritySafeCritical]
#endif
private Object _LoadObjectV1(int pos) {
_store.BaseStream.Seek(_dataSectionOffset+pos, SeekOrigin.Begin);
@@ -654,8 +639,8 @@ namespace System.Resources {
internal Object LoadObjectV2(int pos, out ResourceTypeCode typeCode)
{
- Contract.Assert(_store != null, "ResourceReader is closed!");
- Contract.Assert(_version >= 2, ".resources file was not a V2 (or higher) .resources file!");
+ Debug.Assert(_store != null, "ResourceReader is closed!");
+ Debug.Assert(_version >= 2, ".resources file was not a V2 (or higher) .resources file!");
try {
// mega try-catch performs exceptionally bad on x64; factored out body into
@@ -670,7 +655,6 @@ namespace System.Resources {
}
}
- [System.Security.SecuritySafeCritical] // auto-generated
private Object _LoadObjectV2(int pos, out ResourceTypeCode typeCode) {
_store.BaseStream.Seek(_dataSectionOffset+pos, SeekOrigin.Begin);
typeCode = (ResourceTypeCode) _store.Read7BitEncodedInt();
@@ -752,7 +736,7 @@ namespace System.Resources {
byte[] bytes = new byte[len];
int r = _ums.Read(bytes, 0, len);
- Contract.Assert(r == len, "ResourceReader needs to use a blocking read here. (Call _store.ReadBytes(len)?)");
+ Debug.Assert(r == len, "ResourceReader needs to use a blocking read here. (Call _store.ReadBytes(len)?)");
return bytes;
}
@@ -801,7 +785,6 @@ namespace System.Resources {
// deserialization binder to simulate a type-limiting deserializer.
// This method handles types that are safe to deserialize, as well as
// ensuring we only get back what we expect.
- [System.Security.SecurityCritical] // auto-generated
private Object DeserializeObject(int typeIndex)
{
RuntimeType type = FindType(typeIndex);
@@ -843,10 +826,9 @@ namespace System.Resources {
// 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.
- [System.Security.SecurityCritical] // auto-generated
private void ReadResources()
{
- Contract.Assert(_store != null, "ResourceReader is closed!");
+ Debug.Assert(_store != null, "ResourceReader is closed!");
#if FEATURE_SERIALIZATION
BinaryFormatter bf = new BinaryFormatter(null, new StreamingContext(StreamingContextStates.File | StreamingContextStates.Persistence));
_typeLimitingBinder = new TypeLimitingDeserializationBinder();
@@ -867,7 +849,6 @@ namespace System.Resources {
}
}
- [System.Security.SecurityCritical] // auto-generated
private void _ReadResources()
{
// Read ResourceManager header
@@ -1088,12 +1069,11 @@ namespace System.Resources {
_store.BaseStream.Position = oldPos;
}
}
- Contract.Assert(_typeTable[typeIndex] != null, "Should have found a type!");
+ Debug.Assert(_typeTable[typeIndex] != null, "Should have found a type!");
return _typeTable[typeIndex];
}
#if FEATURE_SERIALIZATION
- [System.Security.SecurityCritical] // auto-generated
private void InitSafeToDeserializeArray()
{
_safeToDeserialize = new bool[_typeTable.Length];
@@ -1165,7 +1145,7 @@ namespace System.Resources {
public void GetResourceData(String resourceName, out String resourceType, out byte[] resourceData)
{
if (resourceName == null)
- throw new ArgumentNullException("resourceName");
+ throw new ArgumentNullException(nameof(resourceName));
Contract.EndContractBlock();
if (_resCache == null)
throw new InvalidOperationException(Environment.GetResourceString("ResourceReaderIsClosed"));
@@ -1200,10 +1180,10 @@ namespace System.Resources {
Array.Sort(sortedDataPositions);
int index = Array.BinarySearch(sortedDataPositions, dataPos);
- Contract.Assert(index >= 0 && index < _numResources, "Couldn't find data position within sorted data positions array!");
+ Debug.Assert(index >= 0 && index < _numResources, "Couldn't find data position within sorted data positions array!");
long nextData = (index < _numResources - 1) ? sortedDataPositions[index + 1] + _dataSectionOffset : _store.BaseStream.Length;
int len = (int) (nextData - (dataPos + _dataSectionOffset));
- Contract.Assert(len >= 0 && len <= (int) _store.BaseStream.Length - dataPos + _dataSectionOffset, "Length was negative or outside the bounds of the file!");
+ Debug.Assert(len >= 0 && len <= (int) _store.BaseStream.Length - dataPos + _dataSectionOffset, "Length was negative or outside the bounds of the file!");
// Read type code then byte[]
_store.BaseStream.Position = _dataSectionOffset + dataPos;
@@ -1227,12 +1207,12 @@ namespace System.Resources {
{
Contract.Requires(typeCode >= 0, "can't be negative");
if (typeCode < ResourceTypeCode.StartOfUserTypes) {
- Contract.Assert(!String.Equals(typeCode.ToString(), "LastPrimitive"), "Change ResourceTypeCode metadata order so LastPrimitive isn't what Enum.ToString prefers.");
+ Debug.Assert(!String.Equals(typeCode.ToString(), "LastPrimitive"), "Change ResourceTypeCode metadata order so LastPrimitive isn't what Enum.ToString prefers.");
return "ResourceTypeCode." + typeCode.ToString();
}
else {
int typeIndex = typeCode - ResourceTypeCode.StartOfUserTypes;
- Contract.Assert(typeIndex >= 0 && typeIndex < _typeTable.Length, "TypeCode is broken or corrupted!");
+ Debug.Assert(typeIndex >= 0 && typeIndex < _typeTable.Length, "TypeCode is broken or corrupted!");
long oldPos = _store.BaseStream.Position;
try {
_store.BaseStream.Position = _typeNamePositions[typeIndex];
@@ -1277,7 +1257,6 @@ namespace System.Resources {
_typeToDeserialize = type;
}
- [System.Security.SecuritySafeCritical] // overrides transparent public member
public override Type BindToType(string assemblyName, string typeName)
{
// BinaryObjectReader::Bind tries us first, then its own code.
@@ -1343,7 +1322,6 @@ namespace System.Resources {
}
public Object Key {
- [System.Security.SecuritySafeCritical] // auto-generated
get {
if (_currentName == ENUM_DONE) throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumEnded));
if (!_currentIsValid) throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumNotStarted));
@@ -1367,7 +1345,6 @@ namespace System.Resources {
}
public DictionaryEntry Entry {
- [System.Security.SecuritySafeCritical] // auto-generated
get {
if (_currentName == ENUM_DONE) throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumEnded));
if (!_currentIsValid) throw new InvalidOperationException(Environment.GetResourceString(ResId.InvalidOperation_EnumNotStarted));
diff --git a/src/mscorlib/src/System/Resources/ResourceSet.cs b/src/mscorlib/src/System/Resources/ResourceSet.cs
index ed40a1237f..1b272fc6ff 100644
--- a/src/mscorlib/src/System/Resources/ResourceSet.cs
+++ b/src/mscorlib/src/System/Resources/ResourceSet.cs
@@ -31,15 +31,11 @@ namespace System.Resources {
// stores them in a hash table. Custom IResourceReaders can be used.
//
[Serializable]
-[System.Runtime.InteropServices.ComVisible(true)]
+ [System.Runtime.InteropServices.ComVisible(true)]
public class ResourceSet : IDisposable, IEnumerable
{
[NonSerialized] protected IResourceReader Reader;
-#if FEATURE_CORECLR
internal Hashtable Table;
-#else
- protected Hashtable Table;
-#endif
private Hashtable _caseInsensitiveTable; // For case-insensitive lookups.
@@ -65,9 +61,6 @@ namespace System.Resources {
// implementation. Use this constructor to open & read from a file
// on disk.
//
- #if FEATURE_CORECLR
- [System.Security.SecurityCritical] // auto-generated
- #endif
public ResourceSet(String fileName)
{
Reader = new ResourceReader(fileName);
@@ -89,7 +82,6 @@ namespace System.Resources {
// implementation. Use this constructor to read from an open stream
// of data.
//
- [System.Security.SecurityCritical] // auto-generated_required
public ResourceSet(Stream stream)
{
Reader = new ResourceReader(stream);
@@ -98,7 +90,6 @@ namespace System.Resources {
}
#if LOOSELY_LINKED_RESOURCE_REFERENCE
- [System.Security.SecurityCritical] // auto_generated_required
public ResourceSet(Stream stream, Assembly assembly)
{
Reader = new ResourceReader(stream);
@@ -111,7 +102,7 @@ namespace System.Resources {
public ResourceSet(IResourceReader reader)
{
if (reader == null)
- throw new ArgumentNullException("reader");
+ throw new ArgumentNullException(nameof(reader));
Contract.EndContractBlock();
Reader = reader;
CommonInit();
@@ -122,7 +113,7 @@ namespace System.Resources {
public ResourceSet(IResourceReader reader, Assembly assembly)
{
if (reader == null)
- throw new ArgumentNullException("reader");
+ throw new ArgumentNullException(nameof(reader));
Contract.EndContractBlock();
Reader = reader;
CommonInit();
@@ -182,15 +173,13 @@ namespace System.Resources {
return typeof(ResourceReader);
}
-#if !FEATURE_CORECLR
// Returns the preferred IResourceWriter class for this kind of ResourceSet.
// Subclasses of ResourceSet using their own Readers &; should override
// GetDefaultReader and GetDefaultWriter.
public virtual Type GetDefaultWriter()
{
- return typeof(ResourceWriter);
+ return Type.GetType("System.Resources.ResourceWriter, System.Resources.Writer, Version=4.0.1.0, Culture=neutral, PublicKeyToken=" + AssemblyRef.MicrosoftPublicKeyToken, throwOnError: true);
}
-#endif // !FEATURE_CORECLR
[ComVisible(false)]
public virtual IDictionaryEnumerator GetEnumerator()
@@ -291,7 +280,7 @@ namespace System.Resources {
private Object GetObjectInternal(String name)
{
if (name == null)
- throw new ArgumentNullException("name");
+ throw new ArgumentNullException(nameof(name));
Contract.EndContractBlock();
Hashtable copyOfTable = Table; // Avoid a race with Dispose
diff --git a/src/mscorlib/src/System/Resources/RuntimeResourceSet.cs b/src/mscorlib/src/System/Resources/RuntimeResourceSet.cs
index 6b512bcf6a..a94ac82781 100644
--- a/src/mscorlib/src/System/Resources/RuntimeResourceSet.cs
+++ b/src/mscorlib/src/System/Resources/RuntimeResourceSet.cs
@@ -20,6 +20,7 @@ namespace System.Resources {
using System.Globalization;
using System.Reflection;
using System.Runtime.Versioning;
+ using System.Diagnostics;
using System.Diagnostics.Contracts;
// A RuntimeResourceSet stores all the resources defined in one
@@ -184,7 +185,6 @@ namespace System.Resources {
// the resources once, adding them into the table.
private bool _haveReadFromReader;
- [System.Security.SecurityCritical] // auto-generated
internal RuntimeResourceSet(String fileName) : base(false)
{
BCLDebug.Log("RESMGRFILEFORMAT", "RuntimeResourceSet .ctor(String)");
@@ -204,7 +204,6 @@ namespace System.Resources {
Assembly = assembly;
}
#else
- [System.Security.SecurityCritical] // auto-generated
internal RuntimeResourceSet(Stream stream) : base(false)
{
BCLDebug.Log("RESMGRFILEFORMAT", "RuntimeResourceSet .ctor(Stream)");
@@ -285,7 +284,7 @@ namespace System.Resources {
private Object GetObject(String key, bool ignoreCase, bool isString)
{
if (key==null)
- throw new ArgumentNullException("key");
+ throw new ArgumentNullException(nameof(key));
if (Reader == null || _resCache == null)
throw new ObjectDisposedException(null, Environment.GetResourceString("ObjectDisposed_ResourceSet"));
Contract.EndContractBlock();
@@ -312,7 +311,7 @@ namespace System.Resources {
}
if (dataPos != -1 && value == null) {
- Contract.Assert(dataPos >= 0, "data section offset cannot be negative!");
+ Debug.Assert(dataPos >= 0, "data section offset cannot be negative!");
// Normally calling LoadString or LoadObject requires
// taking a lock. Note that in this case, we took a
// lock on the entire RuntimeResourceSet, which is
@@ -373,7 +372,7 @@ namespace System.Resources {
Reader.Close();
}
else {
- Contract.Assert(ignoreCase, "This should only happen for case-insensitive lookups");
+ Debug.Assert(ignoreCase, "This should only happen for case-insensitive lookups");
ResourceReader.ResourceEnumerator en = _defaultReader.GetEnumeratorInternal();
while (en.MoveNext()) {
// Note: Always ask for the resource key before the data position.
diff --git a/src/mscorlib/src/System/Resources/SatelliteContractVersionAttribute.cs b/src/mscorlib/src/System/Resources/SatelliteContractVersionAttribute.cs
index f72e810227..327279062a 100644
--- a/src/mscorlib/src/System/Resources/SatelliteContractVersionAttribute.cs
+++ b/src/mscorlib/src/System/Resources/SatelliteContractVersionAttribute.cs
@@ -27,7 +27,7 @@ namespace System.Resources {
public SatelliteContractVersionAttribute(String version)
{
if (version == null)
- throw new ArgumentNullException("version");
+ throw new ArgumentNullException(nameof(version));
Contract.EndContractBlock();
_version = version;
}
diff --git a/src/mscorlib/src/System/Resources/__FastResourceComparer.cs b/src/mscorlib/src/System/Resources/__FastResourceComparer.cs
index 5bc7333863..e0911fae1d 100644
--- a/src/mscorlib/src/System/Resources/__FastResourceComparer.cs
+++ b/src/mscorlib/src/System/Resources/__FastResourceComparer.cs
@@ -17,6 +17,7 @@ namespace System.Resources {
using System;
using System.Collections;
using System.Collections.Generic;
+ using System.Diagnostics;
using System.Diagnostics.Contracts;
internal sealed class FastResourceComparer : IComparer, IEqualityComparer, IComparer<String>, IEqualityComparer<String>
@@ -78,11 +79,10 @@ namespace System.Resources {
// Input is one string to compare with, and a byte[] containing chars in
// little endian unicode. Pass in the number of valid chars.
- [System.Security.SecurityCritical] // auto-generated
public unsafe static int CompareOrdinal(String a, byte[] bytes, int bCharLength)
{
- Contract.Assert(a != null && bytes != null, "FastResourceComparer::CompareOrdinal must have non-null params");
- Contract.Assert(bCharLength * 2 <= bytes.Length, "FastResourceComparer::CompareOrdinal - numChars is too big!");
+ Debug.Assert(a != null && bytes != null, "FastResourceComparer::CompareOrdinal must have non-null params");
+ Debug.Assert(bCharLength * 2 <= bytes.Length, "FastResourceComparer::CompareOrdinal - numChars is too big!");
// This is a managed version of strcmp, but I can't take advantage
// of a terminating 0, unlike strcmp in C.
int i = 0;
@@ -107,7 +107,6 @@ namespace System.Resources {
return a.Length - bCharLength;
}
- [System.Security.SecurityCritical] // auto-generated
public static int CompareOrdinal(byte[] bytes, int aCharLength, String b)
{
return -CompareOrdinal(b, bytes, aCharLength);
@@ -115,12 +114,11 @@ namespace System.Resources {
// This method is to handle potentially misaligned data accesses.
// The byte* must point to little endian Unicode characters.
- [System.Security.SecurityCritical] // auto-generated
internal unsafe static int CompareOrdinal(byte* a, int byteLen, String b)
{
- Contract.Assert((byteLen & 1) == 0, "CompareOrdinal is expecting a UTF-16 string length, which must be even!");
- Contract.Assert(a != null && b != null, "Null args not allowed.");
- Contract.Assert(byteLen >= 0, "byteLen must be non-negative.");
+ Debug.Assert((byteLen & 1) == 0, "CompareOrdinal is expecting a UTF-16 string length, which must be even!");
+ Debug.Assert(a != null && b != null, "Null args not allowed.");
+ Debug.Assert(byteLen >= 0, "byteLen must be non-negative.");
int r = 0;
int i = 0;