Avoid Assembly.Location not returning correct value issue #3

Merged
merged 1 commit into from Dec 27, 2016

Projects

None yet

1 participant

@guitarrapc
Owner
guitarrapc commented Dec 27, 2016 edited

Description of Issue

refer : Azure/azure-webjobs-sdk-script#1073

Error Message

Can't create a metadata reference to an assembly without location.
  at Microsoft.CodeAnalysis.MetadataReference.CreateFromAssemblyInternal(Assembly assembly, MetadataReferenceProperties properties, DocumentationProvider documentation)
  at Microsoft.CodeAnalysis.Scripting.ScriptOptions.CreateReferenceFromAssembly(Assembly assembly)
  at Microsoft.CodeAnalysis.Scripting.ParameterValidationHelpers.<>c__DisplayClass4_0`2.<SelectChecked>b__0(T item)
  at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
  at Microsoft.CodeAnalysis.Scripting.ParameterValidationHelpers.AddRangeChecked[T](ArrayBuilder`1 builder, IEnumerable`1 items, String parameterName)
  at Microsoft.CodeAnalysis.Scripting.ParameterValidationHelpers.ToImmutableArrayChecked[T](IEnumerable`1 items, String parameterName)
  at Microsoft.CodeAnalysis.Scripting.ScriptOptions.WithReferences(IEnumerable`1 references)
  at Microsoft.CodeAnalysis.Scripting.ScriptOptions.WithReferences(IEnumerable`1 references)
  at Submission#0.<EvaluateCSharpAsync>d__3.MoveNext() in D:\home\site\wwwroot\CSharpScripting.csx:line 47

How to avoid

Change DLL location

Workaround 1 -- Move the assembly to a different folder: works great!

Just change from {function}\bin\MyExtensions.dll to ..\sharedlib\MyExtensions.dll, and reference dll by function from #r "MyExtensions.dll" to #r "..\sharedlib\MyExtensions.dll". It avoid issue at all.

Since there are restriction for reference dll should locate inside fuction's bin.

If you need to reference a private assembly, you can upload the assembly file into a bin folder relative to your function and reference it by using the file name (e.g. #r "MyAssembly.dll"). For information on how to upload files to your function folder, see the following section on package management.
https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-csharp

But it seems not for now any more. I can place my dll anywhere and can be reference from function. Wow, great.

DO NOT

Workaround 2 -- Revert to the previous Functions version:

This cause all function disappear and need redeploy. I think it have some risk.

@guitarrapc guitarrapc merged commit 7a3ab4c into master Dec 27, 2016
@guitarrapc guitarrapc deleted the AvoidDllLocationIssue branch Dec 27, 2016
@guitarrapc guitarrapc referenced this pull request in Azure/azure-webjobs-sdk-script Dec 27, 2016
Open

Assembly.Location not returning correct value #1073

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment