从silverlight5中的隔离存储中获取dll时出现UnhandledException

时间:2012-07-09 07:12:07

标签: silverlight silverlight-5.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

请告诉我此错误的解决方法。

1 个答案:

答案 0 :(得分: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);