Quantcast
Channel: CRM Development forum
Viewing all articles
Browse latest Browse all 8223

CRM 2011 CrmSvcUtil.exe: Cannot convert type 'Microsoft.Xrm.Sdk.OptionSetValue' to 'int'

$
0
0

Hi,

i use crmsvcutil.exe to generate early bound classes and it's working fine for shared OptionSets, but if the OptionSet is not shared like producttypecode in the product entity then it's trying to convert an OptionSetValue to int and this is not working. In my example i have a not shared OptionSet prg_teilnehmertyp it's easily fixable to just replace

this.SetAttributeValue("prg_teilnehmertyp", new Microsoft.Xrm.Sdk.OptionSetValue(((int)(value))));

with

                this.OnPropertyChanging("prg_teilnehmertyp");
                this.SetAttributeValue("prg_teilnehmertyp", value);
                this.OnPropertyChanged("prg_teilnehmertyp");

Any Ideas how to solve this on CrmSvcUtil.exe side?

To filter the result from CrmSvcUtil.exe i use ICodeWriterFilterService.

Code snippet from a generated class with CrmSvcUtil.exe

[Microsoft.Xrm.Sdk.AttributeLogicalNameAttribute("prg_teilnehmertyp")]
public Microsoft.Xrm.Sdk.OptionSetValue prg_teilnehmertyp
{
get
{
Microsoft.Xrm.Sdk.OptionSetValue optionSet = this.GetAttributeValue<Microsoft.Xrm.Sdk.OptionSetValue>("prg_teilnehmertyp");
if ((optionSet != null))
{
return ((Microsoft.Xrm.Sdk.OptionSetValue)(System.Enum.ToObject(typeof(Microsoft.Xrm.Sdk.OptionSetValue), optionSet.Value)));
}
else
{
return null;
}
}
set
{
this.OnPropertyChanging("prg_teilnehmertyp");
if ((value == null))
{
this.SetAttributeValue("prg_teilnehmertyp", null);
}
else
{
this.SetAttributeValue("prg_teilnehmertyp", new Microsoft.Xrm.Sdk.OptionSetValue(((int)(value)))); // here the compile error occurs: "Cannot convert type 'Microsoft.Xrm.Sdk.OptionSetValue' to 'int'"
}
this.OnPropertyChanged("prg_teilnehmertyp");
}
}

Kind Regards

Markus




Viewing all articles
Browse latest Browse all 8223

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>