philiplaureano / LinFu

A framework that adds mixins, inversion of control, DbC, and other language features to the Common Language Runtime.
http://www.codeproject.com/KB/cs/LinFuPart1.aspx
206 stars 30 forks source link

AOP / PostWeaving fails when dll contains generics #28

Open fabianoliver opened 9 years ago

fabianoliver commented 9 years ago

Hi,

I'm trying to compile a project (Called "Plugin") with LinFu's Postweaver. I've added the following the the project,

<PropertyGroup>
    <PostWeaveTaskLocation>C:\Path\To\My\LinFu.Core.dll</PostWeaveTaskLocation>
  </PropertyGroup>
  <UsingTask TaskName="PostWeaveTask" AssemblyFile="$(PostWeaveTaskLocation)" />
  <Target Name="AfterBuild">
    <PostWeaveTask TargetFile="$(MSBuildProjectDirectory)\$(OutputPath)$(MSBuildProjectName).dll" InterceptAllExceptions="false" InterceptAllFields="false" InterceptAllNewInstances="false" InterceptAllMethodCalls="false" InterceptAllMethodBodies="true" />
  </Target>

I'm using the LinFu.Core.dll included in LinFu's Nuget package.

This all works fine unless any class in my Project contains any form of generic class or method. So for example, if my Plugin project only contains one class,

    public class TestClass
    {
        public void SomeFunction() { }
    }

Everything works fine. Compiling works, and I can reference the output in other projects, do AOP etc. when I modify this class to contain a generic method though,

    public class TestClass
    {
        public void SomeFunction<T>() { }
    }

something seems to go wrong. The project still compiles fine without any error messages. But its output dll seems to be broken.

When I'm referencing this project directly in another project, I'm getting an error message "The meta file '.....path........\Plugin.dll' could not be opened - the database file is damaged and can possibly not be used'. And when, instead of referencing the project, I'm trying to reference its output dll, I'm getting an error message "Could not add reference to '.....path....\Plugin.dll'. Make sure that it's possible to access this file, and that the file is a valid assembly or COM component.". (Just a heads up, I'm not using an English version of Visual Studio and I couldn't find any official translation for these error messages, so I've translated them to English myself - hence, phrasing might vary a little, but meaning should be clear).

Is this a known problem, does postweaving not work at all when any generics are involved in a library? And is there any way to circumvent these issues and postweave libraries that do contain generics (even if that'd mean linfu wouldn't post-process any specific class or method in the library that is generic)?

philiplaureano commented 9 years ago

Hmm. LinFu.AOP uses a very old copy of Mono.Cecil, and I suspect that you can get a quick win by updating it to the latest version.

On Thu, May 14, 2015 at 7:28 PM, BogeyCode notifications@github.com wrote:

Hi,

I'm trying to compile a project (Called "Plugin") with LinFu's Postweaver. I've added the following the the project,

C:\Path\To\My\LinFu.Core.dll

I'm using the LinFu.Core.dll included in LinFu's Nuget package.

This all works fine unless any class in my Project contains any form of generic class or method. So for example, if my Plugin project only contains one class,

public class TestClass
{
    public void SomeFunction() { }
}

Everything works fine. Compiling works, and I can reference the output in other projects, do AOP etc. when I modify this class to contain a generic method though,

public class TestClass
{
    public void SomeFunction<T>() { }
}

something seems to go wrong. The project still compiles fine without any error messages. But its output dll seems to be broken.

When I'm referencing this project directly in another project, I'm getting an error message "The meta file '.....path........\Plugin.dll' could not be opened - the database file is damaged and can possibly not be used'. And when, instead of referencing the project, I'm trying to reference its output dll, I'm getting an error message "Could not add reference to '.....path....\Plugin.dll'. Make sure that it's possible to access this file, and that the file is a valid assembly or COM component.". (Just a heads up, I'm not using an English version of Visual Studio and I couldn't find any official translation for these error messages, so I've translated them to English myself - hence, phrasing might vary a little, but meaning should be clear).

Is this a known problem, does postweaving not work at all when any generics are involved in a library? And is there any way to circumvent these issues and postweave libraries that do contain generics (even if that'd mean linfu wouldn't post-process any specific class or method in the library that is generic)?

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