Description
Steps to reproduce:
- Download attached project and extract to folder.
- Restore packages, build.
- Observe error.
DllExport -version
: v1.7.4.29858+c1cc52f- Used Visual Studio / MSBuild : MSVS 17.1.0 / MSBuild 15.9.21+g9802d43bc3
Information from Data
tab or log data:
data tab: dllexport-data-tab.txt
msbuild with /v:diag: build.log
Project Sample
Project zip: DllExport-Error-LibSandbox.zip
This is the code from Example.cs
, but the entire project has been attached, so you may see my DllExport
settings, as well as the overall project settings.
N.B.: This error becomes evident when built with C# language version 8+, with nullable reference types enabled. Using a Language version 7.3 or lower (no NRT), or setting nullable reference types to any setting other than enabled
will not produce the error.
using LibSandbox.Native;
namespace LibSandbox
{
interface IFooProvider
{
object Inst { get; }
void Bar(object o);
}
class FooProvider : IFooProvider
{
public object Inst => new object();
public void Bar(object o) { }
}
public class Example
{
[DllExport]
public static void Baz() { }
}
}
Details
So this is a truly bizarre one that I've stumbled across today. I've narrowed it down to a very minimal reproducible example. It appears to be a combination of nullable reference types, and interface implementations.
With the project exactly as it is in the zip above, trying to rebuild will yield the error:
error : syntax error at token '.' in: .interfaceimpl type 'LibSandbox'.'IFooProvider' [...]
However, it seems to be extremely dependant on a number of things. Below, I've listed some modifications. Any single one of the changes below will allow the project to build successfully. Undo the change, and the error returns.
- Remove
IFooProvider.Inst
(and subsequentlyFooProvider.Inst
) - Remove
IFooProvider.Bar
(and subsequentlyFooProvider.Bar
) - Change
IFooProvider.Bar
to take anint
instead ofobject
(and subsequentlyFooProvider.Bar
) - Remove the parameter from
IFooProvider.Bar
(and subsequentlyFooProvider.Bar
) - Add
#nullable disable
at the top ofExample.cs
- Change
<Nullable>enable</Nullable>
inLibSandbox.csproj
to<Nullable>warnings</Nullable>
- Remove
[DllExport]
fromExample.Baz
- Remove the entire
FooProvider
class.
Perhaps some other things would work around this issue, too.
Naturally, (as I'm sure you could imagine), I'm unable to make any of the changes in my actual project, which is why I've turned to posting here.
Let me know if there's more information I can provide!