Hello Experts,
I am trying to create entity and attribute. so for this my code is like below.
private void CreateEntity(ServerConnection.Configuration serverConfig,string entityName, OwnershipTypes ownerType)
{
try
{
using (_serviceProxy = new OrganizationServiceProxy(serverConfig.OrganizationUri,
serverConfig.HomeRealmUri,
serverConfig.Credentials,
serverConfig.DeviceCredentials))
{
_serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(
new ProxyTypesBehavior());
// Create custom entity.
CreateEntityRequest _entity = new CreateEntityRequest()
{
Entity =
new EntityMetadata
{
LogicalName = entityName,
DisplayName =
new Microsoft.Xrm.Sdk.Label(entityName, 1033),
DisplayCollectionName =
new Microsoft.Xrm.Sdk.Label(entityName, 1033),
OwnershipType = ownerType,
SchemaName = entityName,
IsActivity =
false,
// IsAvailableOffline = true,
// IsAuditEnabled = new BooleanManagedProperty(true),
//IsMailMergeEnabled = new BooleanManagedProperty(false)
},
// HasActivities = false,
// HasNotes = true,
PrimaryAttribute =
new StringAttributeMetadata()
{
SchemaName =
"new_name",
LogicalName =
"new_name",
RequiredLevel =
new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.Recommended),
MaxLength = 100,
DisplayName =
new Microsoft.Xrm.Sdk.Label("Name", 1033)
}
 
 
};
_serviceProxy.Execute(_entity);
PublishAllXmlRequest publishReq = new PublishAllXmlRequest();
_serviceProxy.Execute(publishReq);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message+"\n"+ex.StackTrace);
}
}
// Code for Attribute Create
private void CreateAttribute(string entityName)
{
if (addedAttributes != null)
{
foreach (AttributeMetadata anAttribute in addedAttributes)
{
// Create the request.
CreateAttributeRequest createAttributeRequest = new CreateAttributeRequest
{
EntityName = entityName,
Attribute = anAttribute
};
// Execute the request.
_serviceProxy.Execute(createAttributeRequest);
//Console.WriteLine("Created the attribute {0}.", anAttribute.SchemaName);
}
}
}
While creating attribute I am getting following error
Could not find an entity with specified entity name: new_MyCustomEntity
Server stack trace:
at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at Microsoft.Xrm.Sdk.IOrganizationService.Execute(OrganizationRequest request)
at Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy.ExecuteCore(OrganizationRequest request)
at Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy.Execute(OrganizationRequest request)
at EntityCreation.NewEntity.CreateAttribute(String entityName) in d:\Saroj\EntityCreation\EntityCreation\NewEntity.cs:line 609
at EntityCreation.NewEntity.btnCreate_Click(Object sender, EventArgs e) in d:\Saroj\EntityCreation\EntityCreation\NewEntity.cs:line 292
When I am checking CRM 2015 online, The entity is created. It was working fine. But now not working. Please suggest what might be the problem.
Best Regards,
Saroj