CRM 2013: Email Router: The message exceeds maximum supported size

If your email router does not process any emails but your inbox from Email Provider works just fine!?! Check event logs where Email Router is installed. You might see many repeated errors similar to mentioned error here below:

#27938 – An error occurred while checking for email messages to process in mailbox service@gmail.com. Microsoft.Crm.Tools.Email.Providers.EmailException: Error: The message exceeds the maximum supported size.
at Microsoft.Crm.Tools.Email.Providers.ExchangeWSConnector.LogEwsResponseErrorWarning(String message, ResponseClassType responseClassType)
at Microsoft.Crm.Tools.Email.Providers.ExchangeWSConnector.RetrieveMessage(ArrayList ids, Int32 index, ServiceLogger serviceLogger)
at Microsoft.Crm.Tools.Email.Providers.ExchangePollingMailboxProvider.RetrieveNextMessageInternal()
at Microsoft.Crm.Tools.Email.Providers.CrmPollingMailboxProvider.RetrieveNextMessage()
at Microsoft.Crm.Tools.Email.Providers.CrmPollingMailboxProvider.Run()

Check your inbox for the emails with attachments. Find emails with more than expected attachments size per email, take backup (if required) and delete them. Your Email Router should work just fine once this is done!

In my case an email with 100+ MB attachment size was creating an issue.

Happy Troubleshooting!!

Advertisements

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

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 overriden.
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:
http://blogs.msdn.com/b/shawnfa/archive/2009/11/12/differences-between-the-security-rule-sets.aspx
http://blogs.msdn.com/b/shawnfa/archive/2009/11/03/transparency-101-basic-transparency-rules.aspx

AD Change Password C#: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

Hi,

I was trying to Reset/Change Password for Active Directory through C# code behind. And I encountered with the same error:Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

Access Denied errors that are reported by scripts and applications that access WMI namespaces and data generally fall into three categories.

Possible Reasons are:
The user does not have remote access to the computer through DCOM. Typically, DCOM errors occur when connecting to a remote computer with a different operating system versions.

Solution:
Give the user Remote Launch and Remote Activation permissions in dcomcnfg.

  • Right-click My Computer-> Properties Under COM Security, click “Edit Limits” for both sections.
  • Give the user you want remote access, remote launch, and remote activation.
  • Go to DCOM Config, find “Windows Management Instrumentation”, and give the user you want Remote Launch and Remote Activation.

For more information, see Connecting Between Different Operating Systems

References: http://msdn.microsoft.com/en-us/library/windows/desktop/aa394603(v=vs.85).aspx

ADFS 2.0: “Could not load file or assembly ‘Microsoft.IdentityServer.Compression’ or one of its dependencies. An attempt was made to load a program with an incorrect format”

If you have come to this blog searching for the error mentioned above then probably you’re doing some modifications to ADFS 2.0 site.

Following would be the symptoms that you have done so far:

  • You have opened adfs\ls website as Website project in Visual Studio.
  • If the project type is Website, you probably had a message from Visual Studio to upgrade for the .Net v4.0.
  • You have created a new project Empty Web Application and imported adfs\ls website content to the project.
  • You are modifying this site/application on local machine and not on Windows Server where ADFS is installed.

Follow these steps to successfully start modifying ADFS site:

  1. Install Visual Studio 2010 on Windows Server where ADFS is installed and configured.
  2. Create an Empty Web Application
  3. Import all the files from adfs\ls directory to the Web Application. (generally, you can find it on c:\inetpub\adfs\ls)
  4. Right click on the project in Solution Explorer and click on “Convert to Web Application”.
  5. You’re ready to go!

You do not need to add reference of any files to this web application. Just Build and Publish the site to the same directory where adfs is installed.

Microsoft.IdentityServer.Compression and other required files will be referenced from GAC as you are developing the project on the server itself.

Happy Programming! 🙂

CRM 2011: Could not load type ‘System.ServiceModel.Activation.HttpModule’

When you try to access the Microsoft Dynamics CRM 2011 Web client, you get the following error.

Could not load type ‘System.ServiceModel.Activation.HttpModule’ from assembly ‘System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

This error can occur when there are multiple versions of the .NET Framework on the computer that is running IIS, and IIS was installed after .NET Framework 4.0 or before the Service Model in Windows Communication Foundation was registered.

Resolution:

1. Go to computer where CRM 2011 is installed and open command prompt.

2. Change the directory to C:\windows\Microsoft.NET\Framework64\v4.0.30319

3. Type the following command-     aspnet_regiis.exe -iru

4. Reset the IIS by iisreset command.

Done! 🙂

CRM 2011, C# Error: The given key was not found in the dictionary.

Many a times unexpected things happen while programming. And in case of Dynamics CRM it “does” happen. Similar issue happened with me today. The subject of the blog post was the annoying error I wanted to get rid off.

The given key was not found in the dictionary.

The first thing comes into the programmers’ mind is that there is nothing in this error and they just need to cross check with the attribute logical names they have used in coding.

To solve this I cross checked each and every attributes from Dynamics CRM and my C# code and not for single but 3-4 times. Finally, I got the idea that all my code is working absolutely correct with nothing wrong in it.

The real issue was not my code but a plugin/workflow activity developed by some other programmer which was registered on the same entity which I was working on. I disabled the step of the workflow activity and the program worked like a charm.

Check for the Plugins or Workflow Activities registered on the same entity to drill down with your issue.

Happy programming!!

CRM 2011 Web Page Error: The server was unable to process the request due to an internal error either from ServiceBehaviorAttribute or from the configuration behavior

I was working with a web application which connects to the CRM 2011 Organization Web Service. While developing it through Visual Studio the application was working like a charm! And as soon as I published it to the IIS 7, it began showing me following error and stack trace.

The server was unable to process the request due to an internal error.  For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ServiceModel.FaultException: The server was unable to process the request due to an internal error.  For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs.

Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[FaultException: The server was unable to process the request due to an internal error.  For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs.]
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +4767763
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) +1725
Microsoft.Xrm.Sdk.IOrganizationService.Execute(OrganizationRequest request) +0
Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy.ExecuteCore(OrganizationRequest request) +892
xxxxxxxTool.xxxxxContacts.Page_Load(Object sender, EventArgs e) in C:\Users\Administrator\Desktop\xxxxxxxTool\xxxxxxxTool\xxxxxContacts.aspx.cs:173
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +25
System.Web.UI.Control.LoadRecursive() +71
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3048

Looking at the error details, I was not sure what was wrong with a piece of code I wrote! I didn’t even used .Net Framework 3.0 SDK?!? With some findings on net I found some attributes for ServiceBehaviors that should be added to web.config shown as below.

<behaviors>
  <serviceBehaviors>
    <behavior name="SecurityTokenServiceBehavior">
      <!--The serviceMetadata behavior allows one to enable metadata (endpoints, bindings, services) publishing.
This configuration enables publishing of such data over HTTP GET.
This does not include metadata about the STS itself such as Claim Types, Keys and other elements to establish a trust.-->
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="true" />
      <!--Default WCF throttling limits are too low-->
      <serviceThrottling maxConcurrentCalls="65536" maxConcurrentSessions="65536" maxConcurrentInstances="65536" />
    </behavior>
  </serviceBehaviors>
</behaviors>

This was not sufficient as error was still there! I thought I had a problem with my IIS, I reinstalled it! Still there is same error. I checked to the other PCs but the issue persisted. Finally I got the solution by some R&D on IIS part.

Through MSDN I found that the Applications made for CRM or using any web services of CRM 2011 will need the same configuration as CRM App Pool. If the application will not consume more, you can use the same App Pool that CRM 2011 web application uses.

The Similar AppPool created for the application must be running on Classic mode and Identity should be Network Service.

And some authentication settings to the web application developed for the CRM will help the application run without issues on IIS 7. Follow this image for Authentication to web application to set.

Authentication Settings

Authentication Settings

Anonymous Authentication should be Disabled. CRM needs Windows Authentication, Enable it. And there is no need to have a Forms Authentication, Disable it.

After all these settings your application should work as expected.

Happy Troubleshooting!!

Microsoft Ebooks huge collection… Free free free!!

Huge collection of Free Microsoft eBooks for you, including: Office, Office 365, SharePoint, SQL Server, System Center, Visual Studio, Web Development, Windows, Windows Azure, and Windows Server

http://blogs.msdn.com/b/mssmallbiz/archive/2013/06/18/huge-collection-of-free-microsoft-ebooks-for-you-including-office-office-365-sharepoint-sql-server-system-center-visual-studio-web-development-windows-windows-azure-and-windows-server.aspx

Large collection of Free Microsoft eBooks for you, including: SharePoint, Visual Studio, Windows Phone, Windows 8, Office 365, Office 2010, SQL Server 2012, Azure, and more.

http://blogs.msdn.com/b/mssmallbiz/archive/2012/07/27/large-collection-of-free-microsoft-ebooks-for-you-including-sharepoint-visual-studio-windows-phone-windows-8-office-365-office-2010-sql-server-2012-azure-and-more.aspx

CRM 2011 C#: Get List of User Security Roles

Hello guys,

Use below method to get the list of Security Roles that the logged in user belongs to.

A WhoAmIRequest and WhoAmIResponse messages are used to get the current logged in user’s GUID. I have used a FetchXml technique to get the Roles list. The primary entity role is used and a related entity systemuserroles is used to relate the records and a condition is given on the same entity to find the logged in user’s related records.

private List<string> RetrieveSecurityRoles()
{
	List<string> rolesList = new List<string>();
	string fetchXml = @"<fetch mapping=""logical"" count=""50"" version=""1.0"">
							<entity name=""role"">
								<attribute name=""name"" />
								<link-entity name=""systemuserroles"" from=""roleid"" to=""roleid"">
									<filter>
										<condition attribute=""systemuserid"" operator=""eq"" value=""{0}"" />
									</filter>
								</link-entity>
							</entity>
						</fetch>";
	fetchXml = string.Format(fetchXml, ((WhoAmIResponse)oHelper._crmservice.Execute(new WhoAmIRequest())).UserId);
	var result = oHelper._crmservice.RetrieveMultiple(new FetchExpression(fetchXml));

	foreach (var item in result.Entities)
	{
		rolesList.Add(item.Attributes["name"].ToString());
	}

	return rolesList;
}

Hope this helps!!

SharePoint: An exception occurred when trying to issue security token. This is often caused by an incorrect address or SOAP action.

I experienced this error while integrating SharePoint with CRM 2011. Below is the error message:

An exception occurred when trying to issue security token: There was no endpoint listening at http://localhost:32843/SecurityTokenServiceApplication/securitytoken.svc/actas that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.

This error can occur if you have not started SharePoint services.

Solution:

Make sure you have started required SharePoint Server Services… Go to SharePoint Site and click on Manage Services on Server. You will be presented with a list of SharePoint services. Start the required services if any service is Stopped.

Sharepoint Manage Services on Server

SharePoint Manage Services on Server