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

F# dotnet 8 isolated not working with attributes #73

Open
helgeu opened this issue Dec 6, 2024 · 9 comments
Open

F# dotnet 8 isolated not working with attributes #73

helgeu opened this issue Dec 6, 2024 · 9 comments

Comments

@helgeu
Copy link
Contributor

helgeu commented Dec 6, 2024

We are using f# and Darkloop extension and this works very nicely with Azure functions in process mode. We are now moving over to dotnet 8 and isolated but this seems to not work as expected.

I have created a PR with basic code for same F# code as in the C# samples. The expected is that this should give 401s but the attribute is not at all honored as with this code.

Thanks for your great work btw!

@helgeu
Copy link
Contributor Author

helgeu commented Dec 6, 2024

Pull request here: #74

@miikka-valkonen
Copy link

miikka-valkonen commented Dec 9, 2024

I am having the same problem. It seems that FunctionsAuthorizationExtensionStartup is not configured on startup, when F# is used. Somehow the F# isolated worker model startup is not as automatic as with C#.

I am currently trying to manually configure the mentioned extension, but it is a bit problematic due to classes/extensions being internal in DarkLoop.

EDIT:
I got the thing working! The extension needed to be manually configured with the following:
.ConfigureFunctionsWebApplication(fun builder ->
FunctionsAuthorizationExtensionStartup().Configure(builder)
builder.UseFunctionsAuthorization() |> ignore)

The code is not pretty, as the FunctionsAuthorizationExtensionStartup is a public class, which needs to be initialized for nothing here. DarkLoop would need some extension method for F# configuration to make it prettier, but at least this seems like a workaround for the problem.

@helgeu
Copy link
Contributor Author

helgeu commented Dec 9, 2024

I will update my Sample for F# code with this. Great find @miikka-valkonen ! Thanx!

@helgeu
Copy link
Contributor Author

helgeu commented Dec 9, 2024

The sample is updated with working code as per now. Not sure if this issue is still valid, whether it as a F# problem or a Darkloop functions authorize problem so you may decide to close this issue @artmasa as it is working. Although the documentation should reflect this related to Azure Functions and F#. Added one line to the documentation for F#.

@artmasa
Copy link
Contributor

artmasa commented Dec 9, 2024

@helgeu, this is awesome! I will merge soon.
This has to be an F# problem, as this registration happens dynamically through discovery on the WorkerExtensionsStartupAttribute for C#

@artmasa
Copy link
Contributor

artmasa commented Dec 9, 2024

@helgeu and @miikka-valkonen, just curious, do other functions extensions require the same (manual registration)? I'm wondering if something is missing in this package for auto-discovery in F#

@helgeu
Copy link
Contributor Author

helgeu commented Dec 9, 2024

I made this code work on @miikka-valkonen. @miikka-valkonen did find something around this related to other triggers in Azure functions. He may have some more background info and could possibly add to this issue with some links or otherwise?

@artmasa
Copy link
Contributor

artmasa commented Dec 9, 2024

It seems this limitation is due to F# code not being compiled with roslyn, which detects all the startup attributes involved in solution at compile time and generates initialization code when compiling your project.
Here is one issue explaining the problem.
This other issue is still open because of the same reason.

I think this project will need to include extension method to handle this in a more elegant way.

@miikka-valkonen
Copy link

miikka-valkonen commented Dec 9, 2024

@artmasa @helgeu I don't think there is anything auto-discovery related missing from this package. Microsoft has stated the following: "If you're writing your application using F#, some trigger and binding extensions require extra configuration.". Statement is rather vague, but in general F# func apps are required to do some configurations manually, for example here is what MS says you must declare in startup for using Blob Storage binding w/ F#:

let hostBuilder = new HostBuilder()
hostBuilder.ConfigureFunctionsWorkerDefaults(fun (context: HostBuilderContext) (appBuilder: IFunctionsWorkerApplicationBuilder) ->
    appBuilder.ConfigureBlobStorageExtension() |> ignore
) |> ignore

These additional F# configuration calls always reside in ConfigureFunctionsWorkerDefaults/ConfigureFunctionsWebApplication. I think that MS has added that ConfigureBlobStorageExtension in the example just for F# func apps. I don't think MS is going to provide the same auto-discovery support for F#, like it is in C#, as they are stating these things. You are instead supposed to add extension methods to perform the startup of extensions/bindings.

.... and now I see what @artmasa just found out and commented, which is probably the answer as to why the situation is like I stated above. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants