Shadow Copying, and mixed C# and C++ DLLs loading from arbitrary folders

非 Y 不嫁゛ 提交于 2019-12-07 12:30:59

问题


I have a VS 2005 C# project that uses a special Plugin folder to load extra DLLs (for use as nodes in an asset conversion process).

I have a mixture of C# and C++ DLLs in this folder.

The issue I have is that when Shadow Copying is enabled, the C++ DLLs refuse to load using Assembly.LoadFrom. I have attempted to create a custom app domain, and used Load, but this also failed.

Finally, I tried reading the DLL in as byte[] data and using Load on that - again, only the C# DLLs would work this way, with an error "Additional information: Unverifiable code failed policy check. (Exception from HRESULT: 0x80131402)".

An article on the net prompted me to attempt to use /clr:safe when building that particular DLL, but then it simply failed to build due to thousands of errors in Microsoft code... (apparently)

With Shadow Copying disabled, LoadFrom works fine for all DLLs. The app is itself a plugin for Maya, and this used to work with Maya 8.5 but fails with 2008 / 2009 (if Shadow Copying is enabled).

We really would prefer to use Shadow Copying, because it prevents DLL file locks when the app is running (the Plugins folder is stored in a location that Perforce can update while the app is running).

Any ideas as to how I can persuade Shadow Copying to work with a custom folder AND a mix of C# / C++ DLLs without these problems?


回答1:


Sounds like a trust issue. Try getting a Fusion log (see this blog post). Your C++ DLLs are unverifiable since they weren't compiled with /clr:safe, so they can only be loaded as full trust. Presumably when shadow copying, the download cache location doesn't have full trust.

Running caspol -s may get you up and running if this is a development-only issue.




回答2:


Assembly.Load(byte[] ...) explicitly disallows unverifiable (mixed mode) assemblies. you can check the issue on Microsoft Connect.



来源:https://stackoverflow.com/questions/272030/shadow-copying-and-mixed-c-sharp-and-c-dlls-loading-from-arbitrary-folders

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