CrmException: Exception of type Microsoft.Crm.CrmException was thrown

Time for a new fix for a common problem.

When uploading a report you might get an error message. If this error message is:


NullReferenceException: Object reference not set to an instance of an object.]Microsoft.Crm.Reporting.SRSReport.convertDataSource(CrmContext context) +115Microsoft.Crm.Reporting.SRSReport..ctor(String name, String description, String xmlContent, String showin, String relatedentity, String category, CrmContext context, String filename, String origFilter) +136Microsoft.Crm.Reports.ReportCache.CreateSRSReport(String name, String description, String template, String showin, String relatedEntity, String category, String filename, Boolean isNewReport, String defaultFilter) +100Microsoft.Crm.Application.Platform.Report. InternalCreate(String xml) +629Microsoft.Crm.Application.Platform.Entity. Create() +109Microsoft.Crm.Application.Forms.AppForm.R aiseDataEvent(FormEventId eventId) +404Microsoft.Crm.Application.Forms.EndUserForm. Initialize(Entity entity) +56Microsoft.Crm.Application.Forms.EndUserForm. Execute(Entity entity) +13Microsoft.Crm.Web.Tools.ReportProperty. ReportPropertyPage.ConfigureForm() +202Microsoft.Crm.Application.Controls.AppPage. OnPreRender(EventArgs e) +30System.Web.UI.Control.PreRenderRecursiveInternal() +62System.Web.UI.Page.ProcessRequestMain() +1499

Then this post is not about your message. Please go to A Freaky Microsoft Dynamics CRM 3.0 Blog for a fix for this error.

Instead. If you get this message below, then read on for the solution:

[CrmException: Exception of type Microsoft.Crm.CrmException was thrown.] Microsoft.Crm.Application.Platform.Report. InternalCreate(String xml) +721 Microsoft.Crm.Application.Platform.Entity.Create() +109 Microsoft.Crm.Application.Forms.AppForm. RaiseDataEvent(FormEventId eventId) +408 Microsoft.Crm.Application.Forms.EndUserForm. Initialize(Entity entity) +57 Microsoft.Crm.Application.Forms.EndUserForm. Execute(Entity entity) +13 Microsoft.Crm.Web.Tools.ReportProperty. ReportPropertyPage.ConfigureForm() +202 Microsoft.Crm.Application.Controls.AppPage. OnPreRender(EventArgs e) +30 System.Web.UI.Control.PreRenderRecursiveInternal() +62 System.Web.UI.Page.ProcessRequestMain() +1499

I've been struggling with this error message myself and thanks to a posting on a newsgroup by LeeAC, I was able to upload my report. Here's the posting he made:

The issue lay with our RS permissions. In addition to failing to upload reports, we tried downloading them from CRM too. This gave us an NT permissions error. So, we opened up (localhost)/reports, navigated to the CRM datasource (typcially 'Organization_MSCRM), then properties, then security, and then added a user / group called NT AUTHORITY\NETWORK SERVICE, and gave them the permissions of CRM Publisher. After that it all worked fine.

Thanks

Lee



File or assembly name Microsoft.Crm.MetadataService, or one of its dependencies, was not found

Imagine.. You're writing a wonderful MS CRM 3.0 addon. After writing lines and lines of code, the time is there to run and test the addon. Instead of seeing your fantasic, state-of-the-art, rocket-science, cutting-edge addon, it is this message that arises:

Parser Error Message: File or assembly name Microsoft.Crm.MetadataService, or one of its dependencies, was not found.

Great.

Now how to solve this?

Well, Jonathan Randall has answered that question already in one of the newsgroups. Here's his posting:

The issue is caused because when you place your under application under the Microsoft CRM 3.0 web site, your application inherits the settings from the parent web site. Since the Microsoft CRM application has the two assemblies located in its own \bin folder, Microsoft CRM functions
correctly. However, your application does not have these assemblies in its \bin folder so as a result, the application fails to load. Here is some information that will correct the issue:

Symptoms: When a user attempts to access an ASP.NET web application that has its virtual directory located under the Microsoft CRM v3.0 Web Site in Internet Information Services (IIS), the following error will be displayed:

Server Error in '/' Application.
----------------------------------------------------------------------

Further detail on the error includes the following:

Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: File or assembly name Microsoft.Crm.MetadataService, or one of its dependencies, was not found.

Source Error:

Line 11: <add assembly="Microsoft.Crm.ManagedInterop, Version=3.0.5300.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
Line 12: <add assembly="Microsoft.Crm.MetadataHelper, Version=3.0.5300.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
Line 13: <add assembly="Microsoft.Crm.MetadataService, Version=3.0.5300.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
Line 14: <add assembly="Microsoft.Crm.NativeInteropProxy,
Version=3.0.5300.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
Line 15: <add assembly="Microsoft.Crm.ObjectModel, Version=3.0.5300.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

Source File: C:\Program Files\Microsoft CRM\CRMWeb\web.config
Line: 13

Assembly Load Trace: The following information can be helpful to determine why the assembly 'Microsoft.Crm.MetadataService' could not be loaded.

=== Pre-bind state information ===
LOG: DisplayName = Microsoft.Crm.MetadataService, Version=3.0.5300.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
(Fully-specified)
LOG: Appbase = file:///C:/Program Files/Microsoft CRM/CRMWeb/KBTest
LOG: Initial PrivatePath = bin
Calling assembly : (Unknown).
===

LOG: Publisher policy file is not found.
LOG: No redirect found in host configuration file (C:\WINNT\Microsoft.NET\Framework\v1.1.4322\aspnet.config).
LOG: Using machine configuration file from C:\WINNT\Microsoft.NET\Framework\v1.1.4322\config\machine.config.
LOG: Post-policy reference: Microsoft.Crm.MetadataService, Version=3.0.5300.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: Attempting download of new URL file:///C:/WINNT/Microsoft.NET/Framework/v1.1.4322/Temporary ASP.NET Files/kbtest/e724dea7/f72fefd/Microsoft.Crm.MetadataService.DLL.
LOG: Attempting download of new URL file:///C:/WINNT/Microsoft.NET/Framework/v1.1.4322/Temporary ASP.NET Files/kbtest/e724dea7/ f72fefd/ Microsoft.Crm.MetadataService/ Microsoft.Crm.MetadataService.DLL.
LOG: Attempting download of new URL file:///C:/Program Files/Microsoft CRM/CRMWeb/KBTest/bin/Microsoft.Crm.MetadataService.DLL.
LOG: Attempting download of new URL file:///C:/Program Files/Microsoft CRM/CRMWeb/KBTest/bin/Microsoft.Crm.MetadataService/ Microsoft.Crm.MetadataService.DLL.
LOG: Attempting download of new URL file:///C:/WINNT/Microsoft.NET/Framework/v1.1.4322/Temporary ASP.NET Files/kbtest/e724dea7/ f72fefd/Microsoft.Crm.MetadataService.EXE.
LOG: Attempting download of new URL file:///C:/WINNT/Microsoft.NET/Framework/v1.1.4322/Temporary ASP.NET Files/kbtest/ e724dea7/ f72fefd/ Microsoft.Crm.MetadataService/ Microsoft.Crm.MetadataService.EXE.
LOG: Attempting download of new URL file:///C:/Program Files/Microsoft CRM/CRMWeb/KBTest/bin/Microsoft.Crm.MetadataService.EXE.
LOG: Attempting download of new URL file:///C:/Program Files/Microsoft CRM/CRMWeb/KBTest/ bin/Microsoft.Crm.MetadataService/ Microsoft.Crm.MetadataService.EXE.

----------------------------------------------------------------------------
----
Version Information: Microsoft .NET Framework Version:1.1.4322.2300;
ASP.NET Version:1.1.4322.2300

Cause: Since the ASP.NET web application is located under the Microsoft CRM v3.0 web site, the application is inheriting settings that are part of the Microsoft CRM web site's web.config file. The Web.config file for a specific ASP.NET application is located in the root directory of the application and contains settings that apply to the Web application and inherit downward through all of the subdirectories in its branch. In this case, the Microsoft.Crm.MetadataService.dll and the Microsoft.Crm.Tools.ImportExportPublish.dll assemblies are being loaded by the Microsoft CRM web site. These two assemblies are located in the Microsoft CRM web application's \bin directory. Since these two assemblies are not part of the custom ASP.NET application, the Common Language Runtime begins a probing operation to locate the two assemblies. Since the assemblies are not installed into the Global Assembly Cache (GAC) or in the custom ASP.NET application's \bin folder, the exception is thrown.

Resolution:

There are four solutions to resolve the error. Each solution is detailed below.

Solution 1: Remove <add assemblies> entries in Microsoft CRM v3.0 web site's web config file.

In the <system.web> element of the web.config file, locate the <assemblies> node and remove the following entries:
<add assembly="Microsoft.Crm.MetadataService, Version=3.0.5300.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add assembly="Microsoft.Crm.Tools.ImportExportPublish, Version=3.0.5300.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

Solution 2: Install the Microsoft.Crm.MetadataService.dll and the Microsoft.Crm.Tools.ImportExportPublish.dll into the Global Assembly Cache (GAC).

The two assemblies that can be added to the Global Assembly Cache are located in the \bin directory under the Microsoft CRM web site's installation folder. A typical location would be C:\Program Files\Microsoft CRM\CRMWeb\bin.

Solution 3: Edit the ASP.NET web application's web config to remove the two Microsoft CRM assemblies.

Edit the ASP.NET application's web.config by adding the following entries to the <compilation> element that is nested in the <system.web> element of the file:

<system.web>
<compilation defaultLanguage="C#" debug="true">
<assemblies>
<remove assembly="Microsoft.Crm.MetadataService, Version=3.0.5300.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<remove assembly="Microsoft.Crm.Tools.ImportExportPublish, Version=3.0.5300.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</assemblies>
</compilation>
</system.web>

Solution 4: Locate the ASP.NET web application in a separate web site from the Microsoft CRM v3.0 web site.

Using this approach ensures that the application does not inherit any of the settings from the Microsoft CRM web site.

Jonathan Randall
Microsoft Online Support Engineer - MBS CRM Developer Support



Reporting Server not on MSCRM webserver?

If you have Reporting Server installed on a different server, then you should definately read this document:
http://www.microsoft.com/downloads/details.aspx?FamilyID=51bf9f20-bd00-4759-8378-b38eefda7b99&DisplayLang=en

This will help you to get Reporting to work again.

Happy reporting!



Callout debug: Access is Denied

I'm not sure if more people are experiencing the same thing, but at least I'd like to share this information with you.

After creating a debug build of a callout, I do copy the dll and pdb files to the \Microsoft CRM\Server\bin\assembly folder. Now I can normally debug the callout. But after modifying the code and copying the files again, then I cannot step into the code. CRM just steps over the whole callout.

When searching for a reason for this behaviour, I found a message in the event viewer. The message says:
-------------------------------------------------------------------------
Event Type: Error
Event Source: MSCRMCallout
Event Category: None
Event ID: 16912
Date: 6/22/2006
Time: 11:53:00 AM
User: N/A
Computer: CRMTest
Description:
Error: ISV code threw exception: assembly:
Microsoft.Crm.Sdk.FullSample.CalloutSample.dll; class:
Microsoft.Crm.Sdk.FullSample.Callouts.CalloutSample; entity: account,
event: precreate, exception: System.IO.FileLoadException: Access is
denied: 'Microsoft.Crm.Sdk.FullSample.CalloutSample.dll'.
File name: "Microsoft.Crm.Sdk.FullSample.CalloutSample.dll"
at System.Reflection.Assembly.nLoad(AssemblyName fileName, String
codeBase, Boolean isStringized, Evidence assemblySecurity, Boolean
throwOnFileNotFound, Assembly locationHint, StackCrawlMark& stackMark)
at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef,
Boolean stringized, Evidence assemblySecurity, StackCrawlMark&
stackMark)
at System.Reflection.Assembly.LoadFrom(String assemblyFile, Evidence
securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm
hashAlgorithm)
at System.Activator.CreateInstanceFrom(String assemblyFile, String
typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder,
Object[] args, CultureInfo culture, Object[] activationAttributes,
Evidence securityInfo)
at Microsoft.Crm.Callout.CalloutHost.PreCreate(CalloutUserContext
userContext, CalloutEntityContext entityContext, String& entityXml,
String& errorMessage)


=== Pre-bind state information ===
LOG: Where-ref bind. Location = C:\Program Files\Microsoft
CRM\server\bin\assembly\ Microsoft.Crm.Sdk.FullSample.CalloutSample.dll
LOG: Appbase = c:\windows\system32\inetsrvLOG: Initial PrivatePath = NULL
Calling assembly : (Unknown).
===


LOG: Policy not being applied to reference at this time (private,
custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Program Files/Microsoft
CRM /server/bin/assembly/ Microsoft.Crm.Sdk.FullSample.CalloutSample.dll.


For more information, see Help and Support Center at
http://go.microsoft.com/fwlink/events.asp.
-------------------------------------------------------------------------

Now how to solve this?
The resolution is quite simple. After copying the files to the assembly folder, you should give the user "Network Service" full permissions. The callout will work now and you will be able to debug the code.

Good luck!

Update: Ofcourse you can also give the user "Network Service" full rights on the bin folder of your project. You will not have to modify the file then again and again.



Add descriptions to relationship view

When working with relationships, you will find out that it would be useful to add the fields "Description 1" and "Description 2" to the associated view. This means that when you're in the account detail page and you view the associated relationships, that you will not only see "Party 1", "Role 1", "Role 2" and "Party 2". The description fields are useful to store additional information, but it would be really useful if you can show this data without the need of a double click on the record.

So Ronald. How do we do this?

Usually I'd say: "go to the settings, customization, relationships, forms and views and then modify the associated view. Now there's only one small problem. There is no forms and views for the relationships entities. There are 2 entities for relationships: Customer Relationship and Opportunity Relationship. In this article I'm using only the Customer Relationship.

Well, if the link is not there, then why not create a link to that specific page? This is the solution to this problem. The link to any view modification page is:
http://localhost:5555/tools/vieweditor/viewManager.aspx?id={guid}. We only need the guid of the view which is used for the associated relationship view. We can find this id by following the next steps:

- find out the guid of any account (open an account and press CTRL+N)
- go to this url (replace the guid with your account guid):
http://localhost:5555/sfa/accts/areas.aspx?oId={60548D20-B7F5-DA11-AAE6-0003FF2689B7}&oType=1&security=4294500000&tabSet=areaRelationships
- view the source of the page
- search for "viewid"

The value of this attribute is the view guid which you should use in the url http://localhost:5555/tools/vieweditor/viewManager.aspx?id={guid}. Ofcourse you'll need to modify the port number if you have used another port.

Now you can modify the view as desired, for instance add the fields "description 1" and "description 2" to the view. After saving the modifications, you will need to publish the entity "Customer Relationship". And you're done!

Update September 4th 2007:
The article describes how to do this for the customerrelationship. If you need to do this for the opportunity relationship, then follow this url:
http://localhost:5555/sfa/opps/areas.aspx?oId={60548D20-B7F5-DA11-AAE6-0003FF2689B7}&oType=3&security=852407&tabSet=areaRelationship



10.000 Visitors

After 10.5 months of blogging, 50 posts after the "hello world" posting, this blog has been grown to what I hoped it would be. A place to find interesting information regarding MS CRM with a personal touch. Obviously this is being appreciated by the CRM community because as of this day I have had over 10.000 visitors!

Thanks to all of you!