0

我正在尝试开发一个 Silverlight 应用程序,该应用程序将从隔离存储中保存和检索 dll。
例如,如果独立存储中不存在 System.Drawing.dll,我已将其下载并保存到独立存储中。但如果它存在于独立存储中,我会尝试从独立存储中获取该 dll,然后创建该 System.Drawing 的对象以在捕获的图像上绘制一个矩形。但问题是在获取该 dll 后它将返回以下错误。

[Window Title]
Visual Studio Just-In-Time Debugger

[Main Instruction]
An unhandled exception ('Unhandled Error in Silverlight Application 
Code: 4004    
Category: ManagedRuntimeError       
Message: System.TypeLoadException: Could not load type 'System.Runtime.CompilerServices.DependencyAttribute' from assembly 'mscorlib, Version=5.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'.
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()     
') occurred in iexplore.exe [3892].

The Just-In-Time debugger was launched without necessary security permissions. To debug this process, the Just-In-Time debugger must be run as an Administrator. Would you like to debug this process?

[V] View process details  [Yes, debug iexplore.exe] [No, cancel debugging]

[Expanded Information]
Process Name: C:\Program Files\Internet Explorer\iexplore.exe

请让我知道此错误的解决方案。

4

1 回答 1

0

据我所知,无论 DLL 是否位于独立存储中,都无法从 Silverlight 引用 .NET 程序集。在 Silverlight 应用程序中,您应该只能引用 Silverlight DLL:s,或者,如果您在 SL 5 中使用 P/Invoke 功能,则只能引用非托管 DLL:s。

如果要在捕获的(位图)图像中绘制矩形,则可以下载并引用第三方库writablebitmapex并使用该库中的一种矩形绘制方法。writeablebitmapex库可用于 Silverlight 和 WP7 应用程序以及 WPF 和 Metro 应用程序。

您应该能够执行类似的操作:

var captImg = new BitmapImage(new Uri("capturedimage.jpg", UriKind.Relative));
var editCaptImg = new WriteableBitmap(captImg);

// Draw rectangle starting at (5,5), 100 px wide, 150 px high and color red
editCaptImg.DrawRectangle(5, 5, 100, 150, Colors.Red);
于 2012-07-09T13:11:59.027 回答