Failed to create receiver object from assembly

I added a new Feature with EventReceiver to my Solution. While trying to activate this WebApplication feature I got the errormessage, that Sharepoint “Failed to create receiver object from assembly“.

What caused the error?

The SharePoint Timer service cached the old DLL. After re-deploying my solution the cache wasn’t cleared. The reference to my EventReveiver wasn’t found in the old DLL.

What’s the solution?

Restart the SharePoint Timer Service on all servers in the farm.

A proxy type with the name account has been defined by another assembly

I wanted to display different entities from Dynamics CRM in my SharePoint site using the CRM webservice. My code worked while I only had one solution, connection to CRM, deployed on my server. When I wrote a second application that is also using the webservice, I got the following error:
“A proxy type with the name account has been defined by another assembly.”

Here’s the solution. You just have to add a new ProxyTypesBehavior:


ClientCredentials credentials = new ClientCredentials();
credentials.Windows.ClientCredential = new NetworkCredential(username, password, domain);
credentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
IServiceConfiguration<IOrganizationService> orgConfigInfo = ServiceConfigurationFactory.CreateConfiguration<IOrganizationService>(new Uri(@"[...]/XRMServices/2011/Organization.svc"));
OrganizationServiceProxy client = new OrganizationServiceProxy(orgConfigInfo, credentials);
client.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior(Assembly.GetExecutingAssembly()));

Create records in CRM 2011 using the CRM Web Service

When I began to create records in CRM using the webservice, I started with records containing simple text fields. And there was no problem. The following method creates a new contact entity in CRM:

public static Guid createCandidate(OrganizationServiceClient serviceProxy, string firstname, string lastname, string email)
{

Entity application = new Entity() { LogicalName = "contact" };

// Set Contact Properties
AttributeCollection Attributes = new AttributeCollection();

Attributes.Add(new KeyValuePair<string, object>("firstname", firstname));
Attributes.Add(new KeyValuePair<string, object>("lastname", lastname));
Attributes.Add(new KeyValuePair<string, object>("emailaddress2", email));

application.Attributes = Attributes;

//Create Contact
Guid appGuid = serviceProxy.Create(application);

return appGuid;
}

But then I also wanted to fill OptionSet fields (DropDowns) and ReferenceEntity fields (LookUp). But the Webservice always threw an exception:

Die InnerException-Nachricht war “Der Typ “*.OptionSetValue” mit dem Datenvertragsnamen “OptionSetValue:http://schemas.microsoft.com/xrm/2011/Contracts” wurde nicht erwartet. Fügen Sie alle statisch nicht bekannten Typen der Liste der bekannten Typen hinzu. Verwenden Sie dazu z. B. das Attribut “KnownTypeAttribute”, oder fügen Sie die Typen der an DataContractSerializer übergebenen Liste von bekannten Typen hinzu.”.

After a long time I found the solution here:

1. Create a new class in your project with name you prefer.

2. Keep the namespace of this class similar to your Reference.cs (This is important so do not forget it)

3. Now create partial classes as below

[System.Runtime.Serialization.KnownTypeAttribute(typeof(OptionSetValue))]
[System.Runtime.Serialization.KnownTypeAttribute(typeof(EntityReference))]
public partial class Entity { }

[System.Runtime.Serialization.KnownTypeAttribute(typeof(OptionSetValue))]
[System.Runtime.Serialization.KnownTypeAttribute(typeof(EntityReference))]
public partial class EntityCollection { }

[System.Runtime.Serialization.KnownTypeAttribute(typeof(EntityReference))]
[System.Runtime.Serialization.KnownTypeAttribute(typeof(PrincipalAccess))]
[System.Runtime.Serialization.KnownTypeAttribute(typeof(OptionSetValue))]
public partial class OrganizationRequest { }

4. Now go to your actual code, and for lookup field use like this:

Attributes.Add(new KeyValuePair<string,object>("parentcustomerid", new EntityReference() {Id = t.Id, LogicalName= t.LogicalName}));

5. Build the solution

Now everything should work as expectedt!

How to get the assembly public key token using Visual Studio 2012

If you want to register a WorkflowActivity as safe in Webconfig you need the public key token from the dll.

<authorizedTypes>

<authorizedType Assembly=”Testprojekt, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b04480df764d9b77″ Namespace=”Testprojekt” TypeName=”*” Authorized=”True” />
</authorizedTypes>

1. On your SharePoint Server in Windows starmenue, open the “Developer Command Promt for VS2012”

2. In commandprompt type “sn -T *path to your dll*”

publicKeyToken

Disable Scrollbar in Page Viewer WebPart

Use a Content Editor WebPart instead with the following HTML:

<iframe name="Iframe" src="yourURL" scrolling="no"
FRAMEBORDER="0" style="width:100%; border:0;  height:100%; overflow:hidden;">
</iframe>

1. Add a Content Editor WebPart to the Page
2. Click “Edit WebPart”
3. In Ribbon Tab “Format Text” click “Edit Source”
4. Copy and paste the code above into the “Edit Source”-window and replace “yourURL” with the URL you want to be displayed in the WebPart. Set the size of the WebPart to your needs.

Get Public Key Token for Assembly in Visual Studio

In Visual Studio Click Tools > External Tools > Add and enter the following:

GetPublicKey

Command: C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\sn.exe
Arguments: -T $(TargetPath)

Note: The path for the command can be different depending on you Visual Studio version. Just check in your file directory where the sn.exe is (might be v6.0A instead of v7.0A).

Error occurred in deployment step ‘Install app for SharePoint’: The provided App differs from another App with the same version and product ID

Problem:
Cannot deploy a solution and getting the error: Error occurred in deployment step ‘Install app for SharePoint’: The provided App differs from another App with the same version and product ID.

Solution:
Open the AppManifest.xml in code view and generate a new guid for the app -> Change value of ProductID.

Add URLs to Hyperlinks-List via XML or C#

ListInstance Elements.xml

<Data>
   <Rows>
      <Row>
         <Field Name=”URL”>www.google.de, Google</Field>
      </Row>
   </Rows>
</Data>

Note:

  • Webrelative URLs are not working here, only full or serverrelativ URLs are possible!
  • Don’t forget the space after the comma
  • C# – via Feature EventReceiver

    using (SPWeb web = properties.Feature.Parent as SPWeb)
    
    {
    SPList list = web.Lists["Links"];
    SPListItem newItem = list.Items.Add();
    string name = “Google”;
    string url = “www.google.de”
    newItem["URL"] = url + “, ” + name;
    newItem.Update();
    }
    

    Note:

  • All types of URLs are possible, for example you can set up the URL using web.ServerRelativeUrl.