LinFu icon indicating copy to clipboard operation
LinFu copied to clipboard

Problem with Generics...

Open caloggins opened this issue 13 years ago • 8 comments

I'm playing around with various concepts. The test framework has three assemblies (A, B, and C). A has a reference to B, and C has a reference to B (A+B, C+B). It's a simple plug-in test with MEF. One of the dependencies being loaded is a simple service locator. When I attempt to use generic methods on the locator, the post compile method frags the assembly. When I use regular methods, it works...

The class:

    [Export(typeof(IPlugin))]
    public class MudPlugin : IPlugin
    {
        [Import]
        public IServiceHost MyServiceHost { get; set; }

        public void DoWork()
        {
            //MyServiceHost.Register<INoInterfaceObject, NoInterfaceObject>();
            MyServiceHost.Register(typeof(INoInterfaceObject), typeof(NoInterfaceObject));

            //var o = MyServiceHost.Resolve<INoInterfaceObject>();
            var o = (INoInterfaceObject)MyServiceHost.Resolve(typeof(INoInterfaceObject));
            o.DoWork();
        }
    }

The exception seen in ILSpy when the generic methods are used instead:

System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
   at Mono.Collections.Generic.Collection`1.get_Item(Int32 index)
   at Mono.Cecil.SignatureReader.GetGenericParameter(GenericParameterType type, UInt32 var)
   at Mono.Cecil.SignatureReader.ReadTypeSignature(ElementType etype)
   at Mono.Cecil.MetadataReader.GetTypeSpecification(UInt32 rid)
   at Mono.Cecil.MetadataReader.LookupToken(MetadataToken token)
   at Mono.Cecil.Cil.CodeReader.ReadOperand(Instruction instruction)
   at Mono.Cecil.Cil.CodeReader.ReadCode()
   at Mono.Cecil.Cil.CodeReader.ReadFatMethod()
   at Mono.Cecil.Cil.CodeReader.ReadMethodBody()
   at Mono.Cecil.Cil.CodeReader.ReadMethodBody(MethodDefinition method)
   at Mono.Cecil.MethodDefinition.b__2(MethodDefinition method, MetadataReader reader)
   at Mono.Cecil.ModuleDefinition.Read[TItem,TRet](TRet& variable, TItem item, Func`3 read)
   at Mono.Cecil.MethodDefinition.get_Body()
   at ICSharpCode.Decompiler.CodeMappings.CreateCodeMapping(MethodDefinition member, Tuple`2 codeMappings)
   at ICSharpCode.Decompiler.Ast.AstBuilder.CreateMethod(MethodDefinition methodDef)
   at ICSharpCode.Decompiler.Ast.AstBuilder.AddTypeMembers(TypeDeclaration astType, TypeDefinition typeDef)
   at ICSharpCode.Decompiler.Ast.AstBuilder.CreateType(TypeDefinition typeDef)
   at ICSharpCode.Decompiler.Ast.AstBuilder.AddType(TypeDefinition typeDef)
   at ICSharpCode.ILSpy.CSharpLanguage.DecompileType(TypeDefinition type, ITextOutput output, DecompilationOptions options)
   at ICSharpCode.ILSpy.TreeNodes.TypeTreeNode.Decompile(Language language, ITextOutput output, DecompilationOptions options)
   at ICSharpCode.ILSpy.TextView.DecompilerTextView.DecompileNodes(DecompilationContext context, ITextOutput textOutput)
   at ICSharpCode.ILSpy.TextView.DecompilerTextView.c__DisplayClass10.b__f()

I don't believe this to just be an issue with ILSpy, because of the behavior of the calling application. When the generics are used, the assembly is rendered unusable by the parent app (A cannot use MEF to load C). When generics are not used, everything functions normally.

Please let me know what other info I can supply...

caloggins avatar May 10 '11 17:05 caloggins

Are you running LinFu to postcompile the assembly? What does the raw IL look like from IL spy?

On Wed, May 11, 2011 at 1:47 AM, caloggins < [email protected]>wrote:

I'm playing around with various concepts. The test framework has three assemblies (A, B, and C). A has a reference to B, and C has a reference to B (A+B, C+B). It's a simple plug-in test with MEF. One of the dependencies being loaded is a simple service locator. When I attempt to use generic methods on the locator, the post compile method frags the assembly. When I use regular methods, it works...

The class:

   [Export(typeof(IPlugin))]
   public class MudPlugin : IPlugin
   {
       [Import]
       public IServiceHost MyServiceHost { get; set; }

       public void DoWork()
       {
           //MyServiceHost.Register<INoInterfaceObject,
NoInterfaceObject>();
           MyServiceHost.Register(typeof(INoInterfaceObject),
typeof(NoInterfaceObject));

           //var o = MyServiceHost.Resolve<INoInterfaceObject>();
           var o =
(INoInterfaceObject)MyServiceHost.Resolve(typeof(INoInterfaceObject));
           o.DoWork();
       }
   }

The exception seen in ILSpy when the generic methods are used instead:

System.ArgumentOutOfRangeException: Specified argument was out of the range
of valid values.
  at Mono.Collections.Generic.Collection`1.get_Item(Int32 index)
  at Mono.Cecil.SignatureReader.GetGenericParameter(GenericParameterType
type, UInt32 var)
  at Mono.Cecil.SignatureReader.ReadTypeSignature(ElementType etype)
  at Mono.Cecil.MetadataReader.GetTypeSpecification(UInt32 rid)
  at Mono.Cecil.MetadataReader.LookupToken(MetadataToken token)
  at Mono.Cecil.Cil.CodeReader.ReadOperand(Instruction instruction)
  at Mono.Cecil.Cil.CodeReader.ReadCode()
  at Mono.Cecil.Cil.CodeReader.ReadFatMethod()
  at Mono.Cecil.Cil.CodeReader.ReadMethodBody()
  at Mono.Cecil.Cil.CodeReader.ReadMethodBody(MethodDefinition method)
  at Mono.Cecil.MethodDefinition.b__2(MethodDefinition method,
MetadataReader reader)
  at Mono.Cecil.ModuleDefinition.Read[TItem,TRet](TRet& variable, TItem
item, Func`3 read)
  at Mono.Cecil.MethodDefinition.get_Body()
  at ICSharpCode.Decompiler.CodeMappings.CreateCodeMapping(MethodDefinition
member, Tuple`2 codeMappings)
  at ICSharpCode.Decompiler.Ast.AstBuilder.CreateMethod(MethodDefinition
methodDef)
  at ICSharpCode.Decompiler.Ast.AstBuilder.AddTypeMembers(TypeDeclaration
astType, TypeDefinition typeDef)
  at ICSharpCode.Decompiler.Ast.AstBuilder.CreateType(TypeDefinition
typeDef)
  at ICSharpCode.Decompiler.Ast.AstBuilder.AddType(TypeDefinition typeDef)
  at ICSharpCode.ILSpy.CSharpLanguage.DecompileType(TypeDefinition type,
ITextOutput output, DecompilationOptions options)
  at ICSharpCode.ILSpy.TreeNodes.TypeTreeNode.Decompile(Language language,
ITextOutput output, DecompilationOptions options)
  at
ICSharpCode.ILSpy.TextView.DecompilerTextView.DecompileNodes(DecompilationContext
context, ITextOutput textOutput)
  at
ICSharpCode.ILSpy.TextView.DecompilerTextView.c__DisplayClass10.b__f()

I don't believe this to just be an issue with ILSpy, because of the behavior of the calling application. When the generics are used, the assembly is rendered unusable by the parent app (A cannot use MEF to load C). When generics are not used, everything functions normally.

Please let me know what other info I can supply...

Reply to this email directly or view it on GitHub: https://github.com/philiplaureano/LinFu/issues/12

philiplaureano avatar May 10 '11 22:05 philiplaureano

Yes, LinFu is setup as a build task:

  <PropertyGroup>
    <PostWeaveTaskLocation>$(MSBuildProjectDirectory)\$(OutputPath)\..\..\..\lib\LinFu.Core.dll</PostWeaveTaskLocation>
  </PropertyGroup>
  <UsingTask TaskName="PostWeaveTask" AssemblyFile="$(PostWeaveTaskLocation)" />
  <Target Name="AfterBuild">
    <PostWeaveTask TargetFile="$(MSBuildProjectDirectory)\$(OutputPath)$(MSBuildProjectName).dll" InterceptAllMethodCalls="true" />
  </Target>

When attempting to view the IL with ILSpy, the following exception is displayed:

System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
   at Mono.Collections.Generic.Collection`1.get_Item(Int32 index)
   at Mono.Cecil.SignatureReader.GetGenericParameter(GenericParameterType type, UInt32 var)
   at Mono.Cecil.SignatureReader.ReadTypeSignature(ElementType etype)
   at Mono.Cecil.MetadataReader.GetTypeSpecification(UInt32 rid)
   at Mono.Cecil.MetadataReader.LookupToken(MetadataToken token)
   at Mono.Cecil.Cil.CodeReader.ReadOperand(Instruction instruction)
   at Mono.Cecil.Cil.CodeReader.ReadCode()
   at Mono.Cecil.Cil.CodeReader.ReadFatMethod()
   at Mono.Cecil.Cil.CodeReader.ReadMethodBody()
   at Mono.Cecil.Cil.CodeReader.ReadMethodBody(MethodDefinition method)
   at Mono.Cecil.MethodDefinition.<get_Body>b__2(MethodDefinition method, MetadataReader reader)
   at Mono.Cecil.ModuleDefinition.Read[TItem,TRet](TRet& variable, TItem item, Func`3 read)
   at Mono.Cecil.MethodDefinition.get_Body()
   at ICSharpCode.Decompiler.CodeMappings.CreateCodeMapping(MethodDefinition member, Tuple`2 codeMappings)
   at ICSharpCode.Decompiler.Disassembler.ReflectionDisassembler.DisassembleMethodInternal(MethodDefinition method)
   at ICSharpCode.Decompiler.Disassembler.ReflectionDisassembler.DisassembleType(TypeDefinition type)
   at ICSharpCode.ILSpy.ILLanguage.DecompileType(TypeDefinition type, ITextOutput output, DecompilationOptions options)
   at ICSharpCode.ILSpy.TreeNodes.TypeTreeNode.Decompile(Language language, ITextOutput output, DecompilationOptions options)
   at ICSharpCode.ILSpy.TextView.DecompilerTextView.DecompileNodes(DecompilationContext context, ITextOutput textOutput)
   at ICSharpCode.ILSpy.TextView.DecompilerTextView.<>c__DisplayClass10.<DecompileAsync>b__f()

LinFu.Core.dll version 2.3.0.0. I can pack the solution up and send it to you, if that might help.

caloggins avatar May 11 '11 10:05 caloggins

Side note, when I remove the LinFu from the build process, everything works normally.

caloggins avatar May 11 '11 11:05 caloggins

Sure, go ahead and send me the solution. I'll take a look at what it generates.

On Wed, May 11, 2011 at 6:57 PM, caloggins < [email protected]>wrote:

Yes, LinFu is setup as a build task:

 <PropertyGroup>

 <PostWeaveTaskLocation>$(MSBuildProjectDirectory)\$(OutputPath)\..\..\..\lib\LinFu.Core.dll</PostWeaveTaskLocation>
 </PropertyGroup>
 <UsingTask TaskName="PostWeaveTask"
AssemblyFile="$(PostWeaveTaskLocation)" />
 <Target Name="AfterBuild">
   <PostWeaveTask
TargetFile="$(MSBuildProjectDirectory)\$(OutputPath)$(MSBuildProjectName).dll"
InterceptAllMethodCalls="true" />
 </Target>

When attempting to view the IL with ILSpy, the following exception is displayed:

System.ArgumentOutOfRangeException: Specified argument was out of the range
of valid values.
  at Mono.Collections.Generic.Collection`1.get_Item(Int32 index)
  at Mono.Cecil.SignatureReader.GetGenericParameter(GenericParameterType
type, UInt32 var)
  at Mono.Cecil.SignatureReader.ReadTypeSignature(ElementType etype)
  at Mono.Cecil.MetadataReader.GetTypeSpecification(UInt32 rid)
  at Mono.Cecil.MetadataReader.LookupToken(MetadataToken token)
  at Mono.Cecil.Cil.CodeReader.ReadOperand(Instruction instruction)
  at Mono.Cecil.Cil.CodeReader.ReadCode()
  at Mono.Cecil.Cil.CodeReader.ReadFatMethod()
  at Mono.Cecil.Cil.CodeReader.ReadMethodBody()
  at Mono.Cecil.Cil.CodeReader.ReadMethodBody(MethodDefinition method)
   at Mono.Cecil.MethodDefinition.<get_Body>b__2(MethodDefinition
method, MetadataReader reader)
   at Mono.Cecil.ModuleDefinition.Read[TItem,TRet](TRet& variable, TItem
item, Func`3 read)
  at Mono.Cecil.MethodDefinition.get_Body()
  at ICSharpCode.Decompiler.CodeMappings.CreateCodeMapping(MethodDefinition
member, Tuple`2 codeMappings)
   at
ICSharpCode.Decompiler.Disassembler.ReflectionDisassembler.DisassembleMethodInternal(MethodDefinition
method)
  at
ICSharpCode.Decompiler.Disassembler.ReflectionDisassembler.DisassembleType(TypeDefinition
type)
  at ICSharpCode.ILSpy.ILLanguage.DecompileType(TypeDefinition type,
ITextOutput output, DecompilationOptions options)
   at ICSharpCode.ILSpy.TreeNodes.TypeTreeNode.Decompile(Language language,
ITextOutput output, DecompilationOptions options)
  at
ICSharpCode.ILSpy.TextView.DecompilerTextView.DecompileNodes(DecompilationContext
context, ITextOutput textOutput)
   at
ICSharpCode.ILSpy.TextView.DecompilerTextView.<>c__DisplayClass10.<DecompileAsync>b__f()

LinFu.Core.dll version 2.3.0.0. I can pack the solution up and send it to you, if that might help.

Reply to this email directly or view it on GitHub: https://github.com/philiplaureano/LinFu/issues/12#comment_1137978

philiplaureano avatar May 11 '11 13:05 philiplaureano

Here it is. WaterPlugin.cs has some comments in it. Hope this helps.

On Wed, May 11, 2011 at 9:28 AM, philiplaureano < [email protected]>wrote:

Sure, go ahead and send me the solution. I'll take a look at what it generates.

On Wed, May 11, 2011 at 6:57 PM, caloggins < [email protected]>wrote:

Yes, LinFu is setup as a build task:

 <PropertyGroup>


 <PostWeaveTaskLocation>$(MSBuildProjectDirectory)\$(OutputPath)\..\..\..\lib\LinFu.Core.dll</PostWeaveTaskLocation>
 </PropertyGroup>
 <UsingTask TaskName="PostWeaveTask"
AssemblyFile="$(PostWeaveTaskLocation)" />
 <Target Name="AfterBuild">
   <PostWeaveTask

TargetFile="$(MSBuildProjectDirectory)\$(OutputPath)$(MSBuildProjectName).dll"
InterceptAllMethodCalls="true" />
 </Target>

When attempting to view the IL with ILSpy, the following exception is displayed:

System.ArgumentOutOfRangeException: Specified argument was out of the
range
of valid values.
  at Mono.Collections.Generic.Collection`1.get_Item(Int32 index)
  at Mono.Cecil.SignatureReader.GetGenericParameter(GenericParameterType
type, UInt32 var)
  at Mono.Cecil.SignatureReader.ReadTypeSignature(ElementType etype)
  at Mono.Cecil.MetadataReader.GetTypeSpecification(UInt32 rid)
  at Mono.Cecil.MetadataReader.LookupToken(MetadataToken token)
  at Mono.Cecil.Cil.CodeReader.ReadOperand(Instruction instruction)
  at Mono.Cecil.Cil.CodeReader.ReadCode()
  at Mono.Cecil.Cil.CodeReader.ReadFatMethod()
  at Mono.Cecil.Cil.CodeReader.ReadMethodBody()
  at Mono.Cecil.Cil.CodeReader.ReadMethodBody(MethodDefinition method)
   at Mono.Cecil.MethodDefinition.<get_Body>b__2(MethodDefinition
method, MetadataReader reader)
   at Mono.Cecil.ModuleDefinition.Read[TItem,TRet](TRet& variable, TItem
item, Func`3 read)
  at Mono.Cecil.MethodDefinition.get_Body()
  at
ICSharpCode.Decompiler.CodeMappings.CreateCodeMapping(MethodDefinition
member, Tuple`2 codeMappings)
   at

ICSharpCode.Decompiler.Disassembler.ReflectionDisassembler.DisassembleMethodInternal(MethodDefinition
method)
  at

ICSharpCode.Decompiler.Disassembler.ReflectionDisassembler.DisassembleType(TypeDefinition
type)
  at ICSharpCode.ILSpy.ILLanguage.DecompileType(TypeDefinition type,
ITextOutput output, DecompilationOptions options)
   at ICSharpCode.ILSpy.TreeNodes.TypeTreeNode.Decompile(Language
language,
ITextOutput output, DecompilationOptions options)
  at

ICSharpCode.ILSpy.TextView.DecompilerTextView.DecompileNodes(DecompilationContext
context, ITextOutput textOutput)
   at

ICSharpCode.ILSpy.TextView.DecompilerTextView.<>c__DisplayClass10.<DecompileAsync>b__f()

LinFu.Core.dll version 2.3.0.0. I can pack the solution up and send it to you, if that might help.

Reply to this email directly or view it on GitHub: https://github.com/philiplaureano/LinFu/issues/12#comment_1137978

Reply to this email directly or view it on GitHub: https://github.com/philiplaureano/LinFu/issues/12#comment_1138685

caloggins avatar May 11 '11 13:05 caloggins

Did you forget to add the attachment for WaterPlugin.cs? I don't see the file in this message chain.

philiplaureano avatar May 11 '11 13:05 philiplaureano

I attached a .7z of the entire solution, did it get stripped? I can u/l it to google docs or something... Let me know the best way to send it along.

On Wed, May 11, 2011 at 9:52 AM, philiplaureano < [email protected]>wrote:

Did you forget to add the attachment for WaterPlugin.cs? I don't see the file in this message chain.

Reply to this email directly or view it on GitHub: https://github.com/philiplaureano/LinFu/issues/12#comment_1138822

caloggins avatar May 11 '11 13:05 caloggins

send it directly to my gmail account at [email protected] - Thanks

On Wed, May 11, 2011 at 9:58 PM, caloggins < [email protected]>wrote:

I attached a .7z of the entire solution, did it get stripped? I can u/l it to google docs or something... Let me know the best way to send it along.

On Wed, May 11, 2011 at 9:52 AM, philiplaureano < [email protected]>wrote:

Did you forget to add the attachment for WaterPlugin.cs? I don't see the file in this message chain.

Reply to this email directly or view it on GitHub: https://github.com/philiplaureano/LinFu/issues/12#comment_1138822

Reply to this email directly or view it on GitHub: https://github.com/philiplaureano/LinFu/issues/12#comment_1138866

philiplaureano avatar May 11 '11 13:05 philiplaureano