question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

#elif WINDOWS doesn't work

See original GitHub issue

Description

I want to create a service and use dependency injection.

It works on each platform except windows. First, #elif __WINDOWS__ wasn’t taken into account by Visual Studio (see screenshot below) image

Next, #elif WINDOWS was recognized by Visual Studio but not by the compiler as it tells me it can’t find the implementation of my service.

It should work and the documentation MUST (just my opinion, you’re the boss haha) be updated to tell to developpers what’s the difference between #if __ANDROID__ and #if ANDROID On the Microsoft documentation I saw both, it’s quite confusing. Even more when #if __WINDOWS__ doesn’t work while #if WINDOWS does. Edit: answer given here don’t use the double underscore.

Steps to Reproduce

  • create an interface inside the MAUI project
  • create an implementation of that interface inside each platforms folder
  • try to register the service inside MauiProgram.cs

Version with bug

Release Candidate 2 (current)

Last version that worked well

Unknown/Other

Affected platforms

Windows (I’m using Visual Studio 17.2.0 Preview 6.0)

Affected platform versions

net6.0-windows10.0.19041

Did you find any workaround?

Yes !

I handle each platform and handle WINDOWS in the #else

But it’s a dirty hack because if the problem occurs on Tizen too, it cannot work

Relevant log output

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:29 (15 by maintainers)

github_iconTop GitHub Comments

3reactions
nk54commented, Feb 14, 2023

LOL I didn’t notice it was you @jfversluis : the famous Gerald from youtube!! 😆 I post some messages on your Youtube channel few days ago (Nicolas Krier) to say how much I love your content 😉

Glad to meet you here 😄

2reactions
salarcodecommented, Nov 3, 2022

Adding this to .csproj file fixes the issue for me. Looks like WINDOWS is not defined

<PropertyGroup Condition="$(TargetFramework.Contains('-windows'))">
    <DefineConstants>WINDOWS</DefineConstants>
</PropertyGroup>
Read more comments on GitHub >

github_iconTop Results From Across the Web

else & elif statements not working in Python
The code wont work. I know you are using python 3. something. I am using python 2.7.3 the code that will actually work...
Read more >
Why does my elif not work?
Hi all, I'm trying to figure out why my elif statement doesn't work. Any help would be appreciated. board = [] for x...
Read more >
Why won't my elif statement "work"?
Why won't my elif statement "work"? The instructions were to create an elif statement that checks if the user has already guessed a...
Read more >
Python If ... elif ... elif behaves super weird. Am I doing ...
The basic answer is that all your other if/elif tests are checking for colour, but the one that fails to run is not...
Read more >
Why my IDLE doesn't support else, elif
I try to work with the else and elif but it only support if condition. I am using python shell 3.7.2 in a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found