Why won't SQL Server register my assembly as SAFE?

自闭症网瘾萝莉.ら 提交于 2019-12-05 16:17:57

I ran into the same thing, and after some investigation, I think it's because of optimization that the compiler does on lambda expressions. There's some overhead in creation a delegate from a lambda expression. I think it must lazy initialize a hidden static field containing the delegate the first time the lambda is accessed so it can reuse the already constructed delegate in future calls.

The reason I think this is because if the lambda captures any variables, it doesn't cause the SAFE issue. It would make sense that if it's capturing variables, you would need to create a different delegate for each time it's called, but if the lambda is completely self contained, it could cache it for efficiency purposes.

Microsoft did fix the issue in SQL 2008, but they won't fix it in SQL 2005, so if there's a need to support existing SQL 2005 installations, all it requires is eliminating "statically optimizable" lambdas, not all the lambdas in the whole assembly.

When persmission set is unsafe, SQL won't verify the metadata of your assembly.

Try to apply the hotfix from KB 941256, or apply CU4 for SP2. Altough is a different HRESULT than the E_FAIL you're getting, perhaps the hotfix addresses the issue.

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