Experiences on CRM, .Net and DHTML


  • Join Us on Facebook!
  • Follow Us on Twitter!
  • LinkedIn
  • Subcribe to Our RSS Feed

C#: Security accessibility of the overriding method must match the security accessibility of the method being overridden

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.

[assembly: SecurityRules(SecurityRuleSet.Level1)] 
[assembly: AllowPartiallyTrustedCallers]

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:

CRM Dev Lab Series - Dev VM and Connectivity(Hyper-V)

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. 


  • Create & Configure Virtual Switches
    • Screen - 1 Open Hyper-V Manager on the Host O/S. In my case it is Windows 8.1.

      In this post, I am going to use the VM named CRM 2013.  Please notice that it is in Off state. We are going to make few Hardware related changes to this VM hence it needs to be in Off state. From the
      screenshot below you can see in Actions pane on right side we have Virtual Switch Manager. Click on it.

    • Screen - 2 Virtual Switch Manager appears. Select External and Click on Create Virtual Switch.

    • Screen - 3 A dialog window will appear, select a Network card which is connected to Internet/Intranet and Click Apply. Please note that if your Network is not DHCP enabled or if your
      Network restricts allocation of IPs then you will have to get an IP address which you can use later on.

    • Screen - 4 & 5 You will get a warning regarding disruption of network. Click on Apply when you are ready and are able to afford being disconnected from the network for a

    • Screen - 6 & 7 Now repeat step 4 and 5, but instead of External this time select Internal. And click on Apply. This time there will not be any network disruptions.


    • 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) 

  • Configure Network Adapters for the VM
    • Screen - 9 In Hyper-V Manager, Select the VM you want to connect with and Right click > Settings.

    • Screen - 10 Settings Dialog will appear, Select Add Hardware if it is not selected by default.

    • Screen - 11 Select Network Adapter and Click on Add.

    • Screen - 12 & 13 A Network Adapter will be added to the Hardware. Here you can see a list of available Virtual Switches. Select External and Click on Apply.


    • Screen - 14 Similarly, Add one more Network Adapter to the VM. This time Select Internal from Available Virtual Switches and Click on Apply.

    • Screen - 15 Right Click on the VM and Click on Start.

    • Screen - 16 Once the VM starts, wait for few minutes.

    • Screen - 17 Observe Networking Tab. It will show some random IPs initially.

    • Screen - 18 Right Click on the VM and Select Connect. Log in to your Guest VM and Navigate to Control Panel\Network and Internet\Network Connections. Here you will see two connections named: Ethernet and Ethernet 2. Rename Ethernet to Internet and Ethernet 2 to Domain.

    • Screen - 19 Select Domain 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.

    • 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.


  • Verifying connections and few tricks
    • Now you have all the necessary configurations done. Here are few things you might want to do additionally. First let's check few things to be sure we have completed all the configurations correctly.

    • From your Host machine, open a command prompt and type in ping Check if you are getting responses.

    • From your Guest VM, open a command prompt and type in ping Check if you are getting responses.

    • If you have installed CRM on port 5555, open up Internet Explorer and type in You will be presented with a credential prompt, use the credentials you were using in the Guest VM and you should be able to access CRM. If you are facing challenges, please make sure in Guest VM Firewall settings allow traffic on port 5555.

    • To make thing easier you might want to add a host entry. Navigate to System32\Drivers\ETC. Open hosts file and the following at the last line: crmhq. Once this entry is added to the host file, you can access CRM server by using this URL: http://crmhq:5555.


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

  • Hyper-V Virtual Switch Overview

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

Getting Total Record Count in CRM 2011

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;

Configuring host name with a wildcard SSL certificate for IIS

This is a long due post almost a year or more. I was working with an ADFS 2.0 setup on a single box (Development only) and was facing challenges with installation and configuration of IIS Host Headers which will allow me to complete required steps for ADFS 2.0 setup for Microsoft Dynamics CRM 2011. When you are configuring a wildcard SSL certificate (*.crmxpress.com) in IIS snap-in you will notice that Host name is disabled when you try to configure site binding. After a little research, I found an article that described the steps to enable the host name.

  1. Open Microsoft Management Console (MMC) by Start -> Run -> Type MMC -< Enter.
  2. File -> Add/Remove Snap-ins.
  3. From the list of Snap-ins, select Certificates and add it to Console Root.
  4. Select appropriate option, in my case, it was My user account but you can select Service account or Computer account based on your configuration.
  5. Once the Snap-in has been added locate the certificate and right click-> Properties.
  6. In General tab, you will see Friendly name field. Enter *.<<yourdomainname>>.com or appropriate value based on your certificate.
  7. Click on Ok and now you can configure the site bindings and configure the host header.