Plug-in can't find referenced assembly - Deploying plug-in with SDK to DB
-
Monday, February 11, 2013 11:41 AM
Hello everyone,
I'm creating a plugin that will utilizes an assembly. I've been having trouble getting it to work though.
[I can't add images so please forgive my "all text" post]
I have a solution in visual studio 2010 Professional and i'm using the SDK for Dynamics CRM 2011. My solution includes a 'PluginPackage' project for deploying my plug-in and a 'plugins' solution for a plugin. The plugin project has a "PdfSharp.dll" Reference.
The plugin on it's own (without the referenced assembly) works fine. But when i reference the assembly .dll in my project and deploy it, i get this error in run-time:
Could not load file or assembly 'PdfSharp, Version=1.32.2608.0, Culture=neutral, PublicKeyToken=f94615aa0424f9eb' or one of its dependencies. The system cannot find the file specified.
I know that the SDK deploys the plug-in to the database. I pasted the 'PdfSharp.dll' file to:
- C:\Program Files\Microsoft Dynamics CRM\Server\bin
- C:\Program Files\Microsoft Dynamics CRM\Server\bin\assembly
- C:\Windows\assembly -> (GAC)
The assembly filename, version and public key token are all the same as in the error message.
Any info on how to solve this without using ILMerge would be very much appreciated.
Also
I checked the references that PdfSharp.dll has:
- System
- System.Data
- System.Drawing
- System.Windows.Forms
- System.XML
Which are all in the GAC.
Thanks,
Selvihan Batırbek
- Edited by Selvihan Batırbek Monday, February 11, 2013 11:52 AM Added info
All Replies
-
Monday, February 11, 2013 12:23 PM
Hi Selvihan,
Have you tried registering the dll to GAC instead of copying it to the GAC?
Check out the following link.
http://msdn.microsoft.com/en-us/library/ex0ss12c(v=vs.80).aspx
Thanks,
Thank you, DT
-
Monday, February 11, 2013 1:08 PM
Hello DT,
I haven't been able to use gacutil.exe because it's not installed on the server machine for some reason. I'm reluctant to install framework related material on the server because it's the company server and not my own.
Is there any difference between drag&drop and using gacutil.exe? Because i tried using gacutil.exe, and when I found it wasn't on the server, I checked if dragging and dropping would suffice and it thought it would: http://msdn.microsoft.com/en-us/library/aa559668%28v=bts.20%29.aspx
I also found this article related to drag-drop vs gacutil.exe : http://stackoverflow.com/questions/10783818/drag-and-drop-dll-to-assembly-folder- Edited by Selvihan Batırbek Monday, February 11, 2013 1:09 PM
-
Monday, February 11, 2013 3:04 PMModerator
It shouldn't matter how the assembly gets into the GAC (drag & drop via the explorer shell extension, or gacutil), but make sure you've used the correct GAC - assemblies built with .Net Framework v3.5 or lower go in %windir%\assembly, whereas those built with .Net Framework v4.0 or higher go in %windir%\Microsoft.Net\assembly.
You may also need to retstart the process your plugin runs under - i.e. recycle the CrmAppPool application pool if it's a synchronous plugin, or restart the Crm Async Service if it's an asynchronous plugin
Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk
-
Monday, February 11, 2013 11:20 PM
1. Copy the dll to CRMWeb\bin
2. GAC it using GACUTIL tool
Hope this helps. Amar
CRM Forum Guidance on how to Help Us Help You
- Edited by Amarsen Reddy Monday, February 11, 2013 11:23 PM
-
Tuesday, February 12, 2013 7:41 AM
Hi Selvihan,
Is there a reason why you don't want the plugin registered on disk instead of in the database? One thought is to try to register it on disk just to se if there is something else that gives the error.
Regards
Rickard Norström Developer CRM-Konsulterna
http://www.crmkonsulterna.se
Swedish Dynamics CRM Forum: http://www.crmforum.se
My Blog: http://rickardnorstrom.blogspot.se -
Tuesday, February 12, 2013 9:23 AM
Hello Rickard & Everyone;
After some time the error I was receiving before had disappeared. Meaning I was not getting the Assembly not found error. But now when I reference some objects in the assembly, i get an Object Null Reference Exception error.
PdfDocument doc = new PdfDocument();
tracingService.Trace("Doc created. Now creating page");
PdfPage page = doc.AddPage();
tracingService.Trace("Page created. Now creating gfx");
XGraphics.FromPdfPage(page); //Code Fails HereI've used this plugin before and this is the default initialization. I'm positive this should not fail. So I'm assuming it has to do with the assembly reference again somehow. But I have no clue how..
I deleted all the assembly files i frantically copied all over my system. My plug-in is synchronus, I'm guessing one of the running services have a timer which updates assembly references, or something..
To try and solve the problem I tried to deploy my plug-in on disk.
After compiling and manually copying the plugin dll to the server/bin/assembly folder and clicking deploy in visual studio
I recieve this error (Because sandboxed plug-ins can only be deployed to database):
Error 1 Error registering plugins and/or workflows. The given plugin assembly source type is not supported for isolated plugin assemblies. C:\Program Files (x86)\MSBuild\Microsoft\CRM\Microsoft.CrmDeveloperTools.CrmClient.targets 176 4 testpackage
If i change the isolation mode to "None" instead of "Sandbox":
Error 1 Error registering plugins and/or workflows. Action failed for assembly 'testpackage.testplugin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=364579f10afc9ddd': Assembly must be registered in isolation. C:\Program Files (x86)\MSBuild\Microsoft\CRM\Microsoft.CrmDeveloperTools.CrmClient.targets 176 4 testpackage
I even tried ILMerge to no avail.. I'm starting to think I have no way of referencing an assembly in a plugin :(
If you kind people have any other suggestions, please share.
Thanks,
Selvihan Batırbek
- Edited by Selvihan Batırbek Tuesday, February 12, 2013 10:39 AM
-
Tuesday, February 12, 2013 10:31 AM
try { XGraphics.FromPdfPage(page); } catch (Exception ex) { throw new InvalidPluginExecutionException(ex.InnerException.Message,ex); }Inner Exception Throws:
System.NullReferenceException: Object reference not set to an instance of an object
If I change "ex.InnerException.Message" to "ex.Message " the error output is:
System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed
I even tried debugging the plug-in by attaching the visual studio debugger to the Plugin Registration Tool. When I press "Step Into (F11)" on the line "
XGraphics.FromPdfPage(page);
It immediately throws the aforementioned errors, without even entering the method (Even if it is metadata).
-
Tuesday, February 12, 2013 11:25 AM
Well I finally managed to get it to work. I did it by deploying the plugin on disk and adding the referenced assembly in the same directory.
I simply can't use a referenced assembly when the plugin is deployed to database (Sandbox isolation). So ill be explaining how to do it on disk
Here's the rundown for some future poor soul :P
- I'm going to assume you can create and deploy plugins via visual studio and CRM SDK
- Now to be able to reference assemblies, First open "RegisterFile.crmregister" it should automatically be added when you create a Dynamics CRM Plugin Package.
- Find this line: (if it's not there, first add a plug-in project to your 'Dynamics CRM Plugin Package' solution)
<Solution Assembly="testpackage.testplugin.dll" Id="74346b01-fb74-e211-8716-005056960040" IsolationMode="Sandbox" SourceType="Database"
This is by default (at least for me). The SourceType needs to be "Disk". But "Sandbox" isolation mode is only valid for "Database" source types. So change both to:
<Solution Assembly="testpackage.testplugin.dll" Id="74346b01-fb74-e211-8716-005056960040" IsolationMode="None" SourceType="Disk"
- Now to be able to deploy this to your CRM Server, you need to build your plug-in. And copy its .DLL file and all referenced assemblies to: C:\Program Files\Microsoft Dynamics CRM\Server\bin\assembly (For x64. I don't know what it is for x86).
- Now that the plugin and all referenced assemblies are in this folder, go ahead and deploy your package.
If you get an error like: Error 1 Error registering plugins and/or workflows. Action failed for assembly 'testpackage.testplugin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=364579f10afc9ddd': Assembly must be registered in isolation. C:\Program Files (x86)\MSBuild\Microsoft\CRM\Microsoft.CrmDeveloperTools.CrmClient.targets 176 4 testpackage It's because your trying to deploy this plugin with an account that does not have enough privilage. The user account you're using to connect and deploy the package must be in the "Deployment Administrators" group. Where this is I don't know unfortunately :) But what you can do is, if you can, connect with the default 'Administrator' account which has this privilege by default. If you can't use the administrator account, you're going to need to find a way to add your account to the Deployment Administrators group. "There is a security restriction that enables only privileged users to register plug-ins. The system user account under which the plug-in is being registered must exist in the Deployment Administrators group of Deployment Manager" (From: http://msdn.microsoft.com/en-us/library/cc151098.aspx)
You should have been able to successfully deploy your plugin.
Now to edit or update your plugin
- You're going to have to build your plug-in again, and copy the .dll to the assembly folder again (The folder I mentioned above).
- If you updated any of your assemblies, same goes for them.
- But you can't delete the older one because ISS is using it.
- To free it from ISS's slimy hands you must open the ISS Manager and navigate to "Application Pools" under your machine. And 'Recycle' the 'CRMAppPool' service.
- Wait 5 seconds and now the dll should be free for changes.
- Copy your new dll's over and deploy once again.
- Your plug-in should be updated.
NOTE: If your plugin is asynchronus (You can find out what your plugin is in the "RegisterFile.crmregister" file : Mode="Synchronous" ), instead of recycling the CRMAppPool service, you may need to restart the Asynchronus Service that handles asynch crm processes. It's a Windows service and can be found using the administrative tools on your computer. Just google it and you should be fine (:
This is such a gruesome process.. If anyone has any tips, I'd gladly welcome them :)
This is all the info I have to share. Hope it helps someone.
Thanks for all the tips
Regards,
Selvihan Batırbek
- Marked As Answer by Selvihan Batırbek Tuesday, February 12, 2013 11:59 AM
- Edited by Selvihan Batırbek Tuesday, February 12, 2013 12:00 PM