-
Notifications
You must be signed in to change notification settings - Fork 1
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
When generating postman collection, an exception occurs if a controller request body contains a property of type IList<string>. The issue arises because the code attempts to instantiate string elements using Activator.CreateInstance, which is not supported for the string type.
Error Message
Unhandled exception. System.MissingMethodException: Cannot dynamically create an instance of type 'System.String'. Reason: Uninitialized Strings cannot be created.
at System.RuntimeType.ActivatorCache..ctor(RuntimeType rt)
at System.RuntimeType.IGenericCacheEntry`1.CreateAndCache(RuntimeType type)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)
at Simplify.Web.Postman.Assembly.Collection.PartBuilders.RequestBuilder.InitializeListsSingleEmptyValues(Object model)
at Simplify.Web.Postman.Assembly.Collection.PartBuilders.RequestBuilder.BuildRequestJsonData(Type modelType)
at Simplify.Web.Postman.Assembly.Collection.PartBuilders.RequestBuilder.TryBuildBody(IControllerMetadata metaData)
at Simplify.Web.Postman.Assembly.Collection.PartBuilders.RequestBuilder.Build(IControllerMetadata metaData, KeyValuePair`2 route)
at Simplify.Web.Postman.Assembly.Collection.PartBuilders.CollectionItemsBuilder.BuildRequestCollectionItem(IControllerMetadata metaData, KeyValuePair`2 route)
at Simplify.Web.Postman.Assembly.Collection.PartBuilders.CollectionItemsBuilder.Build(CollectionModel model)
at Simplify.Web.Postman.Assembly.Collection.CollectionBuilder.Create()
at Simplify.Web.Postman.Generators.FileBasedCollectionGenerator.Generate()
at Simplify.Web.Postman.Generators.FileBasedPostmanGenerator.Generate()
at Simplify.Web.Postman.Setup.SimplifyDIContextHandlerExtensions.GeneratePostmanData(IDIContextHandler contextHandler)
Steps to Reproduce
- Create a controller with a request model containing a
IList<string>property. - Attempt to generate a Postman collection.
- Observe the
MissingMethodExceptionduring collection generation.
Expected Behavior
The package should handle IList<string> and string properties gracefully, initializing string elements as empty strings or with a suitable default value, so that Postman collections can be generated for all valid request models without exceptions.
Solution
The fix involves:
- Checking for string types before attempting to use
Activator.CreateInstance. - Returning
string.Emptyfor string types instead of using the activator.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working
Type
Projects
Status
Closed