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

Avoid Assembly.Location not returning correct value issue #3

Merged
merged 1 commit into from Dec 27, 2016

Conversation

Projects
None yet
1 participant
@guitarrapc
Owner

guitarrapc commented Dec 27, 2016

Description of Issue

refer : Azure/azure-functions-host#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

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