Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Commit e582b1d

Browse files
committed
changed exception message
1 parent 4feb51c commit e582b1d

File tree

5 files changed

+27
-27
lines changed

5 files changed

+27
-27
lines changed

src/Microsoft.AspNet.Mvc.Core/Properties/Resources.Designer.cs

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Microsoft.AspNet.Mvc.Core/Resources.resx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,12 +452,12 @@
452452
<value>The model's runtime type '{0}' is not assignable to the type '{1}'.</value>
453453
</data>
454454
<data name="TempData_CannotSerializeToSession" xml:space="preserve">
455-
<value>The type {0} cannot be serialized to Session by '{1}'.</value>
455+
<value>The '{0}' cannot serialize an object of type '{1}' to session state.</value>
456456
</data>
457457
<data name="TempData_CannotDeserializeToken" xml:space="preserve">
458458
<value>Cannot deserialize JToken of type {0}.</value>
459459
</data>
460460
<data name="TempData_CannotSerializeDictionary" xml:space="preserve">
461-
<value>The dictionary with TKey {0} cannot be serialized to Session by '{1}'.</value>
461+
<value>The '{0}' cannot serialize a dictionary with a key of type '{1}' to session state.</value>
462462
</data>
463463
</root>

src/Microsoft.AspNet.Mvc.Core/SessionStateTempDataProvider.cs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Collections.Concurrent;
66
using System.Collections.Generic;
7+
using System.Diagnostics;
78
using System.IO;
89
using System.Linq;
910
using System.Reflection;
@@ -183,27 +184,26 @@ internal void EnsureObjectCanBeSerialized(object item)
183184
}
184185
else if (itemType.GetTypeInfo().IsGenericType)
185186
{
186-
if (itemType.ExtractGenericInterface(typeof(IList<>)) != null ||
187-
itemType.ExtractGenericInterface(typeof(IDictionary<,>)) != null)
187+
if (itemType.ExtractGenericInterface(typeof(IList<>)) != null)
188188
{
189189
var genericTypeArguments = itemType.GetGenericArguments();
190-
if (genericTypeArguments.Length > 1)
190+
Debug.Assert(genericTypeArguments.Length == 1, "IList<T> has one generic argument");
191+
actualType = genericTypeArguments[0];
192+
}
193+
else if (itemType.ExtractGenericInterface(typeof(IDictionary<,>)) != null)
194+
{
195+
var genericTypeArguments = itemType.GetGenericArguments();
196+
Debug.Assert(genericTypeArguments.Length == 2, "IDictionary<TKey, TValue> has two generic arguments");
197+
// Throw if the key type of the dictionary is not string.
198+
if (genericTypeArguments[0] != typeof(string))
191199
{
192-
// Throw if the key type of the dictionary is not string.
193-
if (genericTypeArguments[0] != typeof(string))
194-
{
195-
var message = Resources.FormatTempData_CannotSerializeDictionary(genericTypeArguments[0],
196-
typeof(SessionStateTempDataProvider).FullName);
197-
throw new InvalidOperationException(message);
198-
}
199-
else
200-
{
201-
actualType = genericTypeArguments[1];
202-
}
200+
var message = Resources.FormatTempData_CannotSerializeDictionary(
201+
typeof(SessionStateTempDataProvider).FullName, genericTypeArguments[0]);
202+
throw new InvalidOperationException(message);
203203
}
204204
else
205205
{
206-
actualType = genericTypeArguments[0];
206+
actualType = genericTypeArguments[1];
207207
}
208208
}
209209
}
@@ -212,8 +212,8 @@ internal void EnsureObjectCanBeSerialized(object item)
212212
if (!TypeHelper.IsSimpleType(actualType))
213213
{
214214
var underlyingType = Nullable.GetUnderlyingType(actualType) ?? actualType;
215-
var message = Resources.FormatTempData_CannotSerializeToSession(underlyingType,
216-
typeof(SessionStateTempDataProvider).FullName);
215+
var message = Resources.FormatTempData_CannotSerializeToSession(
216+
typeof(SessionStateTempDataProvider).FullName, underlyingType);
217217
throw new InvalidOperationException(message);
218218
}
219219
}

test/Microsoft.AspNet.Mvc.Core.Test/SessionStateTempDataProviderTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public void EnsureObjectCanBeSerialized_InvalidType_Throws(object value, Type ty
104104
{
105105
testProvider.EnsureObjectCanBeSerialized(value);
106106
});
107-
Assert.Equal($"The type {type} cannot be serialized to Session by '{typeof(SessionStateTempDataProvider).FullName}'.",
107+
Assert.Equal($"The '{typeof(SessionStateTempDataProvider).FullName}' cannot serialize an object of type '{type}' to session state.",
108108
exception.Message);
109109
}
110110

@@ -134,7 +134,7 @@ public void EnsureObjectCanBeSerialized_InvalidDictionaryType_Throws(object valu
134134
{
135135
testProvider.EnsureObjectCanBeSerialized(value);
136136
});
137-
Assert.Equal($"The dictionary with TKey {type} cannot be serialized to Session by '{typeof(SessionStateTempDataProvider).FullName}'.",
137+
Assert.Equal($"The '{typeof(SessionStateTempDataProvider).FullName}' cannot serialize a dictionary with a key of type '{type}' to session state.",
138138
exception.Message);
139139
}
140140

test/Microsoft.AspNet.Mvc.FunctionalTests/TempDataTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ public async Task TempData_InvalidType_Throws()
193193
{
194194
await client.PostAsync("/Home/SetTempDataInvalidType", content);
195195
});
196-
Assert.Equal("The type " + typeof(TempDataWebSite.Controllers.HomeController.NonSerializableType).FullName +
197-
" cannot be serialized to Session by '" + typeof(SessionStateTempDataProvider).FullName + "'.", exception.Message);
196+
Assert.Equal("The '" + typeof(SessionStateTempDataProvider).FullName + "' cannot serialize an object of type '" +
197+
typeof(TempDataWebSite.Controllers.HomeController.NonSerializableType).FullName + "' to session state.", exception.Message);
198198
}
199199

200200
private HttpRequestMessage GetRequest(string path, HttpResponseMessage response)

0 commit comments

Comments
 (0)