diff --git a/src/runtime/Codecs/DecoderGroup.cs b/src/runtime/Codecs/DecoderGroup.cs
index cf0ee33e9..5b3d127ad 100644
--- a/src/runtime/Codecs/DecoderGroup.cs
+++ b/src/runtime/Codecs/DecoderGroup.cs
@@ -30,7 +30,7 @@ public void Add(IPyObjectDecoder item)
public bool CanDecode(PyType objectType, Type targetType)
=> this.decoders.Any(decoder => decoder.CanDecode(objectType, targetType));
///
- public bool TryDecode(PyObject pyObj, out T value)
+ public bool TryDecode(PyObject pyObj, out T? value)
{
if (pyObj is null) throw new ArgumentNullException(nameof(pyObj));
@@ -65,7 +65,7 @@ public static class DecoderGroupExtensions
/// that can decode from to ,
/// or null if a matching decoder can not be found.
///
- public static IPyObjectDecoder GetDecoder(
+ public static IPyObjectDecoder? GetDecoder(
this IPyObjectDecoder decoder,
PyType objectType, Type targetType)
{
diff --git a/src/runtime/Codecs/EncoderGroup.cs b/src/runtime/Codecs/EncoderGroup.cs
index 6c40623ca..32b550eb9 100644
--- a/src/runtime/Codecs/EncoderGroup.cs
+++ b/src/runtime/Codecs/EncoderGroup.cs
@@ -28,7 +28,7 @@ public void Add(IPyObjectEncoder item)
///
public bool CanEncode(Type type) => this.encoders.Any(encoder => encoder.CanEncode(type));
///
- public PyObject TryEncode(object value)
+ public PyObject? TryEncode(object value)
{
if (value is null) throw new ArgumentNullException(nameof(value));
diff --git a/src/runtime/CollectionWrappers/IterableWrapper.cs b/src/runtime/CollectionWrappers/IterableWrapper.cs
index 2ddcd6190..d30e584d3 100644
--- a/src/runtime/CollectionWrappers/IterableWrapper.cs
+++ b/src/runtime/CollectionWrappers/IterableWrapper.cs
@@ -35,7 +35,7 @@ public IEnumerator GetEnumerator()
iterObject.Dispose();
break;
}
- yield return iterObject.Current.As();
+ yield return iterObject.Current.As()!;
}
}
}
diff --git a/src/runtime/CollectionWrappers/ListWrapper.cs b/src/runtime/CollectionWrappers/ListWrapper.cs
index 29608bc40..41ccb8fae 100644
--- a/src/runtime/CollectionWrappers/ListWrapper.cs
+++ b/src/runtime/CollectionWrappers/ListWrapper.cs
@@ -16,7 +16,7 @@ public T this[int index]
{
var item = Runtime.PyList_GetItem(pyObject, index);
var pyItem = new PyObject(item);
- return pyItem.As();
+ return pyItem.As()!;
}
set
{
diff --git a/src/runtime/CustomMarshaler.cs b/src/runtime/CustomMarshaler.cs
index 4ba603609..f544756d8 100644
--- a/src/runtime/CustomMarshaler.cs
+++ b/src/runtime/CustomMarshaler.cs
@@ -74,7 +74,7 @@ public static ICustomMarshaler GetInstance(string cookie)
return Instance;
}
- public static string PtrToStringUni(IntPtr p)
+ public static string? PtrToStringUni(IntPtr p)
{
if (p == IntPtr.Zero)
{
@@ -134,7 +134,7 @@ public static IntPtr Py3UnicodePy2StringtoPtr(string s)
///
/// Managed String
///
- public static string PtrToPy3UnicodePy2String(IntPtr p)
+ public static string? PtrToPy3UnicodePy2String(IntPtr p)
{
return PtrToStringUni(p);
}
@@ -184,7 +184,7 @@ public override IntPtr MarshalManagedToNative(object managedObj)
return mem;
}
- public static ICustomMarshaler GetInstance(string cookie)
+ public static ICustomMarshaler GetInstance(string? cookie)
{
return Instance;
}
diff --git a/src/runtime/Python.Runtime.csproj b/src/runtime/Python.Runtime.csproj
index c90ca38e4..a90aa3aaa 100644
--- a/src/runtime/Python.Runtime.csproj
+++ b/src/runtime/Python.Runtime.csproj
@@ -60,7 +60,8 @@
+
+
-
diff --git a/src/runtime/ReflectedClrType.cs b/src/runtime/ReflectedClrType.cs
index 3b83fb443..93c28fd87 100644
--- a/src/runtime/ReflectedClrType.cs
+++ b/src/runtime/ReflectedClrType.cs
@@ -53,7 +53,9 @@ internal void Restore(InterDomainContext context)
{
var cb = context.Storage.GetValue("impl");
- cb.Load(this, context);
+ Debug.Assert(cb is not null);
+
+ cb!.Load(this, context);
Restore(cb);
}
diff --git a/src/runtime/StateSerialization/CLRWrapperCollection.cs b/src/runtime/StateSerialization/CLRWrapperCollection.cs
index 66d5170dd..f9e2654eb 100644
--- a/src/runtime/StateSerialization/CLRWrapperCollection.cs
+++ b/src/runtime/StateSerialization/CLRWrapperCollection.cs
@@ -1,10 +1,11 @@
using System.Collections.ObjectModel;
+using System.Diagnostics.CodeAnalysis;
namespace Python.Runtime;
public class CLRWrapperCollection : KeyedCollection