Restriction of .NET functions to a single namespace prevents usage of some C# features
GGG-KILLER opened this issue · 5 comments
The restriction that a function's assembly can only have a single namespace prevents the usage of some C# features that embeds attributes in the resulting assembly:
readonly struct
s
(I will update this list as more features that embed code into the resulting assembly are found.)
My proposed solution is to ignore types that have attributes named EmbeddedAttribute
and/or CompilerGeneratedAttribute
in the namespace counting code:
Hi @GGG-KILLER,
The #58 probably solves that. Once this is merged, can you please check if that is the case?
Hi @allantargino, unfortunately I no longer work for the company that was using this, however I will however attempt to test this in a VM when I get some time.
Ok @allantargino, today I tried to setup the new 3.1 runtime on master but it proved to be nontrivial so I'm unable to test.
The following should be enough to test if that fixed it or not though:
using Kubeless.Functions;
public class module
{
private readonly struct Box<T>
{
public T Boxed { get; }
public Box(T boxed)
{
this.Boxed = boxed;
}
}
public object handler(Event k8Event, Context k8Context)
{
return new Box<object>(k8Event.Data);
}
}
@GGG-KILLER I'm not sure I understand the actual problem about single namespace restriction (I don't see multiple namespaces in the test function?). But since I have dotnetcore3.1 runtime from #58 in my kubeless deployment, I tested your function (with a slight modification required by the runtime) and it works.
This is the exact function definition that I used for testing:
using System;
using System.Threading.Tasks;
using Kubeless.Functions;
public class module
{
private readonly struct Box<T>
{
public T Boxed { get; }
public Box(T boxed)
{
this.Boxed = boxed;
}
}
public async Task<object> handler(Event k8Event, Context k8Context)
{
return new Box<object>(k8Event.Data);
}
}
Do you think this test is enough to say that the pull request solved this issue?
I'm not sure I understand the actual problem about single namespace restriction (I don't see multiple namespaces in the test function?)
Actually, when you compile that code, the readonly struct
is marked with an IsReadonlyAttribute
, which in turn, is generated during compilation and stored on the System.Runtime.CompilerServices
namespace inside your assembly (and that IsReadonlyAttribute
in turn is marked with the EmbeddedAttribute
which is stored on the Microsoft.CodeAnalysis
namespace):
But yes, since your test passed, it's enough to say the pull request has solved this issue.