locked
How to point to Custom DLLs RRS feed

  • Question

  • User248267340 posted

    I wrote a website in aspx, using Visual Studio. I downloaded a few packages to get the NewtonSoft library, and other DLLs for tokens. My project uses JsonArrays a lot.

    The DLLs are in "bin", and in my codebehind file I  have references like this: "Using NewtonSoft.Json;" for example.

    But when I deploy all the files to an IIS environment, I get Error CS0246, can't find the NewtonSoft library and others. My project runs well except for this one issue - not finding 3rd party DLLs.

    I've read a lot of Stackoverflow articles, but they mostly talk about setting paths in VS. But once I deploy, there's no VS. So I'm not understanding something maybe.

    If my Default.asps.cs file has "Using Newtonsoft.Json" and my directory has a fully populated "bin" folder, then why can't it find the DLLs?

    Monday, April 5, 2021 11:59 PM

Answers

  • User753101303 posted

    Hi,

    myapp was added as a new *application* as well? Could it be that IIS looks at top-level directory/bin rather than to top-level directory/myapp/bin ?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 7, 2021 7:39 AM

All replies

  • User-1330468790 posted

    Hi coreysan,

     

    The error tells that you don't output the library to the target bin folder.

    I think we need to target the problem first. Have you checked if the target bin folder contains the 'NewtonSoft.Json' assemby or not?  (Open the bin folder under the publish folder) 

    Before that, could you please tell me the steps that you add the NewtonSoft library in your project?

     

    The common way that we add references in VS is to right click the "References" section in Solution Explorer and add the assembly. Moreover, you need to make sure that the "Copy Local" is set to "True".

     

    Best regards,

    Sean

    Tuesday, April 6, 2021 3:38 AM
  • User248267340 posted

    Sean, I appreciate your input - thank you! This is my first time deploying a VS project to an IIS server, so I realize I have much to learn. But here goes:

    1. I built an application using Visual Studio 2019 on my local desktop. It was necessary to use a C# template with Json objects. So, I made use of NuGet packages to download NewtonSoft, and other packages as well, for tokenization. The app runs perfectly in VS2019 on my desktop. All files are in the proper locations according to how VS 2019 lays it out.
    2. Next, I ran the VS publisher and directed the output to a folder. I did this so I could view the contents of "bin" and review everything. Once all the files were verified, I copied them all to our IIS server. Note: I didn't have VS 2019 publish directly to the IIS server. I manually copied the entire output folder from the work the publisher did. If using Web Deploy is better, I can try it. Its just that the IIS Server is more of an intranet server, and I have limited access. That's why I typically just copy aspx files over.
    3. Finally, on the IIS server I have several apps, all doing different things, so I have a top-level menu to direct the user to the right app. In this case, the menu references the appropriate folder and the Default.aspx file in that folder for this project.
    4. This is where the trouble starts. I have other directories with aspx apps that work just fine. This one is different in the sense that it uses 3rd party DLLs, whereas the others do not. So, when I run the app, I get "not found" errors for the 3rd party libraries, even though it's clearly obvious that the DLLs are sitting right there in the "bin" directory. For this project, everything is laid out like this:

    top-level directory/index.html

    top-level directory/myapp (not the real name, but you get the idea)

    top-level directory/myapp/Default.aspx and Default.aspx.cs

    top-level directory/myapp/bin

    top-level directory/myapp/bin/Newtonsoft.Json.dll

    etc.

    The top-level index.html has a link to:

    top-level directory/myapp/Default.aspx

    Inside the Default.aspx.cs file, I have references like this: "using Newtonsoft.Json;"

    I don't know why running the app doesn't see the DLLs in the bin directory. That's my core problem. Do these DLLs need to be registered somehow? I know that some articles on StackOverflow talk about gacutil.exe, but I've never used that program before.

    I'm sure I'm missing an important step, but I have no idea what it is!

    Tuesday, April 6, 2021 4:10 PM
  • User-1330468790 posted

    Hi coreysan,

     

    Thank you very much for detailed information.

     

    I don't think you miss steps based on your description. By the way, what is the exact error message? Is it for namespace or type?

    According to this documentation: Compiler Error CS0246, the error could be various for different situations.

      

    Here we can adopt some solutions to narrow down the problem.

    1. Permission issue. You can directly copy the output folder to "wwwroot" (by default it has all privileges for web sites) as a separate project and test if the issue still exists.  If the assembly works in that place, it might be a permission issue.
    2. BindRedirect. You could check the web.config file under the "myapp" to see if there is a setting of BindingRedirect for NewtonSoft.Json as below. If not, you could try to add them.
       <runtime>
          <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
            <dependentAssembly>
              <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
              <bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
            </dependentAssembly>
          </assemblyBinding>
        </runtime>

     

    Best regards,

    Sean

    Wednesday, April 7, 2021 6:42 AM
  • User753101303 posted

    Hi,

    myapp was added as a new *application* as well? Could it be that IIS looks at top-level directory/bin rather than to top-level directory/myapp/bin ?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 7, 2021 7:39 AM
  • User248267340 posted

    Sean,

    Again - thank you so much for your assistance. I'm more than grateful!

    I do have the reference to BindingRedirect in the Web.Config file. But before I go any further, I learned something from the other reply by PatriceSC. I got much better behavior when I moved the "bin" folder up one level. It resolved the NewtonSoft message! Now it says it can't find the System.Het.http assembly. So I'll see if I can add that and see what happens!

    Wednesday, April 7, 2021 4:58 PM
  • User248267340 posted

    PatriceSc, I mentioned to Sean that I had the "bin" folder down a level. When I moved it up one level as you suggested, I got much better behavior. So your suggestion might be the very fix I need.

    I need to also add the "System.Net.http" assembly as well. I'll test some more before I conclude this thread.

    Thank you for your suggestion! So simple!

    Wednesday, April 7, 2021 5:09 PM
  • User248267340 posted

    Spot on! That was it. I didn't know that "bin" had a default location.

    Is there any way to tell IIS that for this app, the bin folder has been moved elsewhere? I can leave "bin" where it is, but I'd like to move it if possible. I've tried several different ways in the web.config, but I haven't figured it out yet.

    Corey

    Wednesday, April 7, 2021 6:01 PM
  • User-1330468790 posted

    Hi coreysan,

     

    Have you tried to use below element?

    <assemblyBinding> Element for <runtime>

     

    Under this element, there is an element called: <probing> Element

    It specifies application base subdirectories for the common language runtime to search when loading assemblies.

    For example, you will search for assemblies from below paths one by one. bin, bin2\subbin and bin3

    <configuration>  
       <runtime>  
          <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">  
             <probing privatePath="bin;bin2\subbin;bin3"/>  
          </assemblyBinding>  
       </runtime>  
    </configuration>  

     

    Best regards,

    Sean

    Tuesday, April 13, 2021 5:44 AM
  • User248267340 posted

    Sean,

    Thanks - good to hear from you. I tried using probing PrivatePAth as you recommended, but without success!

    Right now I'm using the bin folder at the top level to get it working, but someday it would be nice to point to a subfolder location.

    Tuesday, April 13, 2021 8:35 PM
  • User753101303 posted

    It was just to understand what happens but not how I would suggest to fix that. More likely tou just added folders and so you actually have a single application.

    Instead you can use https://www.helpmasterpro.com/helpfile/Web%20Modules/html%20files/Virtual%20Directory%20-%20creating%20in%20iis7.htm so that those new folders are actually REAL web applicaitons on their own. If the app is well written, it should work quite well. At worst you'll may need to fix links so that they are relative to the root of the web app rather than to the root of the web site.

    Edit for example you can have folders such as c:\main, c::\app1, c:\app2, c:\app3 where each app in its own folder.

    The site points to the c:\main folder which is basically and empty app. You can use the link above to create new applications pointing each to its own folder.

    As a result you have a http://main.com site and then you have http:://main.com/app1, http://main.com/aoo2 etc.. each being a separate web application.

    Tuesday, April 13, 2021 8:55 PM