NotSupportedException Thrown With Silverlight 5 Assemblies #103

Closed
opened 2012-06-12 14:09:11 -05:00 by martincostello · 3 comments
martincostello commented 2012-06-12 14:09:11 -05:00 (Migrated from github.com)

To replicate, run the following code using an assembly from the Silverlight 5 SDK:

using System;
using System.Linq;
using Mono.Cecil;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            ModuleDefinition module = ModuleDefinition.ReadModule(@"C:\Program Files (x86)\Microsoft SDKs\Silverlight\v5.0\Libraries\Client\Microsoft.CSharp.dll");

            CustomAttribute debuggbleAttribute = module.Assembly.CustomAttributes
                .Where((attrib) => string.Equals(attrib.AttributeType.FullName, typeof(System.Diagnostics.DebuggableAttribute).FullName, StringComparison.Ordinal))
                .FirstOrDefault();

            if (debuggbleAttribute != null)
            {
                var ctorArgs = debuggbleAttribute.ConstructorArguments;
                int count = ctorArgs.Count;
                Console.WriteLine(count);
            }
        }
    }
}

A NotSupportedException is thrown from Mono.Cecil\BaseAssemblyResolver.cs(245): "Version not supported: 5.0.5.0"

Replicated with local build using Master with commit 34f3fcbfac.

Mono.Cecil should support reading Silverlight 5.0 assemblies.

To replicate, run the following code using an assembly from the Silverlight 5 SDK: ``` csharp using System; using System.Linq; using Mono.Cecil; namespace ConsoleApp { class Program { static void Main(string[] args) { ModuleDefinition module = ModuleDefinition.ReadModule(@"C:\Program Files (x86)\Microsoft SDKs\Silverlight\v5.0\Libraries\Client\Microsoft.CSharp.dll"); CustomAttribute debuggbleAttribute = module.Assembly.CustomAttributes .Where((attrib) => string.Equals(attrib.AttributeType.FullName, typeof(System.Diagnostics.DebuggableAttribute).FullName, StringComparison.Ordinal)) .FirstOrDefault(); if (debuggbleAttribute != null) { var ctorArgs = debuggbleAttribute.ConstructorArguments; int count = ctorArgs.Count; Console.WriteLine(count); } } } } ``` A NotSupportedException is thrown from Mono.Cecil\BaseAssemblyResolver.cs(245): "Version not supported: 5.0.5.0" Replicated with local build using Master with commit 34f3fcbfac. Mono.Cecil should support reading Silverlight 5.0 assemblies.
jbevain commented 2012-06-12 15:25:32 -05:00 (Migrated from github.com)

Mono.Cecil should support reading Silverlight 5.0 assemblies.

As a matter of fact, it supports reading them just fine.
The only thing is that for resolving assemblies, it doesn't know what 5.0.5.0 means, as Silverlight assemblies are no different from desktop assemblies.

Thus, for silverlight assemblies, you must use a custom assembly resolver which knows how to resolver SL assemblies.

For instance, you can write:

var resolver = new DefaultAssemblyResolver();
resolver.AddSearchDirectory(@"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\Silverlight\v5.0");

var module = ModuleDefinition.ReadModule(@"C:\Program Files (x86)\Microsoft SDKs\Silverlight\v5.0\Libraries\Client\Microsoft.CSharp.dll", new ReaderParameters { AssemblyResolver = resolver });

To make your sample to work.

> Mono.Cecil should support reading Silverlight 5.0 assemblies. As a matter of fact, it supports reading them just fine. The only thing is that for resolving assemblies, it doesn't know what 5.0.5.0 means, as Silverlight assemblies are no different from desktop assemblies. Thus, for silverlight assemblies, you must use a custom assembly resolver which knows how to resolver SL assemblies. For instance, you can write: ``` csharp var resolver = new DefaultAssemblyResolver(); resolver.AddSearchDirectory(@"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\Silverlight\v5.0"); var module = ModuleDefinition.ReadModule(@"C:\Program Files (x86)\Microsoft SDKs\Silverlight\v5.0\Libraries\Client\Microsoft.CSharp.dll", new ReaderParameters { AssemblyResolver = resolver }); ``` To make your sample to work.
martincostello commented 2012-06-12 16:01:37 -05:00 (Migrated from github.com)

OK fair enough. I'm already using a custom resolver, so I'll add the v5 path to the directory list.

I just assumed you'd want to include the path in the default resolver.

OK fair enough. I'm already using a custom resolver, so I'll add the v5 path to the directory list. I just assumed you'd want to include the path in the default resolver.
gitttt commented 2020-01-09 09:13:17 -06:00 (Migrated from github.com)

Would the example really work with those three lines? Don't you have to program a parser?

Would the example really work with those three lines? Don't you have to program a parser?
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-jbevain/cecil#103
No description provided.