Implicit casting operator not compiling outside the original assembly

I am having problems with an implicit casting operator that works fine inside the assembly, where the type is declared, but is not used when using external programs / libraries that reference the original assembly.

Suppose I have this structure:

public readonly struct Tensor
{
    public readonly IntPtr Ptr;

    // Other stuff here..

    public static unsafe implicit operator float*(in Tensor tensor) => (float*)tensor.Ptr.ToPointer();
}

This works great when used with the same build, i.e. I can do:

// Say t is a Tensor
float* p = t;

But if I try to do the same from another program / something referencing the assembly Tensoris defined, the compiler does not say:

error CS0029: Failed to implicitly convert the type "Tensor" to "float *"

The strange thing is that Visual Studio does not show any error in the IDE itself, everything looks fine there:

enter image description here

, , , .

:

  • ?
  • - VS , , ?

!

EDIT: , : https://github.com/Sergio0694/NeuralNetwork.NET

Tensor NeuralNetwork.NET APIs\Structs. , .

№ 2: , : https://github.com/dotnet/roslyn/issues/23945 p >

+4

Source: https://habr.com/ru/post/1691371/


All Articles