Loading plug-in DLL files, “The invoked member is not supported in a dynamic assembly.”

不问归期 提交于 2021-02-06 07:56:21

问题


We have custom DLL's that are not included in our initial setup file. They are loaded at runtime. This process worked fine while using .NET 2.0, but we are getting the "The invoked member is not supported in a dynamic assembly" error message now that we are using .NET 4.0.

try
{
    assem = Assembly.LoadFrom(fi.FullName); //fi is FileSystemInfo
}
catch (FileLoadException) {}
catch (BadImageFormatException) {}
catch (System.Security.SecurityException) {}
catch (ArgumentException) {}
catch (PathTooLongException) {}

回答1:


This error is occurring because Assembly.Load cannot be called upon dynamic assemblies. You must filter out the dynamic assemblies before using them.

var assemblies = AppDomain.CurrentDomain.GetAssemblies().Where(p => !p.IsDynamic);




回答2:


For me this issue was not embedding the license for a Aspose dll: http://www.aspose.com/community/forums/thread/423874/initializing-the-license-file.aspx

Their code injects dynamic assemblies when a license isn't detected, causing their DLLs to fail, as well as a bunch of other code that isn't compatible with dynamic assemblies.

Not sure if this is a common licensing/activation method for ensuring registered use with 3rd party dlls, so I'll post it here for google if it is.




回答3:


This in the app.config file allows for "plug-in" dll's from remote sources.

<configuration>
   <runtime>
      <loadFromRemoteSources enabled="true"/>
   </runtime>
</configuration>

http://msdn.microsoft.com/en-us/library/dd409252.aspx



来源:https://stackoverflow.com/questions/10091221/loading-plug-in-dll-files-the-invoked-member-is-not-supported-in-a-dynamic-ass

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!