Getting an embedded resource from a shared project










0















I'm working on a Xamarin Forms app which has two projects, an Android App and an iOS app. All the other code is stored in shared projects.



Solution looks like this:



  • MyApp.Android (Android project), references MyApp.Base

  • MyApp.iOS (iOS project), references MyApp.Base

  • MyApp.Base (Shared project)

I am using the following code to read an SVG image from the shared project:



using (var stream = GetType().Assembly.GetManifestResourceStream("MyApp.Base.image.svg"))

// do work here...



This works perfectly when the image is in the Android or iOS project, but I want the image to be shared so I put it in the shared project.



GetType().Assembly return MyApp.Android, thus it cannot find the image. I suppose I'm overlooking something but I haven't been able to find a solution.



Can anyone point me in the right direction? Thanks!










share|improve this question






















  • Might want to look at this forums.xamarin.com/discussion/comment/57081/#Comment_57081

    – Andres Castro
    Nov 15 '18 at 20:02















0















I'm working on a Xamarin Forms app which has two projects, an Android App and an iOS app. All the other code is stored in shared projects.



Solution looks like this:



  • MyApp.Android (Android project), references MyApp.Base

  • MyApp.iOS (iOS project), references MyApp.Base

  • MyApp.Base (Shared project)

I am using the following code to read an SVG image from the shared project:



using (var stream = GetType().Assembly.GetManifestResourceStream("MyApp.Base.image.svg"))

// do work here...



This works perfectly when the image is in the Android or iOS project, but I want the image to be shared so I put it in the shared project.



GetType().Assembly return MyApp.Android, thus it cannot find the image. I suppose I'm overlooking something but I haven't been able to find a solution.



Can anyone point me in the right direction? Thanks!










share|improve this question






















  • Might want to look at this forums.xamarin.com/discussion/comment/57081/#Comment_57081

    – Andres Castro
    Nov 15 '18 at 20:02













0












0








0








I'm working on a Xamarin Forms app which has two projects, an Android App and an iOS app. All the other code is stored in shared projects.



Solution looks like this:



  • MyApp.Android (Android project), references MyApp.Base

  • MyApp.iOS (iOS project), references MyApp.Base

  • MyApp.Base (Shared project)

I am using the following code to read an SVG image from the shared project:



using (var stream = GetType().Assembly.GetManifestResourceStream("MyApp.Base.image.svg"))

// do work here...



This works perfectly when the image is in the Android or iOS project, but I want the image to be shared so I put it in the shared project.



GetType().Assembly return MyApp.Android, thus it cannot find the image. I suppose I'm overlooking something but I haven't been able to find a solution.



Can anyone point me in the right direction? Thanks!










share|improve this question














I'm working on a Xamarin Forms app which has two projects, an Android App and an iOS app. All the other code is stored in shared projects.



Solution looks like this:



  • MyApp.Android (Android project), references MyApp.Base

  • MyApp.iOS (iOS project), references MyApp.Base

  • MyApp.Base (Shared project)

I am using the following code to read an SVG image from the shared project:



using (var stream = GetType().Assembly.GetManifestResourceStream("MyApp.Base.image.svg"))

// do work here...



This works perfectly when the image is in the Android or iOS project, but I want the image to be shared so I put it in the shared project.



GetType().Assembly return MyApp.Android, thus it cannot find the image. I suppose I'm overlooking something but I haven't been able to find a solution.



Can anyone point me in the right direction? Thanks!







c# svg xamarin.forms






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 15 '18 at 19:37









JasperJasper

385




385












  • Might want to look at this forums.xamarin.com/discussion/comment/57081/#Comment_57081

    – Andres Castro
    Nov 15 '18 at 20:02

















  • Might want to look at this forums.xamarin.com/discussion/comment/57081/#Comment_57081

    – Andres Castro
    Nov 15 '18 at 20:02
















Might want to look at this forums.xamarin.com/discussion/comment/57081/#Comment_57081

– Andres Castro
Nov 15 '18 at 20:02





Might want to look at this forums.xamarin.com/discussion/comment/57081/#Comment_57081

– Andres Castro
Nov 15 '18 at 20:02












1 Answer
1






active

oldest

votes


















3














You are using the Shared Project NOT the PCL or .Net Standard library. So, all of your Shared Project contents will get merged into the Platform specific project when you Compile them. That means - even if you Embed your resource in your MyApp.Base that will get merged into .iOS/.Droid project.
I suggest you to learn more about Shared Project vs PCL or .Net Standard library.
Below code; I did't tested but this is the direction that you should follow:



#if __IOS__
var resourcePrefix = "MyApp.iOS.";
#endif
#if __ANDROID__
var resourcePrefix = "MyApp.Android.";
#endif

var assembly = IntrospectionExtensions.GetTypeInfo(typeof(SharedPage)).Assembly;
Stream stream = assembly.GetManifestResourceStream
(resourcePrefix + "image.svg");


For more information please look into this page : https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/files?tabs=macos#embedding-in-shared-projects






share|improve this answer























  • Thank you. This solved my problem.

    – Jasper
    Nov 16 '18 at 8:55










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53326784%2fgetting-an-embedded-resource-from-a-shared-project%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









3














You are using the Shared Project NOT the PCL or .Net Standard library. So, all of your Shared Project contents will get merged into the Platform specific project when you Compile them. That means - even if you Embed your resource in your MyApp.Base that will get merged into .iOS/.Droid project.
I suggest you to learn more about Shared Project vs PCL or .Net Standard library.
Below code; I did't tested but this is the direction that you should follow:



#if __IOS__
var resourcePrefix = "MyApp.iOS.";
#endif
#if __ANDROID__
var resourcePrefix = "MyApp.Android.";
#endif

var assembly = IntrospectionExtensions.GetTypeInfo(typeof(SharedPage)).Assembly;
Stream stream = assembly.GetManifestResourceStream
(resourcePrefix + "image.svg");


For more information please look into this page : https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/files?tabs=macos#embedding-in-shared-projects






share|improve this answer























  • Thank you. This solved my problem.

    – Jasper
    Nov 16 '18 at 8:55















3














You are using the Shared Project NOT the PCL or .Net Standard library. So, all of your Shared Project contents will get merged into the Platform specific project when you Compile them. That means - even if you Embed your resource in your MyApp.Base that will get merged into .iOS/.Droid project.
I suggest you to learn more about Shared Project vs PCL or .Net Standard library.
Below code; I did't tested but this is the direction that you should follow:



#if __IOS__
var resourcePrefix = "MyApp.iOS.";
#endif
#if __ANDROID__
var resourcePrefix = "MyApp.Android.";
#endif

var assembly = IntrospectionExtensions.GetTypeInfo(typeof(SharedPage)).Assembly;
Stream stream = assembly.GetManifestResourceStream
(resourcePrefix + "image.svg");


For more information please look into this page : https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/files?tabs=macos#embedding-in-shared-projects






share|improve this answer























  • Thank you. This solved my problem.

    – Jasper
    Nov 16 '18 at 8:55













3












3








3







You are using the Shared Project NOT the PCL or .Net Standard library. So, all of your Shared Project contents will get merged into the Platform specific project when you Compile them. That means - even if you Embed your resource in your MyApp.Base that will get merged into .iOS/.Droid project.
I suggest you to learn more about Shared Project vs PCL or .Net Standard library.
Below code; I did't tested but this is the direction that you should follow:



#if __IOS__
var resourcePrefix = "MyApp.iOS.";
#endif
#if __ANDROID__
var resourcePrefix = "MyApp.Android.";
#endif

var assembly = IntrospectionExtensions.GetTypeInfo(typeof(SharedPage)).Assembly;
Stream stream = assembly.GetManifestResourceStream
(resourcePrefix + "image.svg");


For more information please look into this page : https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/files?tabs=macos#embedding-in-shared-projects






share|improve this answer













You are using the Shared Project NOT the PCL or .Net Standard library. So, all of your Shared Project contents will get merged into the Platform specific project when you Compile them. That means - even if you Embed your resource in your MyApp.Base that will get merged into .iOS/.Droid project.
I suggest you to learn more about Shared Project vs PCL or .Net Standard library.
Below code; I did't tested but this is the direction that you should follow:



#if __IOS__
var resourcePrefix = "MyApp.iOS.";
#endif
#if __ANDROID__
var resourcePrefix = "MyApp.Android.";
#endif

var assembly = IntrospectionExtensions.GetTypeInfo(typeof(SharedPage)).Assembly;
Stream stream = assembly.GetManifestResourceStream
(resourcePrefix + "image.svg");


For more information please look into this page : https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/files?tabs=macos#embedding-in-shared-projects







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 15 '18 at 20:52









Nirmal SubediNirmal Subedi

1,4582923




1,4582923












  • Thank you. This solved my problem.

    – Jasper
    Nov 16 '18 at 8:55

















  • Thank you. This solved my problem.

    – Jasper
    Nov 16 '18 at 8:55
















Thank you. This solved my problem.

– Jasper
Nov 16 '18 at 8:55





Thank you. This solved my problem.

– Jasper
Nov 16 '18 at 8:55



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53326784%2fgetting-an-embedded-resource-from-a-shared-project%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Top Tejano songwriter Luis Silva dead of heart attack at 64

政党

天津地下鉄3号線