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

Source not being generated #132

Closed
trampster opened this issue Jul 30, 2021 · 5 comments
Closed

Source not being generated #132

trampster opened this issue Jul 30, 2021 · 5 comments

Comments

@trampster
Copy link

I have a .net 5 WPF project that I tried to use StronInject on. But the injection code is not being generated.

My Container is as follows:

using JsonSrcGenInstantAnswer.ViewModels;
using StrongInject;

namespace JsonSrcGenInstantAnswer
{
   [Register(typeof(SearchViewModel))]
   [Register(typeof(MainWindow))]
   public partial class InstantAnswerContainer : IContainer<MainWindow>
   {
   }
}

However when I build the build fails I get the following errors in my build output (but strangely not in my Errors list)

1>C:\Work\JsonSrcGenInstantAnswer\JsonSrcGenInstantAnswer\InstantAnswerContainer.cs(8,50,8,72): error CS0535: 'InstantAnswerContainer' does not implement interface member 'IContainer<MainWindow>.Run<TResult, TParam>(Func<MainWindow, TParam, TResult>, TParam)'
1>C:\Work\JsonSrcGenInstantAnswer\JsonSrcGenInstantAnswer\InstantAnswerContainer.cs(8,50,8,72): error CS0535: 'InstantAnswerContainer' does not implement interface member 'IContainer<MainWindow>.Resolve()'
1>C:\Work\JsonSrcGenInstantAnswer\JsonSrcGenInstantAnswer\InstantAnswerContainer.cs(8,50,8,72): error CS0535: 'InstantAnswerContainer' does not implement interface member 'IDisposable.Dispose()'
@YairHalberstadt
Copy link
Owner

Which version of wpf are you using? I believe generators only work on 5.1 of the SDK

@trampster
Copy link
Author

How do I change to 5.1 of the SDK?

my project file looks like this:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net5.0-windows</TargetFramework>
    <UseWPF>true</UseWPF>
  </PropertyGroup>

  <ItemGroup>
    <None Remove="search.png" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="StrongInject" Version="1.2.0" />
  </ItemGroup>

  <ItemGroup>
    <Resource Include="search.png">
      <CopyToOutputDirectory>Never</CopyToOutputDirectory>
    </Resource>
  </ItemGroup>

</Project>

@trampster
Copy link
Author

trampster commented Jul 30, 2021

Do you mean the .Net SDK? because the lastest version of that I can find is 5.0.8. My Visual Studio is upto date.

@trampster
Copy link
Author

I found this issue which appears to have a work around dotnet/wpf#3404

Which is to add the following to my project file:

<IncludePackageReferencesDuringMarkupCompilation>true</IncludePackageReferencesDuringMarkupCompilation>

Seems that this will be on by default in .net 6.

This is obviously not the fault of StrongInject so I'm closing this.

@YairHalberstadt
Copy link
Owner

It's also on by default in dotnet SDK 5.0.2

dotnet/sdk#15465

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