Rules for assembly environment - .net-core

Is there a way, using attributes or something, to contract/specify what kind of projects that can reference an assembly (project)? For example I create an assembly, and I want to make sure that it is not referenced from an environment running as web assembly in a browser.

Related

Debugging ASP.NET web service, C++/CLI DLL, and native DLL in Visual Studio 2008

I have a VS2008 solution with three projects: C# ASP.NET web service, which is using C++/CLI DLL, which in turn is calling functions of native C++ DLL. All references are properly set. In web service bin folder there are all three DLL's. Problem is when I hit F5 the page in my browser informs me about FileNotFoundException from HRESULT 0x8007007E, The specified module could not be found.
The missing module is my native DLL. ASP.NET Development Server copies (and uses) my C++/CLI DLL somewhere in %USERPROFILE%\AppData\Local\Temp\Temporary ASP.NET Files\root, but not the native one. If I manually copy native DLL to the same folder with C++/CLI DLL then I can debug my web service. However, this copying does not seem right.
Copying native DLL somewhere on PATH does not feel right either, because other developers need to remember it.
There is a similar question here, and a blog post linked in one answer. The given solution requires that I change DLL's to be delay-loaded, which again seems to much of a half-baked workaround, because it requires to change the end product due to development hurdles.
Is there a proper way to debug a combination of web service, C++CLI DLL, and native DLL?
The issue is simply that the compiler can't figure out where the native c++ library is.
So, there are a couple ways to fix that.
Use DLLImport to load the dll using a relative or absolute path at runtime.
Set the path environment variable to it's location.
Get really complicated in how the project is built (see link below, which you've obviously already read).
http://blogs.msdn.com/b/jorman/archive/2007/08/31/loading-c-assemblies-in-asp-net.aspx
There's no real answer beyond those.

Resources in ASP.NET (VB)

I have added a resource file in App_GlobalResources called FileList.resx.
Now I access the contents within the code by using
My.Resources.FileList.astro1 etc.
It works fine if I set the Build Action of resource file to Embedded. However in this case the resource file is not available after compile and I can't change it later.
If I set the Build Action to Content I get an error : Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "WAP.FileList.resources" was correctly embedded or linked into assembly "WAP" at compile time, or that all the satellite assemblies required are loadable and fully signed.
Please advice me.
Are you using a Visual Studio Web Application? Or a Web Site?
In the latter case, you should be able to change the Resource file after deploying the site, and it should get automatically recompiled on the server. In the former case, it's a built-in that can't be changed after the site is compiled before deployment.
If that's a problem for you, there are of course alternatives to Resource files....
In any way of compiling and deploying your application all resource files will compiled in related to each resource file assemblies. In all cases, resource assemblies are ultimately created for each directory in the site, and satellite assemblies are generated beneath their respective culture-specific directories. Even when the site is JIT-compiled, the outcome is equivalent.
So, you must use Build Action of resource file to Embedded, but as possible solution for dynamic resource definition you can place you resources in a database. And even provide a Resource provider. In that case your database solution would have all the benefits that suggested by resource management aka dynamic culture definition, using resource binding to control, etc.
Here you can find some tutorials how to implement Resource-Provider Model in your application:
Extending the ASP.NET 2.0 Resource-Provider Model
Creating a Data Driven ASP.NET Localization
Resource Provider and Editor

BuildManager.AddReferencedAssembly and BuildManager.GetObjectFactory

I'm experimenting with creating a plugin framework for ASP.NET MVC. I've managed to inject the controllers dynamically, but I've hit the wall when loading the view templates.
I've debugged MVC and located the problem to the following call:
BuildManager.GetObjectFactory("~/Views/HelloWorld/Index.cshtml")
The problem isn't that the path does not exist, but that it does not compile. The view is typed to use HelloWorldPlugin.Models.Message as a model, but it seems the BuildManager can't find the type. I had a look in Temporary ASP.NET Files and as expected, HelloWorldPlugin.dll does not exist there.
What stumps me is that before the application starts, I make a call to BuildManager.AddReferencedAssembly, passing the HelloWorldPlugin assembly as the parameter. This works fine for making MVC find the controller, but why isn't the BuildManager installing it to Temporary ASP.NET Files, and why can't it find it when compiling the view?
Your plugin assembly won't get copied to Temporary ASP.NET Files. Assemblies are loaded from the bin folder. BuildManager.AddReferencedAssembly is merely adding an assembly reference to the one that should be loaded in memory. It's equivalent to adding the assembly to the application-level Web.config file.
Can you share the exact error message you're getting. Did you check your bin folder to make sure that your plugin assembly is referenced properly?

What is difference between web.config assemblies element and project file Reference element

I'm looking at an asp.net application, i notice that there are assemblies defined into two places. In web.config there is configuration/system.web/compilation/assemblies/add elements. In the project file there are references setup under the Project/ItemGroup/Reference elements.
I was wondering, what is the difference between assemblies/references added in either location?
In the web.config section:
The assemblies element defines a collection of assembly names that are used during compilation of an ASP.NET application.
Web site projects usually use the assemblies element as there is no project file storing location of references that the web site uses. The project references would not apply to a web site, as it has no proper project file to store these in, so must store all referenced assemblies in the web.config. There is some interesting, although not directly related, discussion here.
Web application projects may make use of both the assemblies element and project references.
Having a reference in the assemblies element also means you won't have to add the #register at the top of any .aspx pages that use that namespace. More discussion on that here.

How to create a strong-named assembly?

I have a web site project in which my architecture is an N-layered architecture. I am using Micorsoft Enterprise library's validation DLL file. As of now this DLL file is not strongly named. I need to make that assembly strongly named. How can I do this?
I saw some articles which depicts how to create a strong-named assembly by taking the Visual Studio 2008 command prompt and type:
sn -k publickey.snk
Then add the assembly tag to the assemblyinfo.cs file. I tried to do that, but my website project dosen't have any assemblyinfo.cs file.
Since ASP.NET web site projects are compiled dynamically, you can't assign a strong name to the assembly since it does not exist (yet). If you want to assign a strong name your ASP.NET code, you'll have to use a ASP.NET web application project instead.
As for assigning a strong name to a third-party DLL, you can't unless it's been delay signed. There is another way, but it will probably contravene the license agreement.

Resources