-
Notifications
You must be signed in to change notification settings - Fork 180
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
Specified Cast is not valid #116
Comments
Hi @don-matese , Just checked in some code to reproduce your issue and both queries run fine. This is normally related to the way crmsvcutil generates the early bound types, cause there might be difference across different versions of the crmsvcutil. For instance, closed issue #114 was exactly the same thing, a crmsvcutil was generating enums as nullable ints, instead of the previous tested cases with Enums or OptionSetValue for example. Could you post what types do you have in your generated classes for the properties involved in the queries above? This is the applied fix for #114, could you add a new case there maybe with your specific types, and submit a PR? Cheers |
Hi Jordi,
They are all EntityReference fields declared as follows
[Microsoft.Xrm.Sdk.AttributeLogicalNameAttribute("primarycontactid")]
public Microsoft.Xrm.Client.CrmEntityReference PrimaryContactId
{
get
{
return
this.GetAttributeValue<Microsoft.Xrm.Sdk.EntityReference>("primarycontactid");
}
set
{
this.SetAttributeValue<Microsoft.Xrm.Sdk.EntityReference>("PrimaryContactId",
"primarycontactid", value);
}
}
…On 2 February 2017 at 09:06, Jordi ***@***.***> wrote:
Hi @don-matese <https://github.com/don-matese> ,
Just checked in some code to reproduce your issue and both queries run
fine. This is normally related to the way crmsvcutil generates the early
bound types, cause there might be difference across different versions of
the crmsvcutil. For instance, closed issue #114
<#114> was exactly
the same thing, a crmsvcutil was generating enums as nullable ints, instead
of the previous tested cases with Enums or OptionSetValue for example.
Could you post what types do you have in your generated classes for the
properties involved in the queries above?
Cheers
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#116 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABl8KHx-k1RhKbmCtVTtR5l_Ky-thLTHks5rYZyDgaJpZM4L0El_>
.
|
Just one thing then... I replaced your attributenames definitions by lowercase as the AttributeNames wasn't in your sample, maybe you aren't using lowercase names? Are you on latest version 1.20.1? Cause those examples run fine without exceptions :) |
Mmm runs fine locally, fails on appveyor, but probably related to referenced SDK version. Will double check again |
I have the latest version, given one of the queries works and the other
doesn't I think I am more inclined to believe either the code I inherited
is flawed (likely) or the structure of the query is unexpected in the
QueryExpression handler in FakeXrmEasy. Either way, I suspect its the way
the Query in CreateBrokenTestQuery is constructed thats at the root of the
issue - thanks for your time on this though.
Mauro
…On 2 February 2017 at 09:20, Jordi ***@***.***> wrote:
Mmm runs fine locally, fails on appveyor, but probably related to
referenced SDK version. Will double check again
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#116 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABl8KHITAOPX-dMJjDRP3TWGf9PwMUuCks5rYZ_zgaJpZM4L0El_>
.
|
Apologies Jordi
Having looked at the code a bit more closely, while the Attributes I am
filtering on are indeed EntityReferences, other fields are declared as
nullable<int>
Your entity code for example has this attribute in Account
/// <summary>
/// Select a category to indicate whether the customer account is
standard or preferred.
/// </summary>
[Microsoft.Xrm.Sdk.AttributeLogicalNameAttribute("accountcategorycode")]
public Microsoft.Xrm.Sdk.OptionSetValue AccountCategoryCode
{
get
{
return
this.GetAttributeValue<Microsoft.Xrm.Sdk.OptionSetValue>("accountcategorycode");
}
set
{
this.OnPropertyChanging("AccountCategoryCode");
this.SetAttributeValue("accountcategorycode", value);
this.OnPropertyChanged("AccountCategoryCode");
}
}
Whereas mine does the following
/// <summary>
/// Drop-down list for selecting the category of the account.
/// </summary>
[Microsoft.Xrm.Sdk.AttributeLogicalNameAttribute("accountcategorycode")]
public System.Nullable<int> AccountCategoryCode
{
get
{
return
this.GetAttributeValue<System.Nullable<int>>("accountcategorycode");
}
set
{
this.SetAttributeValue<Microsoft.Xrm.Sdk.OptionSetValue>("AccountCategoryCode",
"accountcategorycode", value);
}
}
Your code was generated using CrmSvcUtil
[System.CodeDom.Compiler.GeneratedCodeAttribute("CrmSvcUtil",
"7.0.0000.3543")]
mine was [System.CodeDom.Compiler.GeneratedCodeAttribute("CrmSvcUtil",
"5.0.9688.1046")]
Does your fix then mean I need to recompile my Entities Classes using a
newer CrmSvcUtil?
…On 2 February 2017 at 09:26, Mauro Masucci ***@***.***> wrote:
I have the latest version, given one of the queries works and the other
doesn't I think I am more inclined to believe either the code I inherited
is flawed (likely) or the structure of the query is unexpected in the
QueryExpression handler in FakeXrmEasy. Either way, I suspect its the way
the Query in CreateBrokenTestQuery is constructed thats at the root of the
issue - thanks for your time on this though.
Mauro
On 2 February 2017 at 09:20, Jordi ***@***.***> wrote:
> Mmm runs fine locally, fails on appveyor, but probably related to
> referenced SDK version. Will double check again
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <#116 (comment)>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/ABl8KHITAOPX-dMJjDRP3TWGf9PwMUuCks5rYZ_zgaJpZM4L0El_>
> .
>
|
Wow! that looks like a bug in the crmsvcutil version you are using (which is highly likely, for instance, latest developer toolkit for 365 beta generates types which don't even build ). It is weird that one property should be retrieved as a Nullable in the getter but set as an OptionSetValue in the setter, isn't it? Looks like a bug in that version of crmsvcutil :) Issue #114 was sorted with this version: 5.0.9690.2165 Could you try with that one? |
Hi Mauro, did that work with crmsvcutil from latest 2011 SDK? |
Hi Mauro, closing this one. If you still are having issues please reopen it. |
When testing a method from a third party I get the error "specified cast is not valid" . In all honesty I am not sure if the problem is the query or the FakeXrmEasy test.
you can also read more here http://stackoverflow.com/questions/41978580/specified-cast-invalid
Included code below
The text was updated successfully, but these errors were encountered: