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

Breaking change in version 2.1.0.230 #355

Closed
LinusNoren opened this issue Sep 25, 2018 · 8 comments
Closed

Breaking change in version 2.1.0.230 #355

LinusNoren opened this issue Sep 25, 2018 · 8 comments
Labels
state: in work Issues that are currently worked on type: bug Issues that describe misbehaving functionality

Comments

@LinusNoren
Copy link

Before version 2.1.0.230 you could do this:
_fileSystem = new Mock<IFileSystem>();
_fileSystem.Setup(x => x.Directory.Exists(It.IsAny<string>())).Returns(true);

But that doesn't work any longer, you get this error:

Castle.DynamicProxy.InvalidProxyConstructorArgumentsException: Can not instantiate proxy of class: System.IO.Abstractions.DirectoryBase.
Could not find a parameterless constructor..

How should you write this code to get this to work now?

@fgreinacher
Copy link
Contributor

@herebebeasties probably related to the changes in #352?

@fgreinacher
Copy link
Contributor

Could we for this use case have an internal parameterless constructor and expose it to Moq/Castle Core via InternalsVisibleTo?

@fgreinacher fgreinacher added type: bug Issues that describe misbehaving functionality state: needs discussion Issues that need further discussion labels Sep 25, 2018
@herebebeasties
Copy link
Contributor

Users can probably fix this by giving Moq a DefaultValueProvider subclass or similar (see their docs), but I agree it would be nicer if you could mock this out of the box without such apparatus.

A default internal constructor that's visible to DynamicProxyGen2 or whatever it is seems like a reasonable solution to me. Have to be a bit careful about how we signal to people who are implementing these base classes that they shouldn't be using it, though.

It might make more sense to make these things into interfaces, but that's an even bigger API break. :-/

I'll have a think and sort out a PR.

@fgreinacher fgreinacher added state: in work Issues that are currently worked on and removed state: needs discussion Issues that need further discussion labels Sep 28, 2018
@fgreinacher
Copy link
Contributor

Created a PR for the quick-fix. Long-term we should just do #175 to never again run into issues like these.

fgreinacher added a commit that referenced this issue Oct 8, 2018
Mocking libraries, like Moq, are based on
Castle.Core and rely on its functionality for
generating dynamic proxies. This is only possible
when there is an accessible parameterless constructor.
This changes re-adds such constructors to several
base types. They are marked internal and obsolete
so that nobody accidentially uses them in "real" code.
To allow Castle.Core to access them altough they are
internal we expose our internals to the dynamic proxy
assembly.

Fixes #355
@fgreinacher
Copy link
Contributor

@LinusNoren Could you verify that your problem is fixed in https://www.nuget.org/packages/System.IO.Abstractions/2.1.0.234 and give quick feedback here?

@fgreinacher fgreinacher reopened this Oct 8, 2018
@fgreinacher
Copy link
Contributor

Closing this. @LinusNoren feel free to re-open if you encounter a problem.

@LinusNoren
Copy link
Author

Sorry @fgreinacher, I've haven't had time to verify it yet. Will try to do that tomorrow. Thanks for the fix!

@LinusNoren
Copy link
Author

It works fine! Thank you for the help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state: in work Issues that are currently worked on type: bug Issues that describe misbehaving functionality
Projects
None yet
Development

No branches or pull requests

3 participants