Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: cannot reduce access in 2.0.15 #219

Closed
coderb opened this issue Feb 12, 2018 · 18 comments
Closed

Bug: cannot reduce access in 2.0.15 #219

coderb opened this issue Feb 12, 2018 · 18 comments

Comments

@coderb
Copy link

coderb commented Feb 12, 2018

The following code fails when run through ilrepack on windows. the error is Unhandled Exception: System.TypeLoadException: Derived method 'Meth' in type 'TestIlRepack.ArrayHandler``1' from assembly 'x, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' cannot reduce access.

The method in Class3 is having its access changed to internal from public while the base class remains public.

using System;
using System.Threading.Tasks;

namespace TestIlRepack {
    class Program {
        static void Main(string[] args) {
            GC.KeepAlive(new Class3());
            System.Console.WriteLine("done");
        }
    }

    class Class3 : Class2<Array> {
        public override ValueTask<Array> Meth() { 
            throw new NotImplementedException();
        }
    }

    abstract class Class2<T> : Class1 {

        public abstract ValueTask<T> Meth();

        internal override ValueTask<T2> Meth<T2>() {
            throw new NotImplementedException();
        }
    }

    abstract class Class1 {
        internal abstract ValueTask<T> Meth<T>();
    }
}

@gluck
Copy link
Owner

gluck commented Feb 13, 2018

Hi, what command/arguments do you pass to ILRepack ? also which version are you using ?

@gluck gluck added the bug label Feb 13, 2018
@coderb
Copy link
Author

coderb commented Feb 13, 2018

version 2.0.15

no special flags, just input and output file name.

the packed file only fails to run on windows. mono/linux seems to be tolerant of the access tightening that happens on Class3.

have you tried to reproduce?

@gluck
Copy link
Owner

gluck commented Feb 13, 2018

Thanks.
Not yet tried, but vould be related to the logic here if you wanna peek.

@coderb
Copy link
Author

coderb commented Feb 13, 2018

looked at the code, just a guess:
...it doesn't fail if Class1 is removed, so could it be that the "base-most method" logic is confusing the 2 method signatures?

@skarllot
Copy link

Any action was taken against this issue?

@Logerfo
Copy link

Logerfo commented Sep 30, 2019

This is happening to me when packing Npgsql.

@titomor-outsystems
Copy link

titomor-outsystems commented Oct 21, 2020

It's happening to me as well in Npgsql (v 4.1.5). Derived method 'Read' in type 'Npgsql.TypeHandlers.TextHandler' from assembly 'Npgsql, Version=4.1.5.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7' cannot reduce access.

@titomor-outsystems
Copy link

titomor-outsystems commented Oct 21, 2020

I fixed this in my fork. Waiting for pull request #278
to be merged.

@timotei
Copy link
Collaborator

timotei commented Mar 9, 2021

@Logerfo @titomor-outsystems I just tried merging version 4.1.5 and it worked fine. How are you invoking it?

Here's the output trying to merge it for net461, netstandard2.0 and netcore3.0

ILRepack.exe "F:\Downloads\npgsql.4.1.5\lib\net461\Npgsql.dll" /out:"F:\Downloads\npgsql.4.1.5\lib\net461\Npgsql.out.dll"
INFO: IL Repack - Version 2.1.0
INFO: ------------- IL Repack Arguments -------------
/out:F:\Downloads\npgsql.4.1.5\lib\net461\Npgsql.out.dll  F:\Downloads\npgsql.4.1.5\lib\net461\Npgsql.dll
-----------------------------------------------
INFO: Adding assembly for merge: F:\Downloads\npgsql.4.1.5\lib\net461\Npgsql.dll
INFO: Processing references
INFO: Processing types
INFO: Merging <Module>
INFO: Processing exported types
INFO: Processing resources
INFO: Fixing references
INFO: Writing output assembly to disk
INFO: Finished in 00:00:00.8895930


ILRepack.exe "F:\Downloads\npgsql.4.1.5\lib\netstandard2.0\Npgsql.dll" /out:"F:\Downloads\npgsql.4.1.5\lib\netstandard2.0\Npgsql.out.dll"
INFO: IL Repack - Version 2.1.0
INFO: ------------- IL Repack Arguments -------------
/out:F:\Downloads\npgsql.4.1.5\lib\netstandard2.0\Npgsql.out.dll  F:\Downloads\npgsql.4.1.5\lib\netstandard2.0\Npgsql.dll
-----------------------------------------------
INFO: Adding assembly for merge: F:\Downloads\npgsql.4.1.5\lib\netstandard2.0\Npgsql.dll
INFO: Processing references
INFO: Processing types
INFO: Merging <Module>
INFO: Processing exported types
INFO: Processing resources
INFO: Fixing references
INFO: Writing output assembly to disk
INFO: Finished in 00:00:00.9582638


ILRepack.exe "F:\Downloads\npgsql.4.1.5\lib\netcoreapp3.0\Npgsql.dll" /out:"F:\Downloads\npgsql.4.1.5\lib\netcoreapp3.0\Npgsql.out.dll"
INFO: IL Repack - Version 2.1.0
INFO: ------------- IL Repack Arguments -------------
/out:F:\Downloads\npgsql.4.1.5\lib\netcoreapp3.0\Npgsql.out.dll  F:\Downloads\npgsql.4.1.5\lib\netcoreapp3.0\Npgsql.dll
-----------------------------------------------
INFO: Adding assembly for merge: F:\Downloads\npgsql.4.1.5\lib\netcoreapp3.0\Npgsql.dll
INFO: Processing references
INFO: Processing types
INFO: Merging <Module>
INFO: Processing exported types
INFO: Processing resources
INFO: Fixing references
INFO: Writing output assembly to disk
INFO: Finished in 00:00:00.9131766

@knutdrofus
Copy link

I ran into this for Npgsql as well, using ilrepack 2.0.18. I created a small sample project that demonstrates the problem here: https://github.com/knutdrofus/ilrepack_npgsql_issue

For me, the error appears at runtime, during a type discovery phase during startup, when we're manually feeding types to an IOC container. Not sure if this is a bug or just me using ilrepack incorrectly.

@idigra
Copy link

idigra commented Dec 18, 2023

Also hit this on Program Synthesis: https://www.microsoft.com/en-us/research/project/prose-framework/.

In that case, it's for protected method that overrides a parent class' method, and later overriden by a deeper child.

Any plan to merge the fix and publish an official nuget?

KirillOsenkov added a commit to KirillOsenkov/il-repack that referenced this issue Dec 22, 2023
@KirillOsenkov
Copy link
Collaborator

Thank you @coderb and @knutdrofus for providing detailed repros! They were very helpful when investigating this.

I have a fix ready here:
KirillOsenkov@a8b6ad2

I've verified that it fixes both npgsql as well as the example at the top of this bug.

@KirillOsenkov
Copy link
Collaborator

@idigra I also verified that PROSE works fine too.

@MaMazav
Copy link

MaMazav commented Dec 22, 2023

@idigra I also verified that PROSE works fine too.

Great, thanks :) Is an official nuget with the fix planned to be released?

@KirillOsenkov
Copy link
Collaborator

Yes, stay tuned

@deniszykov
Copy link
Contributor

@KirillOsenkov do you plan update Mono.Cecil to latest version?

@KirillOsenkov
Copy link
Collaborator

Yes, will do a bunch of modernization and go through the outstanding PRs and bugs as time allows

@KirillOsenkov
Copy link
Collaborator

Try this fix out: https://www.nuget.org/packages/ILRepack/2.0.22

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests