Debug on device working, but msbuild getting error CS1061: 'UIWindow' does not contain a definition for 'OverrideUserInterfaceStyle'

cjdiaz 1 Reputation point Microsoft Employee
2020-12-05T01:09:46.907+00:00

Hello,
So I have a Xamarin app, and I'm trying to build a xcarchive file for my iOS project.
On VS 2019 on Windows I'm able to connect to a Mac build host and run the app on an iPhone which I have connected to that Mac using the configuration "Debug" and platform "iPhone".

45363-capture.png

But when I want to create the xcharchive file, and use the command:

msbuild /p:Configuration=Debug /p:ServerAddress=<ipaddress> /p:ServerUser=<user>  /p:Platform=iPhone /p:ArchiveOnBuild=true /t:"Build" <solution name>.sln  

I get the error:

 AppDelegate.cs(46,24): error CS1061: 'UIWindow' does not contain a definition for 'OverrideUserInterfaceStyle' and no  
 accessible extension method 'OverrideUserInterfaceStyle' accepting a first argument of type 'UIWindow' could be found  
(are you missing a using directive or an assembly reference?)  

I'm wondering why this might be the case. I'm running in the exact same configuration, platform, and build host.
If there's another way to try and get the xcarchive such that I could avoid this error, then I'm all ears. Though currently I don't think running the build directly on the Mac is an option.

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,378 questions
{count} votes

2 answers

Sort by: Most helpful
  1. cjdiaz 1 Reputation point Microsoft Employee
    2020-12-28T17:44:33.427+00:00

    @Cole Xia (Shanghai Wicresoft Co,.Ltd.)
    My apologies for the long delay.
    I've taken your suggestion and created a blank Xamarin.Forms app from a VS template, and added the same method call. This one behaves the same exact way.

    To be more specific, the exact call I'm doing is this (trying to opt out of dark mode):

    if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0))  
     {  
          Window.OverrideUserInterfaceStyle = UIUserInterfaceStyle.Light;  
     }  
    

    where Window is of type UIWindow

    When I go into the metadata for the UIView (child class of UIWindow) in UIKit, I see the following definition:

    [BindingImpl(BindingImplOptions.GeneratedCode | BindingImplOptions.Optimizable)]  
    [Introduced(PlatformName.TvOS, 13, 0, PlatformArchitecture.All, null)]  
    [Introduced(PlatformName.iOS, 13, 0, PlatformArchitecture.All, null)]  
    [Unavailable(PlatformName.WatchOS, PlatformArchitecture.All, null)]  
    public virtual UIUserInterfaceStyle OverrideUserInterfaceStyle { get; set; }  
    

  2. Cole Xia (Shanghai Wicresoft Co,.Ltd.) 6,751 Reputation points
    2021-01-01T06:41:21.58+00:00

    Hello,

    Welcome to Microsoft Q&A!

    If you want to set dark/light mode globally, it's better to set UIUserInterfaceStyle key(with a value of Light) in your app’s Info.plist file .

    Check apple docs : https://developer.apple.com/documentation/xcode/supporting_dark_mode_in_your_interface/choosing_a_specific_interface_style_for_your_ios_app?language=objc .

    Thank you.


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.