question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Azure Functions: Exception while executing function: unable to find assembly 'System.Runtime, Version=4.1.0.0'

See original GitHub issue

When attempting to use JsonConvert to deserialize a Service Bus message to a domain POCO, the following exception is through:

Unable to find assembly ‘System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’. Are you missing a private assembly file?

Repro steps

#r "Newtonsoft.Json"
// Entities.dll is a netcoreapp1.1 assembly that defines our business POCOs
#r "Entities.dll"

using System;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;

using Entities.Messages;
 
public static string Run(byte[] evaluationRequest, TraceWriter log)
{
	var body = System.Text.Encoding.UTF8.GetString(evaluationRequest);

	log.Info($"C# ServiceBus queue trigger function processed message: {body}");
	    
    try
    {
    	// EvaluationRequest is defined in Entities.dll in the Entities.Messages namespace
    	// commenting this line out prints the log message
        var message = JsonConvert.DeserializeObject<EvaluationRequest>(body);
    }
    catch (Exception ex)
    {
        log.Info($"Bad invocation {ex.Message}");
    }    

    return "200";
}


// Bringing the Object Graph into a types.csx file and loading it results in a successful deserialization

// POCO from Entities.dll
public class EvaluationRequest 
{
	// Standard System.Guid
	public Guid Measure { get; set; }		
	// Another object in the Entities DLL
	public Patient Patient { get; set; }
	// An Enum		
	public Application ApplicationId { get; set; }

	public string ClientId { get; set; }
}

Provide the steps required to reproduce the problem

  1. Create the function above
  2. Comment out the body of the try…catch block
  3. Execute function and the function succeeds and the log message is printed.
  4. Uncomment the try…catch block
  5. Execute the function and the exception is thrown, but no log message is printed (this makes us think it has something to do with the JIT compiler).

Expected behavior

The string should be deserialized to the POCO.

Actual behavior

2017-05-16T18:51:10.477 Function started (Id=21f3f001-cab2-49ff-84b7-d531a5d667a5) 2017-05-16T18:51:10.477 Unable to find assembly ‘System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’. Are you missing a private assembly file? 2017-05-16T18:51:10.477 Function completed (Failure, Id=21f3f001-cab2-49ff-84b7-d531a5d667a5, Duration=2ms)

Related information

project.json contents:

{
	"dependencies": {
		"Newtonsoft.Json" : "10.0.2"
	},
	"frameworks": {
		"netcoreapp1.1": {
			
    	}
 	}
}
  • Programming language used C#, .csx, Azure Functions
  • Links to source

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
khariqcommented, May 17, 2017

@fabiocav @dallancarr Thank you both your patient explanations. I’ve changed my assemblies to target .Net Standard 1.3 on build. I was convinced you were talking about changing the project.json file.

1reaction
dcarr42commented, May 16, 2017

@khariq fabio is suggesting you need to target net46 or netstandard up to 1.3.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Could not load file or assembly 'Microsoft.Extensions. ...
The Azure Function was running fine locally however in Azure DevOps pipeline I was getting the error described by the OP. I noticed...
Read more >
Azure Functions How to fix Could not load file or assembly ...
Tokens. When this chunk of code runs I am getting the error "Could not load file or assembly 'Microsoft.IdentityModel.Tokens, Version=6.30.
Read more >
Could not load file or assembly 'Microsoft.IdentityModel. ...
Exception message is : Exception while executing function: GetTaskCounts Could not load file or assembly 'Microsoft.IdentityModel.Clients.
Read more >
What causes the runtime to try and bind with the lowest ...
I am working on an Azure function project in a Class Library project that targets .NET Standard 2.0. I am using the following...
Read more >
So You Want to Run Azure Functions Using .NET 5
Trying to convert Azure Functions over to .NET 5 isn't as well supported as you might expect yet. Here's what you need to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found