System.MethodAccessException,CAS和Visual Studio调试器 [英] System.MethodAccessException, CAS and Visual Studio debugger

查看:179
本文介绍了System.MethodAccessException,CAS和Visual Studio调试器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打电话ModelMetadataProviders.Current.GetMetadataForProperties获取ModelMetadata名单在WPF应用程序使用Visual Studio 2010。 作为回报>;这个调用执行很好,我得到的IEnumerable&LT。 在code线,在那里我尝试遍历这个,我得到System.MethodAccessException。

有趣的是它只会发生,如果我与F5调试。 如果我运行code与Ctrl + F5键,那么我没有得到这个例外,code正常工作。 如果我运行从Windows资源管理器的exe,它运行良好,以及。

当然,我失去了一些东西。可能是,System.Web.Mvc不能从WPF应用程序中使用? (为什么) 是否有一些关于Visual Studio调试器?

任何帮助将AP preciated。

下面是整个异常:

  

尝试通过安全透明的方法   System.Web.Mvc.TypeDescriptorHelper.Get(System.Type的)'   访问安全至关重要方法   'System.ComponentModel.DataAnnotations.AssociatedMetadataTypeTypeDescriptionProvider..ctor(System.Type)'   失败了。

     

大会   System.ComponentModel.DataAnnotations,   版本= 4.0.0.0,文化=中立,   公钥= 31bf3856ad364e35'是一个   有条件APTCA组件,它是   在当前的应​​用程序域未启用。   以使该组件中使用由   部分信任或安全透明   code,请加集名称   System.ComponentModel.DataAnnotations,   PublicKey=0024000004800000940000000602000000240000525341310004000001000100B5FC90E7027F67871E773A8FDE8938C81DD402BA65B9201D60593E96C492651E889CC13F1415EBB53FAC1131AE0BD333C5EE6021672D9718EA31A8AEBD0DA0072F25D87DBA6FC90FFD598ED4DA35E44C398C454307E8E33B8426143DAEC9F596836F97C8F74750E5975C64E2189F45DEF46B2A2B1247ADC3652BF5C308055DA9'   到了   PartialTrustVisibleAssemblies名单   在创建应用程序域时。

解决方案

感谢您的信息,李维斯。

由于我不能使用的DataAnnotations监守说的错误,我做我自己的一些编码 - 这涉及到反思。而我面临的问题:-(与CompareAttribute调用GetCustomAttributes时。

不过,后来我发现了一个解决办法。

看来,问题是与Visual Studio宿主进程。

如果我禁用的Visual Studio宿主进程,这两个问题走开!

I am calling ModelMetadataProviders.Current.GetMetadataForProperties to fetch list of ModelMetadata in WPF application with Visual Studio 2010. This call executes fine and I get IEnumerable<> in return. At the code line, where I try to iterate over this, I get System.MethodAccessException.

Funny thing is it happens only if I am debugging with F5. If I run code with Ctrl+F5, then I do NOT get this exception and code works fine. If I run exe from windows explorer, it runs fine as well.

Surely, I am missing something. May be, System.Web.Mvc cannot used from WPF app? (why) Is there something about visual studio debugger?

Any help will be appreciated.

Here is whole exception:

Attempt by security transparent method 'System.Web.Mvc.TypeDescriptorHelper.Get(System.Type)' to access security critical method 'System.ComponentModel.DataAnnotations.AssociatedMetadataTypeTypeDescriptionProvider..ctor(System.Type)' failed.

Assembly 'System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' is a conditionally APTCA assembly which is not enabled in the current AppDomain. To enable this assembly to be used by partial trust or security transparent code, please add assembly name 'System.ComponentModel.DataAnnotations, PublicKey=0024000004800000940000000602000000240000525341310004000001000100B5FC90E7027F67871E773A8FDE8938C81DD402BA65B9201D60593E96C492651E889CC13F1415EBB53FAC1131AE0BD333C5EE6021672D9718EA31A8AEBD0DA0072F25D87DBA6FC90FFD598ED4DA35E44C398C454307E8E33B8426143DAEC9F596836F97C8F74750E5975C64E2189F45DEF46B2A2B1247ADC3652BF5C308055DA9' to the the PartialTrustVisibleAssemblies list when creating the AppDomain.

解决方案

Thanks for information, Levi.

As I could not use DataAnnotations becuase of said bug, I did some coding of my own - which involves reflection. And I faced problem :-( with CompareAttribute when calling GetCustomAttributes.

But, then I found a workaround.

It seems that issue is with Visual Studio Hosting Process.

If I disable visual studio hosting process, both problems go away!

这篇关于System.MethodAccessException,CAS和Visual Studio调试器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆