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

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

Closed
khariq opened this issue May 16, 2017 · 9 comments

Comments

@khariq
Copy link

khariq commented May 16, 2017

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
@dcarr42
Copy link

dcarr42 commented May 16, 2017

Maybe a better question is why do you need to take a dependency on Newtonsoft...

@khariq
Copy link
Author

khariq commented May 16, 2017

Still the same issue. We took the dependency to force the version of Newtonsoft to the exact same one that serialized the data on the source side. Unnecessary, I know, but we were grasping at straws.

@dcarr42
Copy link

dcarr42 commented May 16, 2017

Also is core supported inside Azure Functions. Try net46 just to be on the safe side.

@dcarr42
Copy link

dcarr42 commented May 16, 2017

@fabiocav
Copy link
Member

@khariq Azure Functions only supports the net46 target.

You may have problems with your external reference as .NET Standard 1.3 is the highest supported by the runtime. Just want to clarify your comment on top, though; are you sure your assembly is not targeting .NET Standard 1.1?

@khariq
Copy link
Author

khariq commented May 16, 2017

@fabiocav It is target .NetCore1.1 I changed the framework to 1.0 (which from my understanding is in 1.3?) and the error still occurs. I also deleted project.json to make sure the framework reference is gone.

@fabiocav
Copy link
Member

This might be helpful:
https://docs.microsoft.com/en-us/dotnet/articles/standard/library#net-platforms-support

In order to use your assembly in functions, you need to target netstandard 1.3 (maximum). Or .NET Framework 4.6

@dcarr42
Copy link

dcarr42 commented May 16, 2017

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

@khariq
Copy link
Author

khariq commented 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.

@khariq khariq closed this as completed May 17, 2017
@ghost ghost locked as resolved and limited conversation to collaborators Jan 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants