Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Tasks/Microsoft.NET.Build.Tasks/ClsidMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static void Create(MetadataReader metadataReader, string clsidMapPath)
// Only public COM-visible classes can be exposed via the COM host.
if (TypeIsPublic(metadataReader, definition) && TypeIsClass(metadataReader, definition) && IsComVisible(metadataReader, definition, isAssemblyComVisible))
{
string guid = GetTypeGuid(metadataReader, definition);
string guid = GetTypeGuid(metadataReader, definition).ToString("B");

if (clsidMap.ContainsKey(guid))
{
Expand Down Expand Up @@ -177,7 +177,7 @@ private static CustomAttributeHandle GetComVisibleAttribute(MetadataReader reade
return new CustomAttributeHandle();
}

private static string GetTypeGuid(MetadataReader reader, TypeDefinition type)
private static Guid GetTypeGuid(MetadataReader reader, TypeDefinition type)
{
// Find the class' GUID by reading the GuidAttribute value.
// We do not support implicit runtime-generated GUIDs for the .NET Core COM host.
Expand All @@ -189,7 +189,7 @@ private static string GetTypeGuid(MetadataReader reader, TypeDefinition type)
if (reader.StringComparer.Equals(attributeType.Namespace, "System.Runtime.InteropServices") && reader.StringComparer.Equals(attributeType.Name, "GuidAttribute"))
{
CustomAttributeValue<KnownType> data = attribute.DecodeValue(new TypeResolver());
return (string)data.FixedArguments[0].Value;
return Guid.Parse((string)data.FixedArguments[0].Value);
}
}
throw new BuildErrorException(Strings.ClsidMapExportedTypesRequireExplicitGuid, GetTypeName(reader, type));
Expand Down
17 changes: 11 additions & 6 deletions src/Tasks/Microsoft.NET.Build.Tasks/RegFreeComManifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ internal static class RegFreeComManifest
/// <param name="assemblyName">The name of the assembly.</param>
/// <param name="comHostName">The name of the comhost library.</param>
/// <param name="assemblyVersion">The version of the assembly.</param>
/// <param name="clsidMapPath">The path to the clasidmap file.</param>
/// <param name="clsidMapPath">The path to the clsidmap file.</param>
/// <param name="comManifestPath">The path to which to write the manifest.</param>
public static void CreateManifestFromClsidmap(string assemblyName, string comHostName, string assemblyVersion, string clsidMapPath, string comManifestPath)
{
XNamespace ns = "urn:shemas-microsoft-com:asm.v1";
XNamespace ns = "urn:schemas-microsoft-com:asm.v1";

XElement manifest = new XElement(ns + "assembly", new XAttribute("mainfestVersion", "1.0"));
XElement manifest = new XElement(ns + "assembly", new XAttribute("manifestVersion", "1.0"));
manifest.Add(new XElement(ns + "assemblyIdentity",
new XAttribute("type", "win32"),
new XAttribute("name", $"{assemblyName}.X"),
Expand All @@ -44,14 +44,19 @@ public static void CreateManifestFromClsidmap(string assemblyName, string comHos

foreach (JProperty property in clsidMap.Properties())
{
string guid = property.Name;
fileElement.Add(new XElement(ns + "comClass", new XAttribute("clsid", guid), new XAttribute("threadingModel", "Both")));
string guidMaybe = property.Name;
Guid guid = Guid.Parse(guidMaybe);
fileElement.Add(new XElement(ns + "comClass", new XAttribute("clsid", guid.ToString("B")), new XAttribute("threadingModel", "Both")));
}

manifest.Add(fileElement);

XDocument manifestDocument = new XDocument(new XDeclaration("1.0", "UTF-8", "yes"), manifest);
using (XmlWriter manifestWriter = XmlWriter.Create(comManifestPath))
XmlWriterSettings settings = new XmlWriterSettings()
{
Encoding = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false)
};
using (XmlWriter manifestWriter = XmlWriter.Create(comManifestPath, settings))
{
manifestDocument.WriteTo(manifestWriter);
}
Expand Down