Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not create CfnMapping object in .NET : Could not infer JSII type for .NET type 'JValue' (Parameter 'type') #7392

Closed
Pankajc123 opened this issue Apr 16, 2020 · 5 comments
Labels
@aws-cdk/core Related to core CDK functionality bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. effort/small Small work item – less than a day of effort jsii This issue originates in jsii, or this feature must be implemented in jsii. language/dotnet Related to .NET bindings p1

Comments

@Pankajc123
Copy link

While creating CfnMapping object in .NET, I am getting error as

Unhandled exception. System.ArgumentException: Could not infer JSII type for .NET type 'JValue' (Parameter 'type')

I am able to set "Mapping" property correctly, but when I run "cdk synth command, I am getting above error.

Reproduction Steps

Below is .Net code snippet

using Amazon.CDK;
using Newtonsoft.Json.Linq;
using System.IO;
using System.Collections.Generic;
namespace Missionserver
{
    public class MissionserverStack : Stack
    {
        internal MissionserverStack(Construct scope, string id, IStackProps props = null) : base(scope, id, props)
        {          
            var doccontent = File.ReadAllText("./mapping.json");

            var str = new Dictionary<string, object>();
            var str2 = new Dictionary<string, IDictionary<string,object>>();
            var str3 = JObject.Parse(doccontent);

            foreach(var item in str3)
            {
                str.Clear();
                var jobj = (JObject)str3[item.Key];
                str.Add("bucket", (object)jobj["bucket"]);
                str.Add("region", (object)jobj["region"]);
                str2.Add(item.Key, str);
            }

            var m = new CfnMapping(this, "Repositories", new CfnMappingProps
            {
                Mapping = str2
            });

        }
    }
}

Below is my "mapping.json" file


{
	"us-east-1": {
		"bucket": "arcgisdaily-repo-us-east-1",
		"region": "us-east-1"
	},
	"us-east-2": {
		"bucket": "arcgisdaily-repo-us-east-1",
		"region": "us-east-1"
	},
	"us-west-1": {
		"bucket": "arcgisdaily-repo-us-east-1",
		"region": "us-east-1"
	},
	"us-west-2": {
		"bucket": "arcgisdaily-repo-us-east-1",
		"region": "us-east-1"
	}
}

Error Log

Unhandled exception. System.ArgumentException: Could not infer JSII type for .NET type 'JValue' (Parameter 'type')

at Amazon.JSII.Runtime.Services.Converters.FrameworkToJsiiConverter.InferType(IReferenceMap referenceMap, Type type)
  at Amazon.JSII.Runtime.Services.Converters.FrameworkToJsiiConverter.InferType(IReferenceMap referenceMap, Object value)
  at Amazon.JSII.Runtime.Services.Converters.ValueConverter.ConvertAny(Type type, IReferenceMap referenceMap, Object value)
  at Amazon.JSII.Runtime.Services.Converters.ValueConverter.TryConvertPrimitive(Type type, IReferenceMap referenceMap, Object value, Boolean isOptional, PrimitiveType primitiveType, Object& result)
  at Amazon.JSII.Runtime.Services.Converters.ValueConverter.TryConvert(IOptionalValue optionalValue, Type type, IReferenceMap referenceMap, Object value, Object& result)
  at Amazon.JSII.Runtime.Services.Converters.ValueConverter.TryConvert(TypeReference typeReference, Type type, IReferenceMap referenceMap, Object value, Object& result)
  at Amazon.JSII.Runtime.Services.Converters.FrameworkToJsiiConverter.TryConvertCollectionElement(Object element, IReferenceMap referenceMap, TypeReference elementType, Object& convertedElement)
  at Amazon.JSII.Runtime.Services.Converters.FrameworkToJsiiConverter.TryConvertMap(IReferenceMap referenceMap, TypeReference elementType, Object value, Object& result)
  at Amazon.JSII.Runtime.Services.Converters.FrameworkToJsiiConverter.TryConvertCollectionElement(Object element, IReferenceMap referenceMap, TypeReference elementType, Object& convertedElement)
  at Amazon.JSII.Runtime.Services.Converters.FrameworkToJsiiConverter.TryConvertMap(IReferenceMap referenceMap, TypeReference elementType, Object value, Object& result)
  at Amazon.JSII.Runtime.Services.Converters.ValueConverter.TryConvertCollection(IReferenceMap referenceMap, Object value, Boolean isOptional, CollectionTypeReference collectionType, Object& result)
  at Amazon.JSII.Runtime.Services.Converters.ValueConverter.TryConvert(IOptionalValue optionalValue, Type type, IReferenceMap referenceMap, Object value, Object& result)
  at Amazon.JSII.Runtime.Services.Converters.FrameworkToJsiiConverter.TryConvertClass(Type type, IReferenceMap referenceMap, Object value, Object& result)
  at Amazon.JSII.Runtime.Services.Converters.ValueConverter.TryConvertCustomType(Type type, IReferenceMap referenceMap,
Object value, Boolean isOptional, String fullyQualifiedName, Object& result)
  at Amazon.JSII.Runtime.Services.Converters.ValueConverter.TryConvert(IOptionalValue optionalValue, Type type, IReferenceMap referenceMap, Object value, Object& result)
  at Amazon.JSII.Runtime.Services.Converters.FrameworkToJsiiConverter.TryConvert(IOptionalValue optionalValue, IReferenceMap referenceMap, Object value, Object& result)
  at Amazon.JSII.Runtime.Deputy.DeputyBase.<>c__DisplayClass20_0.<ConvertArguments>b__0(Parameter parameter, Object frameworkArgument)
  at System.Linq.Enumerable.ZipIterator[TFirst,TSecond,TResult](IEnumerable`1 first, IEnumerable`1 second, Func`3 resultSelector)+MoveNext()
  at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items)
  at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 source)
  at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
  at Amazon.JSII.Runtime.Deputy.DeputyBase..ctor(DeputyProps props)
  at Amazon.CDK.Construct..ctor(DeputyProps props)
  at Amazon.CDK.CfnElement..ctor(DeputyProps props)
  at Amazon.CDK.CfnRefElement..ctor(DeputyProps props)
  at Amazon.CDK.CfnMapping..ctor(Construct scope, String id, ICfnMappingProps props)
  at Missionserver.MissionserverStack..ctor(Construct scope, String id, IStackProps props) in E:\CDKWorkshop\missionserver\src\Missionserver\MissionserverStack.cs:line 57
  at Missionserver.Program.Main(String[] args) in E:\CDKWorkshop\missionserver\src\Missionserver\Program.cs:line 17

Environment

  • **CLI Version : 1.24.0
  • **Framework Version: 1.24.0
  • **OS : Windows
  • **Language : .Net

Other

I am quite sure my code is correct and found that similar errors are already reported. (#5317)

Let me know if you need more information. Your help will be much appreciated. Thanks.


This is 🐛 Bug Report

@Pankajc123 Pankajc123 added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Apr 16, 2020
@SomayaB SomayaB added language/dotnet Related to .NET bindings @aws-cdk/core Related to core CDK functionality jsii This issue originates in jsii, or this feature must be implemented in jsii. labels Apr 20, 2020
@MrArnoldPalmer MrArnoldPalmer added p1 and removed needs-triage This issue or PR still needs to be triaged. labels Apr 23, 2020
@Pankajc123
Copy link
Author

is this issue fixed?

@Pankajc123
Copy link
Author

Hello,

Is this issue resolved?

@MrArnoldPalmer
Copy link
Contributor

hey @Pankajc123, this hasn't been solved but you may be able to workaround it by specifying a more specific type if you're able as detailed in aws/jsii#1044

@MrArnoldPalmer MrArnoldPalmer added the effort/small Small work item – less than a day of effort label Aug 17, 2020
@Pankajc123
Copy link
Author

@MrArnoldPalmer Thanks for your workaround. I am able to get past that problem. But i would still like to be fixed.

@github-actions
Copy link

This issue has not received any attention in 1 year. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Jun 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/core Related to core CDK functionality bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. effort/small Small work item – less than a day of effort jsii This issue originates in jsii, or this feature must be implemented in jsii. language/dotnet Related to .NET bindings p1
Projects
None yet
Development

No branches or pull requests

3 participants