Compile as .netmodule fails, but exe is working
See original GitHub issueDescription
Hi,
I am usually not a C# developer, so I’m not really familiar with the C# world, frameworks and the environment, but we have a small integration in our product where we transport data via HTTP. So we have a DLL which has a small C# HTTP1 server and HTTP1 client in it. The main problem is that this solution is too slow and we want to give GRPC a try.
The main problem is that our DLL is a mixed-code assembly (C++ and C#). So I need to compile the C# part in a .netmodule and later on it is linked together to one DLL. This was working fine with .Net 4.8 and the HTTP1 code.
With .Net5 / .Net6 and grpc-dotnet it seems not to work.
The compiler is complaining the following:
error CS0518: Predefined type ‘System.Runtime.CompilerServices.NullableAttribute’ is not defined or im
I really have no idea how to fix it.
If I build it with “OutputType>exe</OutputType”, then it is working.
If I build the example greeter server application with “OutputType>module</OutputType”, then I got this message.
Code parts which are failing:
My complete project file looks like this.
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<OutputType>module</OutputType>
<!-- <OutputType>exe</OutputType> -->
<Utf8Output>true</Utf8Output>
<!-- <NoConfig>true</NoConfig> -->
<!-- <NoStandardLib>true</NoStandardLib> -->
<ProduceReferenceAssembly>false</ProduceReferenceAssembly>
<ProduceOnlyReferenceAssembly>false</ProduceOnlyReferenceAssembly>
<!-- <Nullable>disable</Nullable> -->
</PropertyGroup>
<ItemGroup>
<Protobuf Include="..\Protos\prpc.proto" GrpcServices="Server" Link="..\Protos\prpc.proto" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Grpc.AspNetCore" Version="2.40.0" />
</ItemGroup>
</Project>
Has somebody an idea, why this is not working with this project? Is this a .Net5/6 limitation?
Thank you very much in advance.
Reproduction Steps
- use example project from here https://github.com/grpc/grpc-dotnet/tree/master/examples/Greeter
- change OutputType to “module” in the project file
Expected behavior
compiles to .netmodule
Actual behavior
error CS0518: Predefined type ‘System.Runtime.CompilerServices.NullableAttribute’ is not defined
I really have no idea how to fix it.
Regression?
Compiling to .netmodule works in .Net 4.8 version. We don’t use grpc, this is completely new to our project.
Known Workarounds
no
Configuration
- tried .Net 5 and .Net 6
- Windows 10 Pro (x64)
Other information
No response
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:10 (6 by maintainers)
Just want to point out that the runtime would not have trouble with multimodule assemblies because what the customer is trying to do is this:
I assume link.exe is going to be used to link the .netmodules into a single-module-assembly and at that point the runtime doesn’t mind that this was a non-assembly module at some point in the past because it’s a single-module assembly now.
.NET SDK 6.0.100 is able to build a netmodule that targets .NET Framework 4.8.
.NET SDK 6.0.100 is also able to build a netmodule that targets .NET 6.0, if you configure
<ProduceReferenceAssembly>false</ProduceReferenceAssembly>
, but I suspect the .NET Runtime won’t be able to load the result. This might still be useful if you only want to generate a PE file with some Win32 resources, e.g. for Icon Table… but you need the Resource Compiler for building the resources, and if you have that, then you probably have LINK as well, and can use that instead.