question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Compile as .netmodule fails, but exe is working

See original GitHub issue

Description

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.

image

If I build the example greeter server application with “OutputType>module</OutputType”, then I got this message.

image

Code parts which are failing:

image

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

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:open
  • Created 2 years ago
  • Reactions:1
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
MichalStrehovskycommented, Dec 14, 2021

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:

So I need to compile the C# part in a .netmodule and later on it is linked together to one DLL

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.

1reaction
KalleOlaviNiemitalocommented, Dec 8, 2021

.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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Use cases for using netmodules when compiling .NET ...
A netmodule on its own is practically worthless: Their types and code cannot be loaded and executed by the runtime environment.
Read more >
C# Compiler Options - Output options
An .exe will take its name from the source code file that contains the Main method or top-level statements. A .dll or .netmodule...
Read more >
[solved] gmsh: win build errors, update to occt7.5
I need to fix the gmsh recipe to finally switch fully to occt 7.5. But gmsh somehow failes to build for windows. There...
Read more >
Can't compile C++ : missing "alts.lib"
A lot of my work done on the beta 3 is crashing the editor because of the missing classes (my character blueprint for...
Read more >
Chromium build issue
I am trying to build a Dartium with proprietary codecs. I attempted to build a Dartium with the GYP flags, but to no...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found