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

Default() is not found #46

Open
Lowlet opened this issue Jan 14, 2025 · 16 comments
Open

Default() is not found #46

Lowlet opened this issue Jan 14, 2025 · 16 comments

Comments

@Lowlet
Copy link

Lowlet commented Jan 14, 2025

Hi again! I'm having an issue with source generated Default() method.
image
Do I need to configure something for source gen to work?

@Lowlet
Copy link
Author

Lowlet commented Jan 14, 2025

Default() in samples is working btw. Issue is only in my own code( I have an assembly definition file if this is important).

@PereViader
Copy link
Owner

Hello,
Thank you for the report.
I'll try to repro on my end and come back.

@PereViader
Copy link
Owner

I have yet to repro as I am not currently available. Meanwhile can you include the manualdi assembly as a reference to your custom assembly.
If I recall right, the source generator filters assemblies that reference it, otherwise it would generate code that would not compile due to it lacking the reference to ManualDi

@Lowlet
Copy link
Author

Lowlet commented Jan 14, 2025

I've already included it, sorry forgot to mention.
Also I can see that there's not From...() extensions from ManualDi.Unity3d namespace (like FromGameObjectGetComponentInParent and others) even tho I've added it to usings.
image

@PereViader
Copy link
Owner

In order to see the unity derived methods, make sure that your TConcrete in this case GameService is an instance of UnityEngine.Object

image

@PereViader
Copy link
Owner

PereViader commented Jan 14, 2025

When selecting which type of Installer to choose, see the following

  • [...]EntryPointInstallers should be used as the entry points of sections of the application. EntryPoints will usually reference other installers. Usually they will be placed at the root of a scene / prefab. A scriptable object is possible, but I haven't had any need for it yet.
  • [MonoBehaviour|ScriptableObject]Installer: Should be used for sections or features that you want to keep independent of other parts. They can still depend on other features just by having the feature be injected with things outside it's namespace, but as a good rule of thumb, try to keep each feature as small as possible to inject small interfaces where it applies.

The classes above are provided for convenience and I don't foresee any real need to have any further custom implementations, but if you happen to find any, feel free to implement your own version. The underlying implementation is really simple.

Don't try to Mock or hide the UnityEngine interface. This is more problematic and very complicated to hide. Just keep the unity parts isolated from any pure logic and it usually works great. I like having lots of static utility methods that do the grunt work and then call them from the instances that are bound to the container.

@PereViader
Copy link
Owner

PereViader commented Jan 14, 2025

I've been unable to reproduce your issue where the Default method or the From... unity methods were not available.

image
image

Could you please provide a sample project so I can take a look 🙏

@PereViader
Copy link
Owner

PereViader commented Jan 14, 2025

I recall you mentioned on the previous issue that you are using Unity6

https://docs.unity3d.com/6000.0/Documentation/Manual/create-source-generator.html

According to the docs, unity6 is now only compatible with Microsoft.CodeAnalysis.Csharp 4.3

The project is currently using 4.1 up until now unity required 4.1 😅
https://github.com/PereViader/ManualDi/blob/main/ManualDi.Main/ManualDi.Main.Generators/ManualDi.Main.Generators.csproj

If I have the time, I'll check tomorrow how I could export a unity package with both DLL and conditionally include one or the other depending on the unity version.

@Lowlet
Copy link
Author

Lowlet commented Jan 14, 2025

In order to see the unity derived methods, make sure that your TConcrete in this case GameService is an instance of UnityEngine.Object

This makes perfect sense, not sure why I was testing it with pure service😅

@PereViader
Copy link
Owner

PereViader commented Jan 14, 2025

I tried to get a quick fix up for you and downloaded unity6, but it seems to be working just fine, even with the current 4.1 version.

My suggestion, however strange it might seem, is that you restart your computer.

It has happened to me while developing the source generator that the dotnet roslyn source generation server background app gets stuck and is unable to properly restart and load new DLLs.

image

image

image

If it doesn't work, maybe try to reimport all assets in the project again

Let me know how it goes.

@PereViader
Copy link
Owner

If it still doesn't work after that please link a sample project so I can review it 🙏

@Lowlet
Copy link
Author

Lowlet commented Jan 15, 2025

I tried your suggestions and it didn't worked unfortunately. I tested it in another almost empty 6.0 project and issue was presented there as well. I upgraded that project to 6.1 and it didn't fix it. I then downgraded it to 2022.3 and issue dissapeared. After that I succesfully upgraded it again to 6.0 without any problem. Unfortunately I can't do the same with my main project as it's have many package dependencies and assets (I'm sure uxml assets will be completely broken for example and prob it'll make many more issues). I wll try to reproduce this issue again in empty new project and will send it to you.

@PereViader
Copy link
Owner

I'll try to create a new empty unity 6 project

@PereViader
Copy link
Owner

PereViader commented Jan 15, 2025

Really sorry, but still could not repro your issue.
I created an empty unity 6 project and added ManualDi through OpenUPM to it and everything seems to be working fine 😨
My project.zip <- find the project here
image
image

Best for me to debug would be a minimal project where it is not working 🙏

You could also try to do the following
image

@Lowlet
Copy link
Author

Lowlet commented Jan 15, 2025

I haven't been able to repro it in empty project too. Seems like it's something with my project. I'll update this thread if I find the root of the issue. Thank you for help.

@PereViader
Copy link
Owner

PereViader commented Jan 15, 2025

I'm very interested to understand why this would/could happen. Let me know if I can help somehow

If the analyzer is detected this line should be present in your csproj of your custom assambly

image

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

2 participants