将 Unity dll 引用添加到 Silverlight 4 项目

发布于 2024-09-29 16:49:19 字数 2517 浏览 5 评论 0原文

今天早上,我的 Silverlight 4 应用程序遇到了一个不寻常的问题。我一直是 IoC 框架的忠实粉丝,因此决定在我的项目中使用 Unity。但是当我将程序集添加到我的项目中时,我收到以下错误。

System.Windows.Markup.XamlParseException occurred

Message=Could not load type 'System.Security.AllowPartiallyTrustedCallersAttribute' from assembly 'mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'.

StackTrace: at System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type)
            at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
            at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
            at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg)
            at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent)
            at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean isDecoratedTargetSecurityTransparent)
            at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeAssembly assembly, RuntimeType caType)
            at System.Reflection.RuntimeAssembly.GetCustomAttributes(Type attributeType, Boolean inherit)
            at System.Attribute.GetCustomAttributes(Assembly element, Type attributeType, Boolean inherit)
            at MS.Internal.XamlSchemaContext.ProcessXmlnsDefinitions(Assembly assembly, String assemblyName)
            at MS.Internal.XamlSchemaContext.EnsureManagedAssemblyAttributesLoaded()
       InnerException: 

现在,如果我删除 dll,我的应用程序就可以正常工作了。从早上起我就一直摸不着头脑,在 StackOverflow 搜索或 Google 上都没有什么运气。

非常感谢任何帮助。

干杯---杰格

This morning I had an unusual issue with my Silverlight 4 app. I have been a big fan of IoC frameworks, so decided I will use Unity for my project. But as soon as I added the assembly to my project, I got this following error.

System.Windows.Markup.XamlParseException occurred

Message=Could not load type 'System.Security.AllowPartiallyTrustedCallersAttribute' from assembly 'mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'.

StackTrace: at System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type)
            at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
            at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
            at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg)
            at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent)
            at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean isDecoratedTargetSecurityTransparent)
            at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeAssembly assembly, RuntimeType caType)
            at System.Reflection.RuntimeAssembly.GetCustomAttributes(Type attributeType, Boolean inherit)
            at System.Attribute.GetCustomAttributes(Assembly element, Type attributeType, Boolean inherit)
            at MS.Internal.XamlSchemaContext.ProcessXmlnsDefinitions(Assembly assembly, String assemblyName)
            at MS.Internal.XamlSchemaContext.EnsureManagedAssemblyAttributesLoaded()
       InnerException: 

Now if I remove the dll my app works absolutely fine. I have been scratching my head since morning and not having much luck with StackOverflow search or Google.

Any help is much appreciated.

Cheers---Jag

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

白日梦 2024-10-06 16:49:19

请验证您实际上引用的是 Silverlight 程序集而不是桌面程序集。 Silverlight 版本中没有AllowPartiallyTrustedCallersAttribute 类。

你用的是Unity 2.0吗?如果是这样,DLL 的名称为“Microsoft.Practices.Unity.Silverlight.dll”。这是你添加的DLL吗?如果“.Silverlight”不在文件名中,那么您将引用桌面 dll。

Please verify that you're actually referencing the Silverlight assembly rather than the desktop one. The AllowPartiallyTrustedCallersAttribute class isn't in the Silverlight version.

Are you using Unity 2.0? If so, the DLL is named "Microsoft.Practices.Unity.Silverlight.dll". Is that the DLL you've added? If the ".Silverlight" isn't in the file name, then you're referencing the desktop dll instead.

心奴独伤 2024-10-06 16:49:19

本文可能提供一些有用的信息。它基本上是这样说的:

“在应用程序中使用 Unity 时的限制
部分信任环境是你
无法注册和使用映射
RegisterType 方法,其中
目标类是内部类(C#),朋友
(Visual Basic .NET)、私有 (C#) 或
私有(Visual Basic .NET)。”

This article might provide some useful information. It basically says that:

"the limitation when using Unity in a
partial trust environment is that you
cannot register and use mappings using
the RegisterType methods where the
target class is internal (C#), Friend
(Visual Basic .NET), private (C#), or
Private (Visual Basic .NET)."

夜无邪 2024-10-06 16:49:19

进行干净的构建,然后进行完整的重建,为我解决了这个问题。

Doing a clean build followed by a full rebuild fixed this issue for me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文