Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception when trying to rewrite WPF .NET 6.0 application; unable to find PresentationCore #474

Open
loftyinclination opened this issue Apr 15, 2023 · 5 comments

Comments

@loftyinclination
Copy link

I'm trying to rewrite
Getting logging output:

Failed to resolve assembly: 'PresentationCore, Version=6.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
Attempted fixes

Attempted to ignore that assembly, via setting

    "IgnoredAssemblies": [
        "PresentationCore"
    ]

in the passed JSON configuration file, but no luck.

Running with verbosity set to "exhaustive" gave the following stack trace:

Failed to resolve assembly: 'PresentationCore, Version=6.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
   at Mono.Cecil.BaseAssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters)
   at Mono.Cecil.DefaultAssemblyResolver.Resolve(AssemblyNameReference name)
   at Mono.Cecil.MetadataResolver.Resolve(TypeReference type)
   at Microsoft.Coyote.Rewriting.MethodBodyTypeRewritingPass.TryRewriteMethodReference(MethodReference method, String matchName, MethodReference& result) in D:\a\1\s\Source\Test\Rewriting\Passes\Rewriting\Types\MethodBodyTypeRewritingPass.cs:line 170
   at Microsoft.Coyote.Rewriting.MethodBodyTypeRewritingPass.VisitCallInstruction(Instruction instruction, MethodReference method) in D:\a\1\s\Source\Test\Rewriting\Passes\Rewriting\Types\MethodBodyTypeRewritingPass.cs:line 156
   at Microsoft.Coyote.Rewriting.MethodBodyTypeRewritingPass.VisitInstruction(Instruction instruction) in D:\a\1\s\Source\Test\Rewriting\Passes\Rewriting\Types\MethodBodyTypeRewritingPass.cs:line 85
   at Microsoft.Coyote.Rewriting.Pass.VisitMethod(MethodDefinition method) in D:\a\1\s\Source\Test\Rewriting\Passes\Pass.cs:line 159
   at Microsoft.Coyote.Rewriting.AssemblyInfo.Invoke(Pass pass) in D:\a\1\s\Source\Test\Rewriting\AssemblyInfo.cs:line 181
   at Microsoft.Coyote.Rewriting.RewritingEngine.RewriteAssembly(AssemblyInfo assembly, String outputPath) in D:\a\1\s\Source\Test\Rewriting\RewritingEngine.cs:line 179
   at Microsoft.Coyote.Rewriting.RewritingEngine.Run() in D:\a\1\s\Source\Test\Rewriting\RewritingEngine.cs:line 107
   --- End of stack trace from previous location ---
   at Microsoft.Coyote.Rewriting.RewritingEngine.Run() in D:\a\1\s\Source\Test\Rewriting\RewritingEngine.cs:line 112
   at Microsoft.Coyote.Rewriting.RewritingEngine.Run(RewritingOptions options, Configuration configuration, LogWriter logWriter, Profiler profiler) in D:\a\1\s\Source\Test\Rewriting\RewritingEngine.cs:line 86
   at Microsoft.Coyote.Program.RewriteAssemblies(Configuration configuration, RewritingOptions options) in D:\a\1\s\Tools\Coyote\Program.cs:line 143

I forked the code and wrapped the method.DeclaringType.Resolve() call in a try/catch block, returning false if an exception was thrown, which got me a little further;

Failed to resolve assembly: 'PresentationCore, Version=6.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
   at Mono.Cecil.BaseAssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters)
   at Mono.Cecil.DefaultAssemblyResolver.Resolve(AssemblyNameReference name)
   at Mono.Cecil.MetadataResolver.Resolve(TypeReference type)
   at Microsoft.Coyote.Rewriting.Pass.IsForeignType(TypeReference type) in C:\Dev\coyote\Source\Test\Rewriting\Passes\Pass.cs:line 343
   at Microsoft.Coyote.Rewriting.InterAssemblyInvocationRewritingPass.VisitInstruction(Instruction instruction) in C:\Dev\coyote\Source\Test\Rewriting\Passes\Rewriting\InterAssemblyInvocationRewritingPass.cs:line 41
   at Microsoft.Coyote.Rewriting.Pass.VisitMethod(MethodDefinition method) in C:\Dev\coyote\Source\Test\Rewriting\Passes\Pass.cs:line 155
   at Microsoft.Coyote.Rewriting.AssemblyInfo.Invoke(Pass pass) in C:\Dev\coyote\Source\Test\Rewriting\AssemblyInfo.cs:line 170
   at Microsoft.Coyote.Rewriting.RewritingEngine.RewriteAssembly(AssemblyInfo assembly, String outputPath) in C:\Dev\coyote\Source\Test\Rewriting\RewritingEngine.cs:line 185
   at Microsoft.Coyote.Rewriting.RewritingEngine.Run() in C:\Dev\coyote\Source\Test\Rewriting\RewritingEngine.cs:line 107
   --- End of stack trace from previous location ---
   at Microsoft.Coyote.Rewriting.RewritingEngine.Run() in C:\Dev\coyote\Source\Test\Rewriting\RewritingEngine.cs:line 112
   at Microsoft.Coyote.Rewriting.RewritingEngine.Run(RewritingOptions options, Configuration configuration, LogWriter logWriter, Profiler profiler) in C:\Dev\coyote\Source\Test\Rewriting\RewritingEngine.cs:line 86
   at Microsoft.Coyote.Program.RewriteAssemblies(Configuration configuration, RewritingOptions options) in C:\Dev\coyote\Tools\Coyote\Program.cs:line 143

Did the same try/catch in that method, wrapping methodReference.ReturnType.Resolve(). Now throwing on IsForeignType check in the same VisitInstruction method;
another try/catch and now the rewriting completed successfully.

I doubt this is the correct way of solving this though!

@loftyinclination
Copy link
Author

Tried again this morning by copying PresentationCore.dll from C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App\6.0.16, which made it pass the rewrite step, but currently failing the test run step due to Bad IL Format.

@loftyinclination
Copy link
Author

Small update; weirdly, running ILVerify on the un-rewritten dlls is also throwing errors, so I'm currently trying to slim down the project and get rid of those.

@pdeligia
Copy link
Member

pdeligia commented May 2, 2023

I believe that I have noticed this kind of error before if trying to use a different .NET version of the coyote tool with a different version of .NET binaries to rewrite. For example, trying to use .NET framework coyote rewrite with .NET 7 binaries. Can you confirm that this is not the case for you? In any case, let us know what you discover!

@loftyinclination
Copy link
Author

I've managed to get it rewriting successfully by copying in the files under test and fixing any IL issues on that, and it now runs the coyote test stage successfully. Obviously not ideal to be copying files into the testing framework.

I think I'm using the .NET 7.0 version of coyote, and the project under test is definitely .NET 7.0.

@pdeligia
Copy link
Member

pdeligia commented May 2, 2023

Glad you found a workaround, although I agree painful! If both are .NET 7, then it is really strange, not sure what it could be causing this. Let us know if you discover anything that might point to what is the root cause of this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants