I know the .NET Core replacement for Assembly.GetExecutingAssembly()
is typeof(MyType).GetTypeInfo().Assembly
, but what about the replacement for
Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false)
I have tried appending the last bit of the code after assembly for the first solution mentioned like so:
typeof(VersionInfo).GetTypeInfo().Assembly.GetCustomAttributes(typeof(AssemblyTitleAttribute));
but it gives me a "Can't implicitly convert to object[] message.
UPDATE: Yes, as comments below indicate, I believe it is linked to the output type.
Here is the code snippet, and I am just trying to change it to be compatible with .Net Core:
public class VersionInfo
{
public static string AssemlyTitle
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
// More code follows
I have tried changing this to use CustomAttributeExtensions.GetCustomAttributes(
but I don't currently understand c# enough to know how to implement the same code as above. I still get mixed up about MemberInfo and Type and the like. Any help is extremely appreciated!
This works for me in .NET Core 1.0:
AssemblyInfo.cs
project.json
This is what i use:
This works for me:
I suspect that the issue is in code you have not shown: where you use the result of
GetCustomAttributes()
. That's becauseAssembly.GetCustomAttributes(Type, bool)
in .Net Framework returnsobject[]
, whileCustomAttributeExtensions.GetCustomAttributes(this Assembly, Type)
in .Net Core returnsIEnumerable<Attribute>
.So you need to modify your code accordingly. The simplest way would be to use
.ToArray<object>()
, but a better solution might be to change your code so that it can work withIEnumerable<Attribute>
.Wouldn't this be the simplest?
Just say'in.