12

I'm trying to move assembly redirects from web.config into an external file. The reason for it is that I want to keep binding redirect in one place and use it on both debug and production configurations.

It sort of works, but I'm strugling with specifying relative paths.

<configuration>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <!-- this works, but forces me to use the same path on dev and production machines -->
    <linkedConfiguration href="file://c:\data\web.runtime.config"/>

    <!-- none of those works -->
    <linkedConfiguration href="file://web.runtime.config"/>
    <linkedConfiguration href="file://..\web.runtime.config"/>
    <linkedConfiguration href="file://~/web.runtime.config"/>
  </assemblyBinding>
</configuration>

I want to keep the web.runtime.config in the same folder as the rest of the web application. Is it possible to specify a relative path in linkedConfiguration element?

More info: I've tested it with IIS Express and ASP MVC application in VS 2015. When monitoring file accesses using SysInternals Process Monitor relative pathes seems to resolve to \\web.runtime.config (an invalid network path), while when using the absolute path no leading \\ is added.

5
  • Have you found a solution? Commented Nov 17, 2017 at 2:43
  • 1
    No. I've used alternative approach. Binding redirect is in a single source file and both debug and production configs are generated using web.config transformation. Commented Nov 17, 2017 at 10:56
  • Can you show the structure of RuntimeConfiguration.xml? I'm struggling with the same problem and I'm not sure if my RuntimeConfiguration.xml is correct Commented Apr 19, 2019 at 10:35
  • Can you show the contents of web.runtime.config? I am struggling to get this file structured properly Commented Aug 28, 2020 at 13:24
  • Here's the runtime.config file format: <?xml version="1.0" encoding="utf-8"?> <configuration> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> Commented Oct 10 at 16:01

2 Answers 2

5

I found a way to specify relative path.

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <linkedConfiguration href="file:./RuntimeConfiguration.xml"/>
</assemblyBinding>
Sign up to request clarification or add additional context in comments.

5 Comments

not sure why it was downvoted, because it is actually works. You can even remove ./ and use file:bindings.config
@JoshMouch Did you ever find a solution? we have the same exact issue right now with asp.net core 2.1
My solution was to add some code to the start of the project that made it so you no longer need the AssemblyBindings at all (or at least most of them). It handles the assembly resolve event and tells it to just use whatever version is in the BIN. See: stackoverflow.com/questions/325788/…
You probably don't want to do that, it will load the assembly into a different context using Assembly.LoadFrom versus Load.. learn.microsoft.com/en-us/dotnet/framework/deployment/…
Relative path works for normal app.config, but not for web.config. And i found @JoshMouch 's way works greatly.
1

File web.runtime.config must be in bin dir.

And with href="file:web.runtime.config" it will be work

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.