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

Error when compiling Could not load file or assembly System.Runtime #1055

Closed
CtrlShiftEscape opened this issue Apr 18, 2019 · 14 comments
Closed
Assignees

Comments

@CtrlShiftEscape
Copy link

CtrlShiftEscape commented Apr 18, 2019

WebSharper error FS9001 : Global error : System.IO.FileLoadException: Could not load file or assembly 'System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Could not find or load a specific file. (Exception from HRESULT: 0x80131621)↔File name: 'System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' ---> System.IO.FileLoadException: Could not load file or assembly 'System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL'.↔   at System.Runtime.Loader.AssemblyLoadContext.LoadFromPath(IntPtr ptrNativeAssemblyLoadContext, String ilPath, String niPath, ObjectHandleOnStack retAssembly)↔   at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath)↔   at System.Reflection.Assembly.LoadFrom(String assemblyFile)↔   at WebSharper.FSharp.Program.assemblyResolveHandler@160.Invoke(Object _arg1, ResolveEventArgs e)↔   at System.AppDomain.OnAssemblyResolveEvent(RuntimeAssembly assembly, String assemblyFullName)↔   at System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type)↔   at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)↔   at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)↔   at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg)↔   at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent)↔   at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeAssembly assembly, RuntimeType caType)↔   at System.Attribute.GetCustomAttributes(Assembly element, Type attributeType, Boolean inherit)↔   at System.Attribute.GetCustomAttribute(Assembly element, Type attributeType, Boolean inherit)↔   at <StartupCode$WebSharper-Sitelets-Offline>.$HtmlCommand.loadSite@55(AssemblyResolver aR, String file)↔   at <StartupCode$WebSharper-Sitelets-Offline>.$HtmlCommand.WebSharper-Compiler-HtmlCommand-IHtmlCommand-Execute@53.Invoke(Unit unitVar0)↔   at WebSharper.Compiler.AssemblyResolver.Wrap[T](FSharpFunc`2 action)↔   at WebSharper.Compiler.AssemblyResolver.Wrap[T](FSharpFunc`2 action)↔   at WebSharper.Compiler.CommandTools.ExecuteCommands.Html(WsConfig settings)↔   at WebSharper.FSharp.Program.Compile$cont@201-2(WsConfig config, Boolean isBundleOnly, Loader loader, FSharpList`1 refs, Task`1 wsRefsMeta, Compilation comp, Unit unitVar)↔   at WebSharper.FSharp.Program.Compile$cont@70(WsConfig config, WarnSettings warnSettings, String thisName, Unit unitVar)↔   at WebSharper.FSharp.Program.compileMain$cont@304(String[] argv, Unit unitVar)↔   at WebSharper.FSharp.Program.main(String[] argv)

Project is created using dotnet new websharper-html

@granicz
Copy link
Member

granicz commented Apr 18, 2019

What .NET Core do you have installed? Can you post your output for dotnet --info?

@CtrlShiftEscape
Copy link
Author

.NET Core SDK (reflecting any global.json):
 Version:   3.0.100-preview-009812
 Commit:    e3abf6e935

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.17763
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\3.0.100-preview-009812\

Host (useful for support):
  Version: 3.0.0-preview-27122-01
  Commit:  00c5c8bc40

.NET Core SDKs installed:
  2.1.104 [C:\Program Files\dotnet\sdk]
  2.1.200 [C:\Program Files\dotnet\sdk]
  2.1.201 [C:\Program Files\dotnet\sdk]
  2.1.202 [C:\Program Files\dotnet\sdk]
  2.1.301 [C:\Program Files\dotnet\sdk]
  2.1.400 [C:\Program Files\dotnet\sdk]
  2.1.401 [C:\Program Files\dotnet\sdk]
  2.1.402 [C:\Program Files\dotnet\sdk]
  2.1.403 [C:\Program Files\dotnet\sdk]
  2.1.500 [C:\Program Files\dotnet\sdk]
  2.1.502 [C:\Program Files\dotnet\sdk]
  2.1.503 [C:\Program Files\dotnet\sdk]
  2.1.504 [C:\Program Files\dotnet\sdk]
  2.1.505 [C:\Program Files\dotnet\sdk]
  2.1.600 [C:\Program Files\dotnet\sdk]
  2.1.602 [C:\Program Files\dotnet\sdk]
  2.2.104 [C:\Program Files\dotnet\sdk]
  3.0.100-preview-009812 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.0.0-preview-18579-0056 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.3-servicing-26724-03 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.0.0-preview-27122-01 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.0.0-alpha-27128-4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download

Project is netcoreapp2.2

@granicz
Copy link
Member

granicz commented Apr 19, 2019

Just out of curiousity, what's the version on your System.Runtime in your SDK?

@CtrlShiftEscape
Copy link
Author

Where can I view it?

@Jand42
Copy link
Member

Jand42 commented Apr 21, 2019

Hi, @CtrlShiftEscape, I have been testing latest templates on SDK 3.0.100-preview3-010431 without problems. Can you update your SDK to preview3 or latest preview4 and tell if the issue persists? Thanks.

@yetanotherlogonfail
Copy link

Adam and Jand42, if you are asking for peeps here to do something else to determine a version or setting value of extracting output from .netcore, please provide a link or the instructions of how to get this info, just as in code when you f12 to another function, then f12 again to the next function, ANY additional steps reduces the chances of user following your advice and thus increases the chance users will seek alternate solutions. I too failed to get this git solution to compile, my solution -> look at Giraffe it seems to work. Especially when looking at leading edge stuff like this it is silly for it not to compile. MOST people are going to be put off by it not working out of the box.
DO NOT ADD any more features at all fix the basics and this type of solution might grow.
Sorry to be so harsh but after failing to get Xamarin to compile out of the box, and fable and websharper I’m feeling much much less love for F# and my company projects get C# approval time after time; even python and java solutions have been approved when a func approach would have been preferable.
You’re the leaders with this software, do it right, please.

@Jand42
Copy link
Member

Jand42 commented Jul 3, 2019

@yetanotherlogonfail Hi, here are the .NET Core 3.0 preview releases, they are not auto-updated by the VS2019 installer https://dotnet.microsoft.com/download/dotnet-core/3.0
I have been testing the last release with preview3 on Win 64bit, will try some others.

Having a global.json file can fix down your SDK that is being used, to go back to stable 2.2, create it with:

{
  "sdk": {
    "version": "2.2.104"
  }
}

@mjarosie
Copy link

mjarosie commented May 26, 2020

I'm running into the same issue. Steps to reproduce:

dotnet new websharper-html -lang f# -n test-html
cd test-html

Then after modifying the <TargetFramework> value in test-html.fsproj from netstandard2.0 to netcoreapp3.1:

dotnet restore
dotnet run

Full error that I'm getting:

WebSharper error FS9001 : Global error : System.IO.FileLoadException: Could not load file or assembly 'System.Runtime, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Could not find or load a specific file. (Exception from HRESULT: 0x80131621)
File name: 'System.Runtime, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' ---> System.IO.FileLoadException: Could not load file or assembly 'System.Runtime, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL'.
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromPath(IntPtr ptrNativeAssemblyLoadContext, String ilPath, String niPath, ObjectHandleOnStack retAssembly)
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath)
   at System.Reflection.Assembly.LoadFrom(String assemblyFile)
   at WebSharper.FSharp.Program.assemblyResolveHandler@154.Invoke(Object _arg1, ResolveEventArgs e)
   at System.AppDomain.InvokeResolveEvent(ResolveEventHandler eventHandler, RuntimeAssembly assembly, String name)
   at System.ModuleHandle.ResolveType(RuntimeModule module, Int32 typeToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount, ObjectHandleOnStack type)
   at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
   at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
   at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(CustomAttributeRecord caRecord, MetadataImport scope, Assembly& lastAptcaOkAssembly, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, Object[] attributes, IList derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg)
   at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes)
   at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeAssembly assembly, RuntimeType caType)
   at System.Attribute.GetCustomAttributes(Assembly element, Type attributeType, Boolean inherit)
   at System.Attribute.GetCustomAttribute(Assembly element, Type attributeType, Boolean inherit)
   at <StartupCode$WebSharper-Sitelets-Offline>.$HtmlCommand.loadSite@55(AssemblyResolver aR, String file)
   at <StartupCode$WebSharper-Sitelets-Offline>.$HtmlCommand.WebSharper-Compiler-HtmlCommand-IHtmlCommand-Execute@53.Invoke(Unit unitVar0)
   at WebSharper.Compiler.AssemblyResolver.Wrap[T](FSharpFunc`2 action)
   at WebSharper.Compiler.AssemblyResolver.Wrap[T](FSharpFunc`2 action)
   at WebSharper.Compiler.CommandTools.ExecuteCommands.Html(WsConfig settings)
   at WebSharper.FSharp.Program.Compile$cont@202-2(WsConfig config, Boolean isBundleOnly, Loader loader, FSharpList`1 refs, Task`1 wsRefsMeta, Compilation comp, Unit unitVar)
   at WebSharper.FSharp.Program.Compile$cont@64(WsConfig config, WarnSettings warnSettings, String thisName, Unit unitVar)
   at WebSharper.FSharp.Program.compileMain$cont@310(String[] argv, Unit unitVar)
   at WebSharper.FSharp.Program.main(String[] argv) [C:\source\GoSwimmingly\playground\test-html\test-html.fsproj]

The build failed. Fix the build errors and run again.

Output of dotnet --version:
3.1.300

Output of dotnet --info:

.NET Core SDK (reflecting any global.json):
 Version:   3.1.300
 Commit:    b2475c1295

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.18363
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\3.1.300\

Host (useful for support):
  Version: 3.1.4
  Commit:  0c2e69caa6

.NET Core SDKs installed:
  3.1.201 [C:\Program Files\dotnet\sdk]
  3.1.300 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.18 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

I don't know how to check what's the version of System.Runtime of the SDK, googling didn't point anywhere.

@yetanotherlogonfail
Copy link

Forgot I posted this, im afraid to say that, I should read the book my son bought me more often and take its advice. "Move fast and break things". I didnt move fast enough with F#, and as a result spent way too long getting data with nulls to work and then dealing with the the fact that a language that does not automatically import namespaces, references etc for you is doomed. Giraffe was fab and worked but alas the MS bolier plate of even that was too much for me in the end. I now produce my endpoints in Go/Golang, if fast simple and just works out of the box. My original point I made here STILL applies if anyone posts an example and I mean ANYONE. it must work, out of the box nothing to be added, or else you will find folks giving up- on what maybe a fantastic solution but if you cant step through the example and see it working, it will go the way of F#. condemed in history as another failed startup.

@granicz
Copy link
Member

granicz commented May 27, 2020

@yetanotherlogonfail I would love to take the "move things fast and break things" advice, and keep WebSharper and its libs on the latest netstandard/netcore and SDKs - and just switch the maintenance burden to end users then having to update their own stack constantly. But I doubt anyone would like that. We are juggling a ~100 lib ecosystem, all on a constantly moving netcore, on several OSs. Somewhere in that hierarchy, there is a mismatch with a reference. Let's find it. If anyone has info that can help, it will be quicker. This came up on the WebSharper gitter too, so I think we will have a good grip on it soon. That said, this issue got way less attention it should have, because other priorities got in the way. But rest assured, your voice is heard loud and clear.

@Jand42
Copy link
Member

Jand42 commented May 27, 2020

@CtrlShiftEscape @mjarosie @yetanotherlogonfail Sorry for the very long turnaround, I am now taking a hard look at the netcoreapp3.1 assembly redirection issues. Some WebSharper functionality such as outputting offline sitelets and locally defined macros make the compiler load the freshly compiled assembly dynamically, and the compiler for netcore is still running on netcoreapp2.0. I have tried playing around with assembly redirection in config (having no upper bounds) with no success, currently testing to multi-target the netcore wsfsc between netcoreapp2.0 (used for netstandard2.0 and netcoreapp2.x) and netcoreapp3.1 (used for netstandard2.1 and netcoreapp3.x) I think that would solve it while breaking no existing build scenarios.

@Jand42
Copy link
Member

Jand42 commented Jun 7, 2020

Switched to using netcoreapp3.1 for compilation with https://github.com/dotnet-websharper/core/releases/tag/4.6.4.404
I have tested Docker build with 3.1 sdk only and targeting aspnetcore3.1, built and started successfully.

@granicz
Copy link
Member

granicz commented Jun 8, 2020

Hi @CtrlShiftEscape @mjarosie, can you retry and let me know if you are still running into this issue?

@mjarosie
Copy link

@granicz I just checked, it works! : )

toniarnold added a commit to toniarnold/aspnettest that referenced this issue Jun 15, 2020
All test.playlist unit tests and WebForms/MVC Core/WebSharper SPA
tests are now green. When run at once, they rarely pass as a whole
due to stalled web servers. A test run takes way over half an hour,
primarily because Selenium.Firefox.WebDriver with Firefox is
extremely slow compared with Chrome (fast) and Selenium
InternetExplorer (significantly slower than IIE COM InternetExplorer).

Consolidated Click() test methods across project types and added an
optional awaitRemoved parameter that polls the DOM element for being
removed from the DOM and an optional (higher) timeout to AssertPoll.
Only this makes WebSharper SPA GUI tests reliable.

Updated dependencies except WebSharper, as with 4.6.4,
asplib.websharper can't even indirectly depend on the shared
netstandard2.0 asplib project no more. Related:
dotnet-websharper/core#1055 - the whole .\tools\netstandard2.0
directory is missing in the NuGet package, and the build fails
due to the missing WebSharper.MSBuild.CSharp.
@mrtank mrtank added the 5.0.0.100-preview1 First published Websharper 50 release label Sep 9, 2021
@mrtank mrtank added this to v5.0-preview in Releases Sep 9, 2021
@mrtank mrtank added 4.6.4.404 and removed 5.0.0.100-preview1 First published Websharper 50 release labels Sep 9, 2021
@mrtank mrtank removed this from v5.0-preview in Releases Sep 9, 2021
@mrtank mrtank closed this as completed Sep 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants