Every now and then we run into a situation where we think if I knew a little bit more about this technology, it would have saved me a LOT of time.
This happened to me few days back. I was working with a large chunk of JSON out of which I needed a little piece sent back to server and it took me some time to figure out a way to do it.
I used delete keyword and got rid of extra properties from the object graph before I converted it to JSON. Here is a quick sample I whipped up for this post.
PS: Due to certain restrictions the following code snippet is missing appropriate closing script tags. Kindly add them if you copy the code to use it somewhere. -->
I was porting a .Net 2.0 assembly to .Net 4.0 plugin assembly and faced this particular challenge.
The project had a test app(A WinForm app) and it worked fine on the desktop but when I deployed the logic on server to run as a plugin it gave the following error
xyz..GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext) Security accessibility of the overriding method must match the security accessibility of the method being overridden.
Just notice, the spelling for "overridden" is also not correct. But this is what .Net framework threw.
After some research I found that this behavior is “By Design” i.e. as per security transparency model defined in .Net v4.0. It basically has two models:
1. Level1 (High Level) for v2.0
2. Level2 for v4.0
Here is a a list of critical operations:
1. Call native code
2. Contain unverifiable code
3. Call critical code
4. Perform security asserts
5. Satisfy link demands
6. Derive from non-transparent types
7. Override security critical virtuals
And only full trust code can be security critical.
Hence an overridden member should have the same security accessibility (Critical, Safe Critical or Transparent).
To resolve this error take the following step:
Go to the AssemblyInfo.cs class to your project and add following attributes to it. And this should resolve the exception.
I believe it might be helpful to many as there are lot of Dynamics CRM implementations being upgraded.
Reference links to the differences between both and transparency rules:
I have been thinking to write this post for a while now. Think, 2 or more years. Somehow I could never just start it and was holding back to start a new journey with this blog.
Anyway, I would not like to delay this blog anymore. Let's begin with one of the basic challenges that most of the developers encounter when they start working with
Microsoft Dynamics CRM (From now on let's call it CRM) and that is: How to access the VM from your host and how to provide Internet/external network access to Guest (CRM VM).
For this post, I am making following assumptions and will also expect certain level of familiarity with Hyper-V Configuration options.
Additionally, you are using this for a Development only scenario and you are using Microsoft Windows 8 or Microsoft Windows 8.1 and Hyper-V.
I will also assume you already have created a vanilla CRM VM and it is up and running.
What we just did will create two Hyper-V Virtual Ethernet Adapters behind the scenes. To verify, you can Navigate to Control Panel\Network and Internet\Network Connections
You can right click on Network Icon (Wireless or Ethernet) > Open Network and Sharing Center > Change Adapter Settings
Remember we will be visiting these Network adapters a lot throughout this post.
The Adapters name you will see, based on Input you have provided in Step 4 to 7.
are: vEthernet (Internal) and vEthernet (External).
Screen - 8 Select vEthernet (Internal) Connection and Right Click on it. Click on Properties. From the Properties Window,
Double click on Internet Protocol Version 4(TCP/IPV4) then fill in the details as shown below.
We don’t have to configure anything for vEthernet(External) if it is connecting to a network which will automatically assign an IP. If it doesn’t happen you can acquire an appropriate IP and change it as we changed it for vEthernet(Internal)
Restart Host OS. Remember this step is necessary as without this step I have never seen Internet/External connection working properly inside VM.
Screen - 20 Start Hyper-V Manager. Select the VM and Observe Networking tab. You will see both the IPs are changed now.
Phew... I think this is a longest blog post I have ever wrote. Anyways, I am hoping that this will come handy to someone, someday and yes standard disclaimer is applied: If you end up with a bricked VM then please by all means try from scratch.
Update: 22nd April 2014
Added Reference Links
I PS: This post was originally published at: http://blogs.msdn.com/b/chinmay/archive/2014/04/02/crm-dev-lab-series-dev-vm-and-connectivity-hyper-v.aspx
Many a times I run into this particular situation and somehow I observe people still retrieve all records and then loop through to get the total number of records. It is very easy to get it using the code given below.
QueryExpression query = new QueryExpression("account");
query.ColumnSet = new ColumnSet(true);
query.Criteria.AddCondition(new ConditionExpression("accountid", ConditionOperator.NotNull));
query.PageInfo = new PagingInfo();
query.PageInfo.Count = 1;
query.PageInfo.PageNumber = 1;
query.PageInfo.ReturnTotalRecordCount = true;
EntityCollection result = this.ServiceProxy.RetrieveMultiple(query);
int totalRecords = result.TotalRecordCount;