This seems very similar to Issue 150 and Issue 139 but I could not solve the problem by removing dependencies to my shared library. So now, I just have
FunctionName attributes (they're just logging to trace) And it's reproducable, so if I remove the sdk package, everything builds fine.
Microsoft.NET.Sdk.Functions (1.0.7)
Microsoft.Azure.WebJobs (3.0.0-beta4)
Microsoft.Azure.WebJobs.Extensions (3.0.0-beta4)
csproj:
<TargetFramework>netcoreapp2.0</TargetFramework>
Microsoft.NET.Sdk.Functions.Build.targets(32,5): error : System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
File name: 'System.Runtime, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
at System.Reflection.RuntimeAssembly.GetExportedTypes(RuntimeAssembly assembly, ObjectHandleOnStack retTypes)
at System.Reflection.RuntimeAssembly.GetExportedTypes()
at MakeFunctionJson.FunctionJsonConverter.TryGenerateFunctionJsons()
at MakeFunctionJson.FunctionJsonConverter.TryRun()
Do I understand it right that the generator for the function.json file goes through all dll's of referenced packages? Couldn't you somehow reduce that check to non-framwork-libraries?
I ran into the same issue.
Looking at NuGet dependencies, I've found those Functions and WebJobs seem to referencing System.Runtime (4.3.0).
So in my C:\...\.nuget\packages there is the corresponding file.
Why does my project go to find 4.2.0 and fail?
@StefanRiedmann - Can you please try to use <TargetFramework>netstandard2.0</TargetFramework> instead?
Hi! I wasn't aware that I can assign .netstandard as target framework, but now I realize that it's not an executable. So that sounds like a good option.
Anyway - I solved it by going to good old .NET4.6 and I also found some issues with the beta runtime in Azure. So now, with .NET4.6 and runtime 1.x everything works fine. I have the functions running and I'm too busy to go back to this right now, for testing the .net core way.
I will create a ticket for myself, and I will post my findings when I can work on it.
Thanks so far!
It worked for my project too, thanks @cschwendtner!
@cschwendtner, I am having the same issue, but I am unable to switch the project to netstandard2.0 as I am referencing a project in my function that is targeting netcoreapp2.0. Any suggestions for getting this to work without changing the target framework?
I did change my non-function class and methods to internal and that did not resolve the issue.
I see there are some references that might be breaking this, similar to @steevcoco comments in #151
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
I also updated to 1.0.8 and that fix has not resolved my issue.
Here is the error I am getting:
Severity Code Description Project File Line Suppression State
Error System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
File name: 'System.Runtime, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
at System.Reflection.RuntimeAssembly.GetExportedTypes(RuntimeAssembly assembly, ObjectHandleOnStack retTypes)
at System.Reflection.RuntimeAssembly.GetExportedTypes()
at MakeFunctionJson.FunctionJsonConverter.TryGenerateFunctionJsons()
at MakeFunctionJson.FunctionJsonConverter.TryRun()
WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
Error generating functions metadata
I was able to do some refactoring out of the netcoreapp to a shared netstandard library and change the target framework of the function to get this working. Hopefully this will get fixed to support targeting netcoreapp and leverage the code from netcoreapp projects.
I am however running into a new issue pulling in the nuget package Microsoft.AspNet.WebApi.Client 5.2.4, but this would be a separate issue. Works for netcoreapp, but not the azure function netstandard.
Could not load file or assembly 'System.Net.Http.Formatting, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Could not find or load a specific file. (Exception from HRESULT: 0x80131621). System.Private.CoreLib: Could not load file or assembly 'System.Net.Http.Formatting, Version=5.2.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
@Matthewsre - sorry for the late reply.
I think the intended way to build Function apps is to target .NET Standard (currently netstandard 2.0 - looking at the project template). I didn't find an official statement on this (if targeting .NET Core directly and not .NET Standard is also ok - or if this will be supported in the future).
Having said that, I think there is a workaround for your problem. But I am not sure, if this is officially supported or if that will work in the future.
Currently, when you start a build from Visual Studio, Microsoft.NET.Sdk.Functions.Generator.exe is called by the build task (Full Framework EXE). This explains why System.Runtime cannot be loaded. But there is an option to call the .NET Core based generator (from the build task). I didn't find any official reference on this - I just know this from the source code - so please be cautious when using this.
Can you please try to add <UseNETCoreGenerator>true</UseNETCoreGenerator> to your .csproj file:
<PropertyGroup>
...
<UseNETCoreGenerator>true</UseNETCoreGenerator>
</PropertyGroup>
This should call the .NET Core based generator from the build task.
But there is an option to call the .NET Core based generator (from the build task). I didn't find any official reference on this - I just know this from the source code - so please be cautious when using this.
To use the core version of the generator, as @cschwendtner mentioned you can set this UseNETCoreGenerator property. This property was specifically added for the purpose of selecting which generator to use.
@vijayrkn - thanks for the clarification. I was not sure if this setting is officially supported.
Is the intended way to build Function apps (V2) to target .NET Standard or is targeting .NET Core "directly" also ok? I ask because it seems that some people target .NET Core directly (mainly because they want to use .NET Core assemblies) - which leads to this kind of error during generation (without using UseNETCoreGenerator).
Functions apps are supposed to target .NET Standard. If the app targets netstandard either of the generators should be able to generate the functions.
@fabiocav / @ahmelsayed might be able to talk more on what is expectation from runtime time.
But from the build perspective, if the app has .NETCore dependencies, and the build is triggered from full framework msbuild, then right property needs to be set (UseNETCoreGenerator) to use the core generator instead of full framework generator.
https://github.com/Azure/azure-functions-vs-build-sdk/blob/master/src/Microsoft.NET.Sdk.Functions.MSBuild/Tasks/GenerateFunctions.cs#L49
The UseNetCoreGenerator allows a .NET Core 2.0 app targeted framework Azure Function Project to build, but it is crashing at runtime. The Azure Function Host/Cmd window comes up then displays an error message. I can supply my project I am using to replicate this, but it does feel like an Azure Function Project should target 'netstandard20'.
I am using this in the PropertyGroup node of .csproj.
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<AzureFunctionsVersion>v2</AzureFunctionsVersion>
<UseNETCoreGenerator>true</UseNETCoreGenerator>
</PropertyGroup>
So I'm having this same issue targeting net461. I also added the UseNetCoreGenerator and my runtime breaks now. The weird thing is that it is only happening on one of my computers. This same code is on another computer and it compiles fine and runs fine. In fact, I never even got the error that started this thread on my other computer. It only ever occurred on one of my computers. Is there something I should check for on the working computer that is installed that maybe isn't installed on the one that has these errors?
Could not load file or assembly 'System.Runtime, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
SAME ISSUE
Make sure that you run your .net core based assymbly with command dotnet myassembly.dll
Wow this is too bad - Are there plans to support .NET Core directly? /cc @jeffhollan
Spoke briefly to @fabiocav about this the other week as I hit it by referencing my function from an xUnit test project (.netcore2.1) which I solved by having xUnit target frameworks .netcore2.1;.netstandard2.0 — I know this standard / core / framework stuff gets pretty tangled in general but he or others on team would need to chime in on if supporting as target framework directly is coming
Thanks for the pointer and quick assistance @jeffhollan!
This managed to fix it for me:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netcoreapp2.1;netstandard2.0</TargetFrameworks>
</PropertyGroup>
</Project>
Until I tried to restore my dependencies 🙈
I'm having the same issue, but adding the <UseNETCoreGenerator>true</UseNETCoreGenerator> to the csproj did not solve the issue :(
We try to build for
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<UseNETCoreGenerator>true</UseNETCoreGenerator>
Using a default Functions v2 template we're getting an error on one machine like the one called out here but for System.Runtime 4.1.0.0 (vs 4.2.0.0). I haven't added the generator tag or anything, this is the fist time I've ever seen this error in my experience with Functions. Do we have an official solution here? I am seeing mixed results w/ the Generator tag in the history of this issue...
For my scenario, the VS2017 installation was 15.6.7, and adding the UseNETCoreGenerator tag worked, but the exact same solution on my machine (VS2017.15.8.3) did not require the use of this tag.
I updated the problem machine's .Net Core SDK installation (was 2.1.1xx) to the latest (2.1.402) and that didn't help matters (without the tag in place). Note the 15.6.7 version had the latest Functions Core Tools installed (15.9.02009) - which matches what's on my 15.8.3 box - but was still encountering this issue.
Couple of thoughts here:
1) Functions Core Tools should ensure the entire PC environment is fit for usage. This includes .Net Core, VS version, etc. and assert updates where applicable.
2) Core tooling should detect if the environment will need this UseNETCoreGenerator tag and should insert it as part of the template which creates the Function App project
This needs to be resolved in order to unblock https://github.com/Azure/Azure-Functions/issues/805
Experienced the same issue whilst running an xUnit Test (Which cannot be .NetStandard). after attempting to add - <TargetFramework>netstandard2.0, netcoreapp2.0</TargetFramework> it broke the project.assets.json file, after resolving this and returning to <TargetFramework>netcoreapp2.0</TargetFramework>, and adding <UseNETCoreGenerator>true</UseNETCoreGenerator>, the application then builds and fails at runtime with:
[4/10/2018 9:01:31 AM Error] Failed to launch testhost with error: System.AggregateException: One or more errors occurred. ---> System.ArgumentException: Process with an Id of 7624 is not running.
at System.Diagnostics.Process.GetProcessById(Int32 processId, String machineName)
at System.Diagnostics.Process.GetProcessById(Int32 processId)
at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting.DotnetTestHostManager.LaunchHost(TestProcessStartInfo testHostStartInfo, CancellationToken cancellationToken)
at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting.DotnetTestHostManager.<>c__DisplayClass37_0.
at System.Threading.Tasks.Task1.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting.DotnetTestHostManager.<LaunchTestHostAsync>d__37.MoveNext()
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task1.GetResultCore(Boolean waitCompletionNotification)
at System.Threading.Tasks.Task1.get_Result()
at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyOperationManager.SetupChannel(IEnumerable1 sources)
---> (Inner Exception #0) System.ArgumentException: Process with an Id of 7624 is not running.
at System.Diagnostics.Process.GetProcessById(Int32 processId, String machineName)
at System.Diagnostics.Process.GetProcessById(Int32 processId)
at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting.DotnetTestHostManager.LaunchHost(TestProcessStartInfo testHostStartInfo, CancellationToken cancellationToken)
at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting.DotnetTestHostManager.<>c__DisplayClass37_0.
at System.Threading.Tasks.Task`1.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting.DotnetTestHostManager.
[4/10/2018 9:01:31 AM Error] Failed to launch testhost with error: System.AggregateException: One or more errors occurred. ---> System.ArgumentException: Process with an Id of 7624 is not running.
at System.Diagnostics.Process.GetProcessById(Int32 processId, String machineName)
at System.Diagnostics.Process.GetProcessById(Int32 processId)
at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting.DotnetTestHostManager.LaunchHost(TestProcessStartInfo testHostStartInfo, CancellationToken cancellationToken)
at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting.DotnetTestHostManager.<>c__DisplayClass37_0.
at System.Threading.Tasks.Task1.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting.DotnetTestHostManager.<LaunchTestHostAsync>d__37.MoveNext()
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task1.GetResultCore(Boolean waitCompletionNotification)
at System.Threading.Tasks.Task1.get_Result()
at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyOperationManager.SetupChannel(IEnumerable1 sources)
---> (Inner Exception #0) System.ArgumentException: Process with an Id of 7624 is not running.
at System.Diagnostics.Process.GetProcessById(Int32 processId, String machineName)
at System.Diagnostics.Process.GetProcessById(Int32 processId)
at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting.DotnetTestHostManager.LaunchHost(TestProcessStartInfo testHostStartInfo, CancellationToken cancellationToken)
at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting.DotnetTestHostManager.<>c__DisplayClass37_0.
at System.Threading.Tasks.Task`1.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting.DotnetTestHostManager.
Anybody have found any work around ?
I am having the same issue. But in my case I am using T4 Template to generate some CRUD classes. The Assembly that I am trying to load is in the same solution.
"Could not load file or assembly", I tried to apply the tags for net core and standard and did not work.
VS2017 - 15.8.8 - .net core 2.1.
@richimori can you please open an issue with the issue details (including the assembly name), a stack and ideally, a link to a repository with a repro so we can investigate?
@fabiocav This problem still exists on the latest Azure Functions targeting .NET Core 2.1
System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
Using: Microsoft.NET.Sdk.Functions 1.0.24
It happened as soon as I added this to my project AND I tried to use it: Microsoft.Azure.WebJobs.Extensions.Storage 3.0.1 - which depends on .NETStandard 2.0
@zmarty I'm unable to repro what you're describing. Can you please open a new issue with the details and share a repro so we can take a closer look?
@zmarty @fabiocav I had a very similar problem, both with using Microsoft.NET.Sdk.Functions 1.0.23 and with 1.0.24, using .NET Core 2.1. I had a Azure Function project and it had a dependency on another .NET Core 2.1 class library project in the same solution. I changed the .csproj file of the class library project to this:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<!--<TargetFramework>netcoreapp2.1</TargetFramework>-->
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.24" />
</ItemGroup>
</Project>
This seemed to fix the problem. This stopped the error:
System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
Hope this helps you.
@MahmoodAkhtar that should not be a requirement with 1.0.24, can was that just with the out-of-box project template? Would you mind opening a new issue with the details for tracking and include the information from dotnet --info ?
I had the exact same issue as @MahmoodAkhtar, and the suggestion to change the targetFramework to netstandard2.0 fixed it as well.
@MahmoodAkhtar @bryanllewis this behavior is surprising. It would be really helpful if you're able to find and share a simplified repro. If you do so, it would be best to file it as a new issue and to update this issue with a link.
AF-160-repro.zip
Hi @paulbatum ,
Attached is a simple solution that shows the issue. The Functions project references a shared class library, that uses ILogger.
FunctionApp1.csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<AzureFunctionsVersion>v2</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.26" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ClassLibrary1\ClassLibrary1.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
ClassLibrary1.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.26" />
</ItemGroup>
</Project>
Build error:
0>C:\Users\USERNAME\.nuget\packages\microsoft.net.sdk.functions\1.0.24\build\netstandard1.0\Microsoft.NET.Sdk.Functions.Build.targets(41,5): Error: System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
File name: 'System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
at System.Reflection.RuntimeAssembly.GetExportedTypes(RuntimeAssembly assembly, ObjectHandleOnStack retTypes)
at System.Reflection.RuntimeAssembly.GetExportedTypes()
at MakeFunctionJson.FunctionJsonConverter.TryGenerateFunctionJsons()
at MakeFunctionJson.FunctionJsonConverter.TryRun()
Any help is appreciated.
Thanks.
Ditto for the problem that @scraperg describes above. I have nothing but reference issues using this library, and they seem to resurface any time I change any other references in any project. As soon as I add <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.28" /> to a project, I get the System.Runtime 4.2.1.0 build error.
Thank you @scraperg for the repro, sorry for the lack of response. Thank you @jeffputz for replying and grabbing my attention.
I can confirm that I get the same error from the repro zip on my machine. @fabiocav is going to take a look.
So I found I was able to put this repro into a working state by removing the reference to Microsoft.NET.Sdk.Functions from the class library and replacing it with a reference to Microsoft.Extensions.Logging 2.1.0. Here is the updated csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.1.0" />
</ItemGroup>
</Project>
In general, you probably do not need to reference Microsoft.NET.Sdk.Functions from your class libraries, because it is a metapackage designed to pull in all the necessary dependencies for a function app and provide build time support. This is similar to how you would not generally reference Microsoft.AspNetCore.All from a class library. If you have specific reasons for referencing Microsoft.NET.Sdk.Functions from your class libraries, please share them.
All of that said, I'm still not sure why it blows up with that error...
Okay, more progress after chatting with @fabiocav :)
Our build task is attempting to run functions V1 build task for this repro because the class library is missing the <AzureFunctionsVersion>v2</AzureFunctionsVersion> setting. Simply adding that is another way to fix this repro:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<AzureFunctionsVersion>v2</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.26" />
</ItemGroup>
</Project>
However we do NOT recommend this fix for the reasons I mentioned in my previous reply. The recommended approach is to reference Microsoft.NET.Sdk.Functions only from your function app project.
@paulbatum Ah... I didn't even realize that was a meta reference. Where is that defined in code? I can definitely decompose and likely use a small number of the included references to make things work the way I'd like (get functions into a class library that isn't a functions project).
Its just a NuGet package reference. There is nothing in the code.
Can you elaborate a little more on your scenario? Are you trying to put function definitions into class libraries and then reference them from multiple function apps?
Yes, exactly that.
OK, so yes, I can put the functions in a shared class library (and the intent here in part is so that they can be distributed via a nuget package), and they'll compile as long as I have these refs:
<PackageReference Include="Microsoft.Azure.WebJobs" Version="3.0.8" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="3.0.6" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions" Version="3.0.2" />
But there has to be another step, because the tooling in a functions project referencing the shared library won't generate any of the json files that the runtime needs to "find" the functions. Running locally, the console will say there are no jobs found.
Got it. For this particular scenario, if you try the other approach I mentioned (specifying V2 in the csproj), does that work for you?
I think @fabiocav has some ideas on how we could improve our handling of this scenario, I'll let him comment.
No, it's already set in the functions project. All I did was move the function classes to the shared library and add the above references. My suspicion is that the SDK doesn't traverse the referenced projects/packages looking for functions to gen the function.json files, it only looks in the project itself.
@jeffputz your suspicion is correct. This is what we're planning to address. I've updated an existing issue we have tracking this and assigned to the upcoming milestone, so you can track that for updates https://github.com/Azure/azure-functions-vs-build-sdk/issues/274
@fabiocav I don't see any roadmap or release schedule... do you need some help?
For those who is still struggling. Explicitly adding System.Runtime NuGet package to the project (Azure Function) seemed to resolve this issue for me.
<PackageReference Include="System.Runtime" Version="4.3.1" />
I was also having this problem. I created a function using VS2019 for Mac and then pulled the source down to my Windows laptop and it wouldn't compile giving me the System.RunTime Error.
Fixed it by adding the v2 in the AzureFunctionsVersion which was blank.
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<AzureFunctionsVersion>v2</AzureFunctionsVersion>
</PropertyGroup>
If the last two suggestions alone doesn't help you, try updating the Microsoft.NET.Sdk.Functions package from 1.0.29. That fixed the build issue for me.
I'm seeing a related warning message in my output to this which hasn't been referenced yet in this thread...
[8/12/2019 7:47:35 PM] Exception during runtime resolution of assembly 'System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a': 'System.InvalidCastException: [A]System.AppDomain cannot be cast to [B]System.AppDomain. Type A originates from 'System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' in the context 'Default' at location 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\2.0.9\System.Private.CoreLib.dll'. Type B originates from 'System.Runtime.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' in the context 'Default' at location 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\2.0.9System.Runtime.Extensions.dll'.
[8/12/2019 7:47:35 PM] at Microsoft.Azure.WebJobs.Script.Description.FunctionAssemblyLoader.ResolveAssembly(Object sender, ResolveEventArgs args) in C:\azure-webjobs-sdk-script\src\WebJobs.Script\Description\DotNet\FunctionAssemblyLoader.cs:line 66'
[8/12/2019 7:47:35 PM] Unable to find assembly 'System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Are you missing a private assembly file?
I tried using <UseNETCoreGenerator>true</UseNETCoreGenerator>, but had no effect. Anyone else seeing this in the logs when running?
for me it's been a matter of replacing the blank value I had on this setting with v2
<AzureFunctionsVersion>v2</AzureFunctionsVersion>
for me it's been a matter of replacing the blank value I had on this setting with v2
<AzureFunctionsVersion>v2</AzureFunctionsVersion>
Worked for me too.
Interestingly enough - I use both Rider and VS 2019. I do not get this problem with Rider.
PM> Add-Migration
位于命令管道位置 1 的 cmdlet Add-Migration
请为以下参数提供值:
Name: 1
System.IO.FileLoadException: Could not load file or assembly 'System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
at System.ModuleHandle.ResolveMethod(RuntimeModule module, Int32 methodToken, IntPtr* typeInstArgs, Int32 typeInstCount, IntPtr* methodInstArgs, Int32 methodInstCount)
at System.ModuleHandle.ResolveMethodHandleInternalCore(RuntimeModule module, Int32 methodToken, IntPtr[] typeInstantiationContext, Int32 typeInstCount, IntPtr[] methodInstantiationContext, Int32 methodInstCount)
at System.ModuleHandle.ResolveMethodHandleInternal(RuntimeModule module, Int32 methodToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
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(RuntimeType type, RuntimeType caType, Boolean inherit)
at System.Attribute.GetCustomAttributes(MemberInfo element, Type type, Boolean inherit)
at System.Attribute.GetCustomAttribute(MemberInfo element, Type attributeType, Boolean inherit)
at System.Reflection.CustomAttributeExtensions.GetCustomAttributeT
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.<>c.
at System.Linq.Enumerable.WhereSelectListIterator2.MoveNext()
at System.Linq.Enumerable.WhereEnumerableIterator1.MoveNext()
at System.Linq.Enumerable.ConcatIterator1.MoveNext()
at System.Linq.Enumerable.DistinctIterator1.MoveNext()
at System.Linq.Enumerable.WhereEnumerableIterator1.MoveNext()
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.FindContextTypes()
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.FindContextType(String name)
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(String contextType)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_01.
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Could not load file or assembly 'System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
I was also having this problem when i use "ef Add-Migration"
Hello, i'm experimenting the same issue in Visual studio 2019 (with all the latest update at the 10 november 2019)
i have a .NET core dll project and a MS Test for .NET framework in the same solution: i know that is not good to mix .NET framework and .NET Core but i havo no choice as in my automatic testing i have to process excel files and the Datasource tag is not (yet?) supported by .NET core.
When i try to execute my test i get:
Test method UnitTestProject5.UnitTest1.TestMethod1 threw exception:
System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
it seems that the testing project is looking for a version of the assembly System.Runtime that is not (still?) available in .NETCore: i tried to switch from .NET COre 3 to .NETCore 2 but no luck.
Any workaround? many thanks in advance
@Kedr91 Is the .NET Core dll project you mentioned a function app project? If you are getting this error for a scenario that does not involve Azure Functions then we cannot really help with that.
omg.... .net core is a catastrophe !!! nothing is compatible with anything. I can't do any real world application.
It's not THAT bad, come on :) What is the specific problem you are having?
It's not THAT bad, come on :) What is the specific problem you are having?
I tried to use EF with azure function. after 2 weeks strugelling with it I didn't get anywhere
each of these have a different issue, such as asking for a missing lib with a specific version which is not available on nuget anymore
@daniel-refahi there was an issue recently addressed (fix in an upcoming deployment) that could have caused what you're describing above under certain conditions. If you don't mind, could you please open a separate issue with a repro so we can validate against your specific scenario and make sure it has been addressed by this fix?
I just wonder if i can use a .net core class library dll function in .net framework project. So I create 2 projects. These 2 projects are almost empty. I did not add any additional packages. I just add my .net core dll to .net framework 4.7.2 project. But I encounter this error. I read all comments above and tried but it didn't worked. Still I have this error. What is the reason for this error? Why can't we use core dll in framework project easily. This couldn't be so hard :)
When starting NUnitLite 3.12.0
I also get the error message
Assembly "System.Runtime, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
was not found (in german)
I have a very small project to find out problems of this kind while setting up my developing tools...
@jpr65 would you mind opening another issue and sharing the details and your repro?
@cansuk can you please share more details in a separate issue as well?
Hello,
my targeting framework is:
I'm still seeing this issue looking for System.Runtime.dll. Any fixes?
Most helpful comment
@Matthewsre - sorry for the late reply.
I think the intended way to build Function apps is to target .NET Standard (currently netstandard 2.0 - looking at the project template). I didn't find an official statement on this (if targeting .NET Core directly and not .NET Standard is also ok - or if this will be supported in the future).
Having said that, I think there is a workaround for your problem. But I am not sure, if this is officially supported or if that will work in the future.
Currently, when you start a build from Visual Studio,
Microsoft.NET.Sdk.Functions.Generator.exeis called by the build task (Full Framework EXE). This explains whySystem.Runtimecannot be loaded. But there is an option to call the .NET Core based generator (from the build task). I didn't find any official reference on this - I just know this from the source code - so please be cautious when using this.Can you please try to add
<UseNETCoreGenerator>true</UseNETCoreGenerator>to your .csproj file:This should call the .NET Core based generator from the build task.