UnhandledException while fetching a dll from isolated storage in silverlight5

天涯浪子 提交于 2019-12-11 14:07:20

问题


I am trying to develop one silverlight app which will save and retrieve a dll from isolated storage.
For example I have downloaded and saved System.Drawing.dll into isolated storage if it not exists in isolated storage. But if it exists in isolated storage, i am trying fetch that dll from isolated storage and then creating a object of that System.Drawing to draw a rectangle over captured image. But the problem is after fetching that dll it will return the following error.

[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

Please let me know the solution for this error.


回答1:


As far as I know it is not possible to reference a .NET assembly from Silverlight, regardless of whether the DLL is located in isolated storage or not. From a Silverlight application you should only be able to reference Silverlight DLL:s or, if you are using P/Invoke functionality in SL 5, unmanaged DLL:s.

If you want to draw a rectangle in a captured (bitmap) image, you could instead download and reference the third-party library writablebitmapex and use the one of the rectangle drawing methods from that library. The writeablebitmapex library is available for Silverlight and WP7 applications as well as for WPF and Metro applications.

You should be able to do something similar to this:

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);


来源:https://stackoverflow.com/questions/11390491/unhandledexception-while-fetching-a-dll-from-isolated-storage-in-silverlight5

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