I downloaded a Roslyn source code and built everything according to the instructions here
I made a reference to 3 files:
Microsoft.CodeAnalysis.dll
Microsoft.CodeAnalysis.Features.dll
Microsoft.CodeAnalysis.Workspaces.dll
But when I run the following code I get the following error:
public partial class ThisAddIn
{
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
try
{
foo();
}
catch (Exception ex) // here ERROR !
{
}
}
private void foo()
{
var workspace = new AdhocWorkspace();
var proj = workspace.AddProject("abc", "c#");
}
}
System.IO.FileLoadException.Message
Could not load file or assembly 'Microsoft.CodeAnalysis.Workspaces, Version=42.42.42.42, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. Strong name signature could not be verified. The assembly may have been tampered with, or it was delay signed but not fully signed with the correct private key. (Exception from HRESULT: 0x80131045)
System.IO.FileLoadException.FusionLog
=== Pre-bind state information ===
LOG: DisplayName = Microsoft.CodeAnalysis.Workspaces, Version=42.42.42.42, Culture=neutral, PublicKeyToken=31bf3856ad364e35
(Fully-specified)
LOG: Appbase = file:///C:/Users/google-dev/source/repos/WordAddIn1/WordAddIn1/bin/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : WordAddIn1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: No application configuration file found.
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Microsoft.CodeAnalysis.Workspaces, Version=42.42.42.42, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: Attempting download of new URL file:///C:/Users/google-dev/source/repos/WordAddIn1/WordAddIn1/bin/Debug/Microsoft.CodeAnalysis.Workspaces.DLL.
ERR: Failed to complete setup of assembly (hr = 0x80131045). Probing terminated.
Conversely if I install roslyn through nuget the error does not occur.
If I use the files I built in the WPF project everything works fine, and the problem is only in VSTO.
I'm building Roslyn myself from source code, since I need RegexParser and I'm making it public.
How do I create a strong name key of my own and sign Roslyn using that key? What problems can occur as a result of this?
To sum up the question is: why does an error occur and what do I do to use the files I compiled from the source code.
When you build Roslyn locally, the binaries are "delay signed" meaning they don't have a full strong name signature. That's because the key used to sign those is a Microsoft private key that isn't checked into the repository. This trickery is not a problem for most regular apps (like your WPF app) that are running full trust, but I guess VSTO for some reason is enforcing that. You could create your own strong name key and sign it with that key if you'd like, although depending on what you're trying to do, that might cause other problems.
(If you revise your question to explain why you're building from source instead of using built binaries that'd make the advice easier to give.)
User contributions licensed under CC BY-SA 3.0