ASP.NET, Как добавить блок в web.config?

Я использовал бы метод SingleOrDefault.

var user = (from u in dc.Users
                   where u.UserName == usn
                   select u).SingleOrDefault();
5
задан JoshL 12 November 2013 в 19:01
поделиться

5 ответов

Are all of projA's dependencies in projB? Usually I'd just add a reference from one project to another if they are in the same solution.

Edit:

If you want to add an assembly dynamically then maybe a service reference maybe something to consider. By dumping in projA's DLL into the bin that doesn't really give all the DLLs that it may require, thus there are ways to tie things together so that objects can be understood across systems, like web services using XML to give a common example.

My question back about adding an assembly dynamically is where would you get it from and can that part be automated to be part of projB as that is really the general solution to this kind of problem.

Edit 2:

How could you get all of projA's dependencies? Is it possible to get it so that it doesn't depend on a bunch of other DLLs that may or may not be on the system that this is to run. That is what the error is telling you, that there exists some assembly projC that is also required. Note that this adding of assemblies can continue for a long time if there are many levels of dependencies used.

Summarizing the answer: What would you need to reference in order to load projA into some new project? That's your problem which without knowing what the dependencies look like is rather hard to answer directly.

7
ответ дан 18 December 2019 в 13:16
поделиться

You do not need to add anything in Web.config if the assembly DLL is in the Bin folder - you only need to do this if you are referencing an assembly that is in the GAC.

The error message you are getting is basically saying that the assembly can't be found in the GAC, which is presumably because it isn't there!

4
ответ дан 18 December 2019 в 13:16
поделиться

You don't need to manually add the reference in the web.config file. Right click on your project in the Solution Explorer window in Visual Studio and select 'Add Reference'. Go to the Browse tab and find the DLL you created in the other project, select it and click OK. Optionally, you can add the project A to the same solution as project B and then add the reference through the Projects tab of the Add Reference window.

3
ответ дан 18 December 2019 в 13:16
поделиться

Ошибка

Манифест обнаруженной сборки определение не соответствует сборке ссылка.

предполагает, что DLL была найдена, но не соответствует версии или открытому ключу. Я бы посоветовал дважды проверить, чтобы ссылка на сборку соответствовала информации о версии и что в путях / bin или в GAC

не было вредоносных DLL со старыми номерами версий.
0
ответ дан 18 December 2019 в 13:16
поделиться

Well, I guess to some extent it depends on what you are planning on doing once you've loaded the assembly, and what you've got in the assembly.

I'll assume you've got some sort of plugin architecture, with a known interface or base class that you're going to be calling methods on, lets say IPlugin.

Anyway, here's how to load an assembly dynamically, based on storing a reference to it in either a config section or a DB column somewhere:

private IPlugin LoadPlugin(string fullTypeName) {
  Type type = Type.GetType(fullTypeName, false, true);

  Object plugin = Activator.CreateInstance(type);

  if (plugin is IPlugin) {
    return (IPlugin) plugin;
  }

  // Handle the fact you've not got what you expected however you like
  throw new ApplicationException(error);
}

So this will take a string such as "projA.PluginClass, projA, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" load the assembly, and return you an instance of the class you're interested in.

You would then use it like this:

// Call to DB to get details of class and assembly
string pluginClass = GetPluginDetails();

IPlugin plugin = LoadPlugin(pluginClass);

// Call known method to do something on IPlugin
plugin.SomeMethod();
0
ответ дан 18 December 2019 в 13:16
поделиться
Другие вопросы по тегам:

Похожие вопросы: