Search This Blog

Tuesday, July 19, 2011

CRM 2011: Plugin Registration Tool Error - Unable to load assembly !!


Recently I wrote a custom workflow to create a direct URL for a record within CRM & output the formatted URL, so that it can be used in email alerts to the users.
I faced this peculiar problem while I was registering the custom workflow assembly using the new Plugin Registration tool on my client server. I was unable to load my custom workflow assembly onto the plugin registration tool, whenever I choose to load the assembly on the tool, it gave me an error message:
Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'file:///C:\Plugin Registration Tool\PluginRegistration.exe' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)
   at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark)
   at System.Reflection.Assembly.LoadFrom(String assemblyFile, Evidence securityEvidence)
   at System.Activator.CreateInstanceFromInternal(String assemblyFile, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo)
   at System.AppDomain.CreateInstanceFrom(String assemblyFile, String typeName)
   at System.AppDomain.CreateInstanceFromAndUnwrap(String assemblyName, String typeName)
   at System.AppDomain.CreateInstanceFromAndUnwrap(String assemblyName, String typeName)
   at PluginRegistrationTool.AppDomainContext`1..ctor() in C:\pluginregistration\AssemblyReader.cs:line 41
   at PluginRegistrationTool.RegistrationHelper.RetrievePluginsFromAssembly(String pathToAssembly) in C:\pluginregistration\RegistrationHelper.cs:line 40
   at PluginRegistrationTool.PluginRegistrationForm.btnLoadAssembly_Click(Object sender, EventArgs e) in C:\pluginregistration\PluginRegistrationForm.cs:line 166
Inner Exception: System.NotSupportedException: An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default, so this load may be dangerous. If this load is not intended to sandbox the assembly, please enable the loadFromRemoteSources switch. See http://go.microsoft.com/fwlink/?LinkId=155569 for more information.
The reason I got this error was on the client server was that, the file was blocked on the server !!
Yes, now on some new server OS’s, this feature is enabled by default i.e. any external file that you deploy on the server will be blocked. You have to exclusively unblock the file & then use it to deploy!!
On suggestions from one of my peers, I unblocked the files (workflow assembly & all the files within the plugin registration tool) & then it worked like a charm!!  Everything went smooth later on!!
Unblocking the files: Right click on the file & if you see a unblock button on the properties dialog, then unblock it, else the file is already unblocked!!

I had a day wasted due to this small thing!! hope this helps someone !!

Thanks !!

Friday, July 15, 2011

CRM 2011 Custom workflow


Today I was working on custom workflow activities for CRM 2011. There are lot of changes,  the way you write custom workflow code w.r.t CRM 2011. First thing, you need VS2010 on your system to start working with your project.
Choose a workflow activity library project on your VS 2010.
Add Microsoft.Xrm.sdk & Microsoft.Xrm.sdk.Workflow in your references to your project, when you add this, your project needs to be in .Net framework v 4.0.
Now comes the actual change !
Your workflow activity class needs to derive from a class named: CodeActivity ( a class present in System.Activities, remember to add this assembly in your project references and remove system.workflow.Activities from your directives else this will cause ambiguous error).
We have a new service which can be used for tracing your workflow code or plugin code, called ITracing service.  You can use this service to trace through your code at runtime, you can write messages to it.
You can see how to use this service at the below link:
 
Now coming back to our custom workflow code, there are changes in the way you declare your input & output properties. In CRM 4.0 we used to declare a dependency property for an input or output properties, but in CRM 2011 it’s as shown below:
[Input("Input Value")]
        [Default("Hello")] // this default value will be used if nothing you have specified in your input
        public InArgument<string> ServerName { get; set; }

        [Output("Output value")]
        public OutArgument<string> OutputValue { get; set; }

For more on how to declare your inputs & outputs, refer below link:
After this the usual, strong name your assembly & go on to register your workflow assembly using the new Plugin registration Tool for CRM 2011.
List of changes between CRM 4.0 custom workflow & CRM 2011 Custom workflow code is well explained in the below link:

Hope with this information you can go ahead and build custom workflow activities for CRM 2011.
Good Luck!!

Friday, July 1, 2011

Microsoft Dynamics CRM 2011 – Filtered Lookups

In CRM 4.0, creating a “Filtered Lookup” was… well… kind of a pain. It required quite a bit of JavaScript on the Form in order for the filter to work correctly and if you needed to make additional modifications later on… !
In CRM 2011, the filtered lookups are simple, and you don’t have to know JavaScript to create them.
Example 1: I would like the “Out of the box” Primary Contact lookup on the Account, to ONLY show the contacts that are related to that particular Account. (Very Common request)
Step 1: Access the Account form (From your Solution or Main Customization Area)


Step 2: Open the Form and “Double Click” the Primary Contact field to access the Attribute Properties, then scroll to the bottom of the Field Properties window to adjust the properties of the Lookup!


In addition to being able to filter on Related Records, you can create Filtered views and have the Lookup use it as the default!
Example 2: In CRM, I have multiple “Account Types“. The Account Type field is a Picklist (Option Set) with the following choices: Hospital and Surgery Center. I would like to add an additional Lookup field on the Account form that looks up all Accounts with the “Account Type” of “Surgery Center“.
Step 1: Create the View that filters all Accounts where the Account Type = Surgery Center


Step 2: Create a new Lookup field on the Account Form. (Account to Account)
  1. Access the Account form (Customization Area)
  2. New to CRM 2011 – Create the Lookup directly from the Form!– At the bottom of the Account form, click “New” to create a new Field.

  3. Add your display name and choose the Field “Type” of Lookup.

  4. After the field has been created, add the field to the form using the new “Drag and Drop” functionality.

  5. Double click the field to open its properties

  6. Change the “Default View” to your new View!
As always, make sure to publish your changes to make them available to the users!

Orginal Post:
http://www.powerobjects.com/blog/2011/02/17/microsoft-dynamics-crm-2011-%E2%80%93-filtered-lookups/

Other posts:
http://crmconsultancy.wordpress.com/2011/05/17/filtered-lookups-in-crm-2011/