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

Fody Can't Find Framework #19

Open
hughesjs opened this issue Jul 1, 2022 · 14 comments
Open

Fody Can't Find Framework #19

hughesjs opened this issue Jul 1, 2022 · 14 comments

Comments

@hughesjs
Copy link

hughesjs commented Jul 1, 2022

The details of this issue are here. However, I've replicated the relevant section below for posterity.


So far, I've got this attribute:

[AttributeUsage(AttributeTargets.Method)]
public class ValidatedMethodAttribute: Attribute, IMethodInterceptor
{
	public object Invoke(MethodInfo methodInfo, object instance, Type[] typeArguments, object[] arguments, Func<object[], object> invoker)
	{
		Attribute[]? attributes = methodInfo.GetCustomAttributes().Where(att => att.GetType().IsAssignableTo(typeof(IParameterValidator<>))).ToArray();
		// Do my thing
		return invoker.Invoke(arguments);
	}
}

However, when I execute the build, something weird is going on with Fody but I can't quite work out what this issue is..?

  Fody: An unhandled exception occurred:
Exception:
Failed to execute weaver /home/james/.nuget/packages/someta.fody/1.2.1/build/../weaver/Someta.Fody.dll
Type:
System.Exception
StackTrace:
   at InnerWeaver.ExecuteWeavers() in C:\projects\fody\FodyIsolated\InnerWeaver.cs:line 222
   at InnerWeaver.Execute() in C:\projects\fody\FodyIsolated\InnerWeaver.cs:line 112
Source:
FodyIsolated
TargetSite:
Void ExecuteWeavers()
System.Type was somehow not found.  Aborting.
Type:
System.InvalidOperationException
StackTrace:
   at Someta.Fody.CecilExtensions.Initialize(ModuleDefinition moduleDefinition, TypeSystem typeSystem, AssemblyNameReference soMeta)
   at Someta.Fody.ModuleWeaver.Execute()
   at InnerWeaver.ExecuteWeavers() in C:\projects\fody\FodyIsolated\InnerWeaver.cs:line 186
Source:
Someta.Fody
TargetSite:
Boolean Initialize(Mono.Cecil.ModuleDefinition, Fody.TypeSystem, Mono.Cecil.AssemblyNameReference)

As requested on our SO chat, here's the project I'm having issues with:

https://github.com/hughesjs/warm-up-exercises/tree/user-validator/05-user-validator/cs

@hughesjs
Copy link
Author

hughesjs commented Jul 1, 2022

I've tried adding a zip to this but for some reason Github won't let me upload it, if it's vital you get it as a zip let me know and I'll upload it somewhere you can grab it!

@kswoll
Copy link
Owner

kswoll commented Jul 1, 2022

Thanks, the link to your GitHub repo is perfect. Starting to look at it now.

@kswoll
Copy link
Owner

kswoll commented Jul 1, 2022

So after checking out your repo I was able to successfully build your solution. (I checked out the user-validator branch, of course)

I then created an empty implementation of IUserRepository and added the following lines to your UnitTest1:

[Fact]
public void Test1()
{
	var userService = new UserService(new UserRepository());
	userService.CreateUser(null, null, null);
}

I then debugged the test after putting a breakpoint inside the Invoke method in ValidatedMethodAttribute and the breakpoint was successfully hit. So it all seems to be working for me.

Do you think you could try a clean checkout (into a new folder) like I just did? I wonder if you have some cruft hanging around your obj folder that is somehow getting in the way of a successful build.

@hughesjs
Copy link
Author

hughesjs commented Jul 1, 2022

Huh, strange, I'll give it a try after my dinner!

Out of interest, are you building on Windows/Linux/MacOS? The C:/ drive showing up in the error message is making me wonder if this is some platform dependency issue

@hughesjs
Copy link
Author

hughesjs commented Jul 1, 2022

Yup, I get the same issue on a clean build... Could you try building it in either WSL or a linux docker container? That would pretty much confirm the issue. I've not got anything running Windows to test on I'm afraid

@kswoll
Copy link
Owner

kswoll commented Jul 1, 2022

Oh, interesting. I definitely haven't tried it in that scenario. And yeah, I'll give that a whirl, though might not be able to get back to you until tomorrow. Thanks for working with me on this, as I'd like it to work for everyone. :)

@hughesjs
Copy link
Author

hughesjs commented Jul 4, 2022

No worries mate, let me know if there's anything I can do to help!

@hughesjs
Copy link
Author

hughesjs commented Jul 5, 2022

Hey my dude, wondering if you've had a chance to look at this or if there's anything I can do to help? Of course, no worries if not, I know how busy life gets!

@kswoll
Copy link
Owner

kswoll commented Jul 6, 2022

Hey, sorry, the 4th of July festivities took up way more of my time than I was anticipating. :) But I'm planning to look at it tomorrow. Hopefully it's reproducible on a Mac, as Linux is a bit tricker for me to test on, though I can if it comes to it.

@hughesjs
Copy link
Author

hughesjs commented Jul 6, 2022

Ahh yes of course... I forgot the colonies tend to get quite rowdy about this time of year! Nah, I hope you had a good break mate!

As for testing on Linux (if Mac doesn't reproduce the issue), WSL2 is very easy to set up and should hopefully make testing it easy for you! Happy to help with that if your'e not familiar!

image

@kswoll
Copy link
Owner

kswoll commented Jul 7, 2022

Love it! And thanks! I have WSL installed, so can definitely go that route. Made some headway today just getting set up, but hopefully more time tomorrow.

@hughesjs
Copy link
Author

hughesjs commented Jul 7, 2022

Thanks for all of your help on this one mate, there's no rush, this isn't for production code or anything, just a useful tool to have in my belt

@mmintoff
Copy link

mmintoff commented Jul 8, 2022

Hey, I submitted a PR relevant to this issue :)
You can reproduce the "System.Type was somehow not found. Aborting." issue by using "dotnet build" from Powershell.

@hughesjs
Copy link
Author

@kswoll - Any chance you've got the time to take a look at #20 ?

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

No branches or pull requests

3 participants