ConfuserEx icon indicating copy to clipboard operation
ConfuserEx copied to clipboard

Annoymous object obfuscated by "renameArg" would cause JsonSerializationException

Open SLdragon opened this issue 5 years ago • 1 comments

sample code:

            var obj = new
            {
                a = "1",
                b = 2,
                c = "c"
            };

            var str = JsonConvert.SerializeObject(obj);
            Console.WriteLine(str);

Test config:

<project outputDir=".\" baseDir=".\" xmlns="http://confuser.codeplex.com">
	<module path="test.exe">
		<rule pattern="true">
			<protection id="rename">
				<argument name="renameArgs" value="true" />
			</protection>
		</rule>
	</module>
</project>

After obfuscated, it would throw exceptions as below:

Unhandled Exception: Newtonsoft.Json.JsonSerializationException: A member with the name '' already exists on '_D`3[System.String,System.Int32,System.String]'. Use the JsonPropertyAttribute to specify another name.
   at Newtonsoft.Json.Serialization.JsonPropertyCollection.AddProperty(JsonProperty property)
   at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateConstructorParameters(ConstructorInfo constructor, JsonPropertyCollection memberProperties)
   at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateObjectContract(Type objectType)
   at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract(Type objectType)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveContract(Type type)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)

Are there any settings to avoid obufuscating annoymous object?

SLdragon avatar Feb 12 '20 15:02 SLdragon

me too

tecno14 avatar Dec 15 '20 13:12 tecno14