Adventures on Enterprise Library 5.0: Who moved my cheese (namespace) - visual-studio-2010

Jesus, Krishna, Budda!
I've migrated to EntLib 5.0, but classes like ISymmetricCryptoProvider are not recognized anymore. Funny to say that Data, Logging and other blocks are working compiling fine.
Here's the problematic class:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;//-->it's not working anymore
using Microsoft.Practices.EnterpriseLibrary.Security.Cryptography;//-->it's not working anymore
namespace MyClassLibrary.Security.EnterpriseLibrary
{
public sealed class Crypto
{
public static ISymmetricCryptoProvider MyProvider
{
get
{
//IConfigurationSource is not recognized either, neither SystemConfigurationSource
IConfigurationSource cs = new SystemConfigurationSource();
SymmetricCryptoProviderFactory scpf = new SymmetricCryptoProviderFactory(cs);
ISymmetricCryptoProvider p = scpf.CreateDefault();
return p;
}
}
The references are fine on project too. I really don't know why this particular project it's causing too many trouble on VS2010! Older references were deleted, project was cleaned, rebuilt, but can't make it compile :-(
The references are:
Microsoft.Practices.EnterpriseLibrary.Common
Microsoft.Practices.EnterpriseLibrary.Logging
Microsoft.Practices.EnterpriseLibrary.Logging.Database
Microsoft.Practices.EnterpriseLibrary.Security
Microsoft.Practices.EnterpriseLibrary.Security.Cryptography
Why some namespaces can be found while others can't?

Based on the 4.1 references that you have, you are still referencing the Enterprise Library 4.1 assemblies. You need to remove those references and add references to the Enterprise Library 5.0 assemblies.
The cryptography block should be usable as is without changing your code. Also make sure to update the "references" in all of your configuration files.

Share the command-line when building (output window, csc.exe command line with all the -r's to see what references are going to the compiler)? It might suggest the problem.

Related

Why is a Namespace not included in resulting nuget package after 'nuget pack' and including it in another project

I have a .net 6.0 class library project that has class files in the root, but also contains a Models folder with public classes declared in the class library. I've tried using the *.nupkg file created via nuget pack at the *.csproj level and the one created when the build preference to generate a package on every build. The package is created fine as MyPackage.
When I include 'MyPackage' in another project, I have access to the root classes, but the namespace MyPackage.Models doesn't seem to be included even though it was part of the project. Additionally, the xml documentation file does not seem to be included because I see none of my comments included when calling any of the methods on classes at MyPackage root.
I'm new to using my own nuget packages so this might be a rookie mistake, but I'm not sure what I'm doing wrong here.
Any advice?
I make a test to create a MyPackage package and can correctly reference the namespace MyPackage.Models, here is the project:
I add this code in Method1.cs:
namespace MyPackage.Models
{
public class Method1
{
public int Add(int a,int b)
{
return a + b;
}
}
}
It works in the test:
Maybe you can provide some more information to help reproduce the problem.
The problem was a nuget package caching issue. I had to close out my solutions, clear the cache, and even reboot my machine. When I did that, things worked as I expected.
Before I tried this, I created a new class library project and copied the files from the prior project to this one. When I made a nuget package for this new one, everything worked as intended. That confirmed for me that the issue was caching.

iOS project doesn't reference a static library from Binding project when in Release mode

I've got a static library, which was used to generate the wrapping code by Sharpie. The library was Built after that (including, generated *.dll) successfully.
AppDefinition.cs contains the namespace and the mappings, like this:
namespace TheNamespace
{
// #interface TheParameters : NSObject
[BaseType(typeof(NSObject))]
interface TheParameters
{
The library itself built in Release mode with LinkTarget.ArmV7 | LinkTarget.ArmV7s | LinkTarget.Arm64.
However, when referencing this binding project from my iOS project, it works only in Debug mode.
When I change it to Release, the namespace (and all the related clasees) not available. Also, when exploring the binding library reference in Object Browser, it doesn't display any elements: it's totally empty.
Just to point that: it gets available when changing it in the dropdown to Debug and disappears on Release, what's interesting, undependently on what actually project is selected in Current Project dropdown!
What might be the issue? Thanks!
I think the problem should come from when building static library .When generating static library , there is a build type of release/debug to select.
Above screenshot shows static library types after building , there are three types (Two is Debug and One is Release ). You can see that tt distinguishes between release and debug .
After some Googling I found the solution.
The issue happens because of Visual Studio bug, I guess. And also referred here. (And it's weird it's not mentioned in Xamarin docs on Microsoft website.
To resolve the issue the Binding Project(s) must not reside in the same solution with the main project. Just remove them and attach the library as regular reference.

Why can't I reference one project from another (but CAN use statics)?

This one is weird. I've got a MonoDevelop/MonoTouch project (call it MyApp) that references another project (call it MyUtils), which is a Portable Class Library (targeting .NET 4.0.3, if that is relevant).
In the MyApp project, I've added a reference to MyUtils. In Visual Studio, this works properly: I can refer to the classes in MyUtils without any problem.
But in MonoDevelop on the Mac, if I try to refer to MyUtils from MyApp, I can't. It simply doesn't see the project, and can't, for instance, write something like:
using MyUtils.MyNamespace
If I do, I get a 'type or namespace could not be found' error.
But here's the weird part: MyApp can use the static classes in MyUtils. If I refer to a public static class in MyUtils from MyApp, it works! What could possibly explain this?!
What explains this is that the MonoTouch implementation of PCLs is a bit of a kludge at present.
The proper work is underway, but in the meantime you need to use an interim release of MonoDevelop, and you need to be aware that things like Intellisense and syntax highlighting don't really work in MonoDevelop.
See:
MonoTouch: creating multiplatform apps using Portable Class Libraries
http://slodge.blogspot.co.uk/2013/02/the-future-is-portable.html
Update - the interim release is hidden in a comment on that question:
For those doing PCL stuff, I've posted a patched MonoDevelop 3.1.1 build with improved PCL support here: http://files.xamarin.com/~jeff/MonoDevelop-3.1.1.dmg - it's still not perfect, but it's better than the official builds so far (my patches will be in a future official release) – jstedfast Feb 8 at 14:57

System.Data.Linq not loaded in MVC .NET 4.5

I have an ASP.NET MVC4 Web Application project in .NET 4.5 (VS 2012). It is in VB.
It fails loading System.Data.Linq namespace (with all classes and sub-namespaces).
Project has a reference set to System.Data.Linq.dll.
Any ideas where is the problem?
When I try to add Linq2Sql classes, I get such warning:
Namespace or type specified in the Imports 'System.Data.Linq' doesn't contain
any public member or cannot be found. Make sure the namespace or the type is
defined and contains at least one public member. Make sure the imported element
name doesn't use any aliases.
and such errors:
System.Data.Linq.DataContext
But this is just a beginning: if I try to use anything from System.Data.Linq namespace I get an error, for example if I try to use System.Data.Linq.Mapping.DatabaseAttribute, I get such error:
Type 'System.Data.Linq.Mapping.DatabaseAttribute' is not defined.
I had this same problem - and was able to get past it. I'm not entirely sure which of these steps resolved the issue - but this is what I did.
I had originally created the dbml under app_code/gcm
I removed references to System.Data.DataSetExtensions
I deleted the dbml and recreated it outside of the app_code folder
I built the project (no errors/warnings)
I moved the dbml back to the app_code folder and rebuilt (again no errors/warnings)
Hope that helps you get around this.

How do I call unmanaged functions in C from Unity3d if I don't have a .bundle? (Mac)

I am on Mac.
I have a bunch of C source code (.c and .h).
I have a static library (.a).
I want to use that .a library from within Unity.
I looked into Unity's documentation for plug-ins (http://unity3d.com/support/documentation/Manual/Plugins.html), which says for PC and Mac stand alones, .bundle files seem to be the only solution. All example plugin-in projects that Unity give have .bundle plugins.
But I have seen prime31 plugins using .a library in Unity!
Anyone has a clue how they did that?
Here is all that I can tell from analyzing prime31 plugin:
(1) they put their .a library in Unity's Editor folder
(2) they have a C# script which contains lots of [DllImport ("__Internal")]
I tried to do the same:
(1) I wrote a simple hello_world.c in Xcode and built a .a library. I put the libhelloworld.a in Asset/Editor
(2) I then wrote a C# script that looks like this:
using UnityEngine;
using System.Collections;
using System.Runtime.InteropServices;
public class testlib : MonoBehaviour {
[DllImport ("libhelloworld")]
static public extern System.String helloworld();
}
(3) Then I wrote a test script:
using UnityEngine;
using System.Collections;
public class test : MonoBehaviour {
// Use this for initialization
void Start () {
print(testlib.helloworld());
}
}
(4) By doing so I get a runtime error:
DllNotFoundException: libhelloworld
test.Start () (at Assets/Script/test.cs:8)
Many, many thanks!
PS: In case some of you wonder why I have the source code but not the bundle. I am trying to build a bundle from those .c and .h but hasn't succeeded yet. The source code was compiled with make tools, but I don't know anything else that could build a bundle except for Xcode. So I guess I have to use Xcode to build my bundle. My problem is when I tried to build it with Xcode I get millions of errors saying that I have duplicate main entries. I checked the source code and found that it does have duplicate main()s because the source code has lots of utilities that come with it. I tried deleting those utilities but the same error doesn't go away...
I am planning to ask this question somewhere else because this does not seem very Unity-related. But if someone here happens to know the answer, please don't hesitate -- let me know!
Okay I got an email from the prime31 people. It's impossible to do that.
Unity does not build an Xcode project for OSX, so you can't link a static library. Unity does build an Xcode project for iOS, that's how the prime31 developers could use the .a library(in Xcode, not in Unity)
To sum up, to use unmanaged code in Unity on MacOS, the only correct way is to build a bundle from your source code and then import it to Unity. Just like their documentation said!
I think I will try to build a bundle from source code or try to build a bundle from the .a library that I am now able to build, though Mac OS documentation says it's pointless:
Note: Some Xcode targets (such as shell tools and static libraries) do
not result in the creation of a bundle or package. This is normal and
there is no need to create bundles specifically for these target
types. The resulting binaries generated for those targets are intended
to be used as is.
I may post another question and if that question got answered, I will include a link here...
Alright I am coming back to edit:
Finally I built a bundle from a .a static library and was able to call functions of the library from Unity. Here is how I did: How to organize C source file previously compiled by GCC Make and build them into an Xcode bundle? I have a Duplicate Symbol _main Error
I am using my own library for an iOS project and it works fine. I don't use Unity3D's mechanism of copying from plugins folder but set it up completely in XCode. In the above HelloWorld example try [DllImport("__Internal")].
Follow the links in my previous answer How to use an xcode game on unity3d look at my blog posting, it deals exactly with this problem.

Resources