swig编译GDAL的C#库时遇到的代码安全问题及解决方法

  以前一直用的是别人编译好的gdal库开发,今天本身编译了gdal的2.0.0版本,踩了很多坑,但总算解决了。html

  编译方法主要参考http://blog.csdn.net/liminlu0314/article/details/6945452,踩到的坑及解决方法参考http://www.cnblogs.com/yeahgis/archive/2013/04/10/3011553.html。可是yeahgis前辈没有很好地解决安全透明代码没法调用本机C++代码的问题,给每一个类添加安全等级声明太麻烦了。经过查阅资料,把%gdal_code%\swig\csharp\AssemblyInfo.cs里的安全描述改成安全

// The AllowPartiallyTrustedCallersAttribute requires the assembly to be signed with a strong name key.
// This attribute is necessary since the control is called by either an intranet or Internet
// Web page that should be running under restricted permissions.
//[assembly: SecurityCritical]

// Use the .NET Framework 2.0 transparency rules (level 1 transparency) as default
#if (CLR4)
[assembly: SecurityRules(SecurityRuleSet.Level2)]
#endif

就不会出现代码安全等级问题了。ui

  .NET的代码安全由[assembly: SecurityCritical]和[assembly: SecurityRules(SecurityRuleSet.Level2)]共同决定,程序集范围批注有NONE、SecurityTransparent、SecurityCritical、AllowPartiallyTrustedCallers四种特性,SecurityRuleSet有Level一、Level2两个级别,组合后的安全等级描述以下spa

本次编译中我选择NONE、Level2,安全等级就够用了。.net

附:代码访问安全性基础知识 https://msdn.microsoft.com/zh-cn/library/dd233102.aspxrest