Comments (17)
The x86 version of the .NET Core SDK probably ships a x86 version of Microsoft.Build.Tasks.CodeAnalysis.dll
, I think that it wouldn't work if it was x64.
from buildalyzer.
@jp2masa I moved your second issue regarding resource loading problems to #11 - please continue the discussion on that issue there. I'm going to keep this one focused on bitness of the MSBuild libraries and plan to resolve that specific issue soon.
from buildalyzer.
Can you please try commenting out this line:
https://github.com/daveaglick/Buildalyzer/blob/119b9cc55ba402ef67d211e9df86d0c5aa784ff9/Buildalyzer/ProjectAnalyzer.cs#L53
Also, would you mind providing the top of the stack trace so that I can see which specific line or method it's failing on.
Thanks!
from buildalyzer.
Stack Trace:
Result StackTrace:
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark)
at System.Reflection.Assembly.LoadFrom(String assemblyFile)
at Buildalyzer.ProjectAnalyzer..ctor(AnalyzerManager manager, String projectPath)
at Buildalyzer.AnalyzerManager.GetProject(String projectPath)
at FrameworkTests.FrameworkTestFixture.GetProjectAnalyzer(String projectFile, StringBuilder log) in path\to\Buildalyzer\FrameworkTests\FrameworkTestFixture.cs:line 84
at FrameworkTests.FrameworkTestFixture.LoadsProject(String projectFile) in path\to\Buildalyzer\FrameworkTests\FrameworkTestFixture.cs:line 34
Result Message: System.BadImageFormatException: Could not load file or assembly 'Microsoft.Build.Tasks.CodeAnalysis, Version=2.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Not commenting the line: 12 tests fail. (BadImageFormatException)
Commenting the line: 8 tests fail. (project is null/arg is null)
from buildalyzer.
If I run the tests from the command line (dotnet test
), all tests pass, commenting or not the assembly load line. The Visual Studio test execution engine is x86, so probably that's the problem.
from buildalyzer.
The Visual Studio test execution engine is x86, so probably that's the problem
Now that you mention it, I actually hit this earlier myself. Should have remembered. I usually use the Resharper test runner which is x64 by default, but briefly switched to the VS one and had similar problems. I resolved it by going to Test -> Test Settings -> Default Processor Architecture -> x64. Does that resolve it for you as well?
from buildalyzer.
All the tests are passing now, but I still can't understand why it doesn't work in my application. The dotnet host is x64, so it should work.
from buildalyzer.
Is the host application platform target explicitly x64 or just AnyCPU? Not that it should make any difference since AnyCPU is supposed to pick the x64 runtime when it's available, but maybe worth checking.
from buildalyzer.
The target is AnyCPU, and I only have the .NET Core CLI x64 version installed.
from buildalyzer.
Now I'm getting this exception: https://pastebin.com/VnuwCQKn
from buildalyzer.
Oh, wow, you broke it good 😄.
On the one hand I think this is good because it means that you're actually getting past the previous problems and we're calling the MSBuild API successfully. On the other hand, this looks like it'll be nasty to track down since it's deep in the MSBuild libraries (looks like the method that kicks off the problem is Microsoft.Build.Shared.AssemblyResources.GetStringFromEngineResources
). Seems like something might be off with the resources - perhaps there are extra MSBuild properties we need to set to correctly handle resources.
Is the project you're trying to analyze open source and available somewhere I could get it to try and reproduce?
from buildalyzer.
Also, what platform are you running on?
from buildalyzer.
I was getting the same thing:
(the stack trace is exactly the same as provided by @jp2masa).
In my case, I was attempting to use Buildalyzer from a .NET 4.7 console application. Based on the above discussions, I checked the compiler settings and found this:
Unchecking that check box gets me past this error.
from buildalyzer.
@kentcb Thanks - I think I know how to get around this. MSBuild ships both x64 and x32 binaries by default, but I'm pretty sure Buildalyer is defaulting to the x64 path. I'll take a look at how to switch to the x32 libraries if the host application is detected as a x32 process.
from buildalyzer.
It's looking more and more like a x86 .NET Framework application building a .NET Core SDK-style project via the MSBuild APIs isn't a supported scenario by MSBuild and the project system. The Microsoft.Build.Tasks.CodeAnalysis.dll
assembly that holds the Microsoft.CodeAnalysis.BuildTasks.Csc
task is built for x64 only. As far as I can tell, there's no x86 or AnyCPU equivalent library (which makes sense given that it includes some native code).
I'll update the table in the readme to make this clear and leave the issue a little while longer until I'm certain, but otherwise there isn't much we can do about x86 .NET Framework hosts using the SDK.
from buildalyzer.
@jp2masa That's an excellent point! I forgot that there was a totally separate x86 SDK distribution. Going to try installing it to see what the path difference is (and what dotnet --info
returns in that case).
from buildalyzer.
@jp2masa That did the trick - just needed to add a check and manually change the path we look at (since dotnet --info
will use whichever one is first in the PATH).
from buildalyzer.
Related Issues (20)
- Unsupported log file version HOT 8
- Cache dotnet info results per global.json file HOT 5
- Error when trying to read dotnet --info HOT 3
- multiple Buildalyzer.Tests unit tests are failing HOT 3
- Make working directory used by ProcessRunner configurable HOT 3
- [Discussion] Calling `GetCompilationAsync` on ASP.NET Framework project returns empty compilation HOT 3
- Help offered HOT 1
- Could not load file or assembly `NuGet.Frameworks` HOT 16
- Build/assembly reference not found errors due to random sorting of the projects in the Workspace when loading projects from solution file HOT 9
- Xml documentation is missing for imported symbols in Roslyn Projects HOT 3
- Looking For A New Maintainer HOT 4
- Sponsoring HOT 4
- Coding style, static code analysis, and versioning HOT 15
- Immutability HOT 3
- Targeting netstandard HOT 1
- Error running on macos-14-arm64 image
- Buildalyzer hangs if build does not start
- Buildalyzer seems to be using C# 11 instead of 7.3 on some machines even for a .NET 4.8 project. HOT 8
- Making the library language-agnostic HOT 2
- Buildalyzer should be able to build projects with C# 12 language features
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from buildalyzer.