Apple platform
Mac Catalyst
Framework version
net10.0-*
Affected platform version
.NET 10.0
Description
Summary
Foundation.NSBundle.GetUrlForResource(...) is currently annotated as non-null (NSUrl), but it can return null at runtime when the resource is missing.
This does not match Apple's API contract and makes NRT behavior unsafe for callers.
Affected APIs
NSBundle.GetUrlForResource(string name, string fileExtension)
NSBundle.GetUrlForResource(string name, string fileExtension, string subdirectory)
NSBundle.GetUrlForResource(string name, string fileExtension, string subdirectory, NSUrl bundleURL)
NSBundle.GetUrlForResource(string name, string fileExtension, string subdirectory, string localizationName)
Native API evidence (Objective-C headers)
In Xcode SDK headers, the native Objective-C signatures are explicitly nullable:
Foundation.framework/Headers/NSBundle.h
+ (nullable NSURL *)URLForResource:(nullable NSString *)name withExtension:(nullable NSString *)ext subdirectory:(nullable NSString *)subpath inBundleWithURL:(NSURL *)bundleURL;
- (nullable NSURL *)URLForResource:(nullable NSString *)name withExtension:(nullable NSString *)ext;
- (nullable NSURL *)URLForResource:(nullable NSString *)name withExtension:(nullable NSString *)ext subdirectory:(nullable NSString *)subpath;
- (nullable NSURL *)URLForResource:(nullable NSString *)name withExtension:(nullable NSString *)ext subdirectory:(nullable NSString *)subpath localization:(nullable NSString *)localizationName;
Steps to Reproduce
using Foundation;
var url = NSBundle.MainBundle.GetUrlForResource("definitely_missing_file", "txt");
// Compiles as non-null today, but url can be null at runtime.
Console.WriteLine(url == null ? "null" : url.AbsoluteString);
Did you find any workaround?
No response
Build logs
No response
Apple platform
Mac Catalyst
Framework version
net10.0-*
Affected platform version
.NET 10.0
Description
Summary
Foundation.NSBundle.GetUrlForResource(...)is currently annotated as non-null (NSUrl), but it can returnnullat runtime when the resource is missing.This does not match Apple's API contract and makes NRT behavior unsafe for callers.
Affected APIs
NSBundle.GetUrlForResource(string name, string fileExtension)NSBundle.GetUrlForResource(string name, string fileExtension, string subdirectory)NSBundle.GetUrlForResource(string name, string fileExtension, string subdirectory, NSUrl bundleURL)NSBundle.GetUrlForResource(string name, string fileExtension, string subdirectory, string localizationName)Native API evidence (Objective-C headers)
In Xcode SDK headers, the native Objective-C signatures are explicitly nullable:
Foundation.framework/Headers/NSBundle.hSteps to Reproduce
Did you find any workaround?
No response
Build logs
No response