web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Merging an unmanaged DLL in a plugin

(0) ShareShare
ReportReport
Posted on by

Anyone know if it is possible to bundle an unmanaged DLL (it's a C++ DLL) within a plugin?   I use the unmanaged dll in a C# project using DLLImport.   I have used ILMerge in the past to bundle other assemblies but it doesn't work with this one.

Is it even possible or will I need to build a stand alone app outside of CRM?

Thanks,

Coty

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at
    RE: Merging an unmanaged DLL in a plugin

    Thanks,

    I am going to make a web api project and just reference the endpoints from my plugin, or from another app.  I think this will work with a non-sandboxed plugin.

    I am going to mark your previous response as the answer because I think that technically that would work if I didn't run into the 32/64 bit issue.

    Thanks,

    Coty

  • Suggested answer
    Kokulan Profile Picture
    18,054 on at
    RE: Merging an unmanaged DLL in a plugin

    Your idea of making the unmanaged DLL bit external is actually good in the long run, even when you move to cloud.

    So if its not a lot of effort, i would strip this out of plugin and move to external application or api.

  • Community Member Profile Picture
    on at
    RE: Merging an unmanaged DLL in a plugin

    Hi Kokulan, thanks for the response.

    My original build actually does build to Any CPU, I had previously tried building to x86 as well with no luck.

    I did try to enable 32 bit applications on the IIS server application pool too and it brought the whole site down with a 500 error.   In the event log it was throwing this error:

    ISAPI Filter 'C:\Program Files\Microsoft Dynamics CRM\Server\bin\DefaultAddonFilter.dll' could not be loaded due to a configuration problem. The current configuration only supports loading images built for a x86 processor architecture. The data field contains the error number. To learn more about this issue, including how to troubleshooting this kind of processor architecture mismatch error, see go.microsoft.com/fwlink.

    The error seems odd, because setting the "Enable 32-bit applications" to true I didn't think would make 64 bit apps not load.

    thanks for the help either way, if I can't get this figured out I am just going to create an external web app and just link users to it from a form.

    Thanks,

    Coty

  • Community Member Profile Picture
    on at
    RE: Merging an unmanaged DLL in a plugin

    Sreevalli, That forum post doesn't address the question.

  • Verified answer
    Kokulan Profile Picture
    18,054 on at
    RE: Merging an unmanaged DLL in a plugin

    I would try the following to see if this resolves

    01. When you build the plugin, see if you can set to build for any CPU and see if the deployment succeeds

    See this link for detail : stackoverflow.com/.../an-attempt-was-made-to-load-a-program-with-an-incorrect-format-even-when-the-p

    Check after this deployment if the DLLImport works. If it does not, you could also try enabling 32 bit application at IIS level to see if that makes a difference

  • Suggested answer
    Sreevalli Profile Picture
    3,256 on at
    RE: Merging an unmanaged DLL in a plugin

    Hi,

    Found it useful. go through it - community.dynamics.com/.../if-you-re-using-ilmerge-with-your-plugins-make-sure-you-read-this

  • Community Member Profile Picture
    on at
    RE: Merging an unmanaged DLL in a plugin

    Update:  I actually can't install both versions of the registration tool  (I get the message "A newer version is already installed").  I have several other plugins that rely on the current version so it's not an option to uninstall.

    Coty

  • Community Member Profile Picture
    on at
    RE: Merging an unmanaged DLL in a plugin

    I think I have it so it now finds the DLL, but now I am running into the issue of it being an x86 DLL I think.  First off, I solved my issue by putting the DLL in this folder:

    C:\Program Files\Microsoft Dynamics CRM\Server\bin\assembly\

    And then using the SetDllDirectory PInvoke method:

            [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
            static extern bool SetDllDirectory(string lpPathName);
    Then setting the path, before calling the DLLImport function:

    SetDllDirectory(@"C:\Program Files\Microsoft Dynamics CRM\Server\bin\assembly");



    This is the new error:

    An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)

    Which seems to indicate my plugin will not accept an x86 DLL.  I found an article stating that I should register my plugin using the CRM SDK 2011 registration tool.  My Version of CRM is 2016 on Prem.  Anyone have any experiences with this? Would this even work, or would it cause issues?

    Thank You,

    Coty

  • Verified answer
    Kokulan Profile Picture
    18,054 on at
    RE: Merging an unmanaged DLL in a plugin

    If its On-Prem, if the DLLImport works for you in a C# project, you could try that application and get that working on the the CRM server.  I assume with DLLImport you will have to register the DLL or drop it onto System folder.

    Once you got this working, you could try moving that code to plugin and deploy and see if it work. When the plugin runs in full trust mode it might actually do the DLLImport. I have not tried this myself but thought it might work.  As part of DLLImport if you are using any .NET DLL, you don't have to IL Merge that, you can GAC it on the server.

    Hope it helps.

  • Community Member Profile Picture
    on at
    RE: Merging an unmanaged DLL in a plugin

    You cannot add an unmanaged DLL via the AddReferences context Menu.   This is the error you get:

    815206.Capture.PNG

    I'm referencing the DLL like this in my plugin:

    [DllImport("unmanaged.dll")]

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Aric Levin - MVP Profile Picture

Aric Levin - MVP 2 Moderator

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#3
MA-04060624-0 Profile Picture

MA-04060624-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans